Skip to content

Commit 2c96438

Browse files
committed
Moving gtest PrintTo helpers into its own file.
1 parent 8b89bfa commit 2c96438

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

lldb/include/lldb/Protocol/MCP/Protocol.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct Request {
4545
llvm::json::Value toJSON(const Request &);
4646
bool fromJSON(const llvm::json::Value &, Request &, llvm::json::Path);
4747
bool operator==(const Request &, const Request &);
48-
void PrintTo(const Request &req, std::ostream *os);
4948

5049
enum ErrorCode : signed {
5150
/// Invalid JSON was received by the server. An error occurred on the server
@@ -92,7 +91,6 @@ struct Response {
9291
llvm::json::Value toJSON(const Response &);
9392
bool fromJSON(const llvm::json::Value &, Response &, llvm::json::Path);
9493
bool operator==(const Response &, const Response &);
95-
void PrintTo(const Response &resp, std::ostream *os);
9694

9795
/// A notification which does not expect a response.
9896
/// See
@@ -106,7 +104,6 @@ struct Notification {
106104
llvm::json::Value toJSON(const Notification &);
107105
bool fromJSON(const llvm::json::Value &, Notification &, llvm::json::Path);
108106
bool operator==(const Notification &, const Notification &);
109-
void PrintTo(const Notification &note, std::ostream *os);
110107

111108
/// A general message as defined by the JSON-RPC 2.0 spec.
112109
using Message = std::variant<Request, Response, Notification>;
@@ -116,7 +113,6 @@ static_assert(std::is_convertible_v<Message, Message>,
116113
"Message is not convertible to itself");
117114
bool fromJSON(const llvm::json::Value &, Message &, llvm::json::Path);
118115
llvm::json::Value toJSON(const Message &);
119-
void PrintTo(const Message &message, std::ostream *os);
120116

121117
/// A known resource that the server is capable of reading.
122118
///

lldb/source/Protocol/MCP/Protocol.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ bool operator==(const Request &a, const Request &b) {
8181
return a.id == b.id && a.method == b.method && a.params == b.params;
8282
}
8383

84-
void PrintTo(const Request &req, std::ostream *os) {
85-
*os << formatv("{0}", toJSON(req)).str();
86-
}
87-
8884
llvm::json::Value toJSON(const Error &E) {
8985
llvm::json::Object Result{{"code", E.code}, {"message", E.message}};
9086
if (E.data)
@@ -148,10 +144,6 @@ bool operator==(const Response &a, const Response &b) {
148144
return a.id == b.id && a.result == b.result;
149145
}
150146

151-
void PrintTo(const Response &resp, std::ostream *os) {
152-
*os << formatv("{0}", toJSON(resp)).str();
153-
}
154-
155147
llvm::json::Value toJSON(const Notification &N) {
156148
llvm::json::Object Result{{"jsonrpc", "2.0"}, {"method", N.method}};
157149
if (N.params)
@@ -175,15 +167,6 @@ bool operator==(const Notification &a, const Notification &b) {
175167
return a.method == b.method && a.params == b.params;
176168
}
177169

178-
void PrintTo(const Notification &note, std::ostream *os) {
179-
*os << formatv("{0}", toJSON(note)).str();
180-
}
181-
182-
void PrintTo(const Message &message, std::ostream *os) {
183-
return std::visit([os](auto &&message) { return PrintTo(message, os); },
184-
message);
185-
}
186-
187170
bool fromJSON(const llvm::json::Value &V, Resource &R, llvm::json::Path P) {
188171
llvm::json::ObjectMapper O(V, P);
189172
return O && O.map("uri", R.uri) && O.map("name", R.name) &&

lldb/unittests/Protocol/ProtocolMCPServerTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "ProtocolMCPTestUtilities.h"
910
#include "TestingSupport/Host/JSONTransportTestUtilities.h"
1011
#include "TestingSupport/Host/PipeTestUtilities.h"
1112
#include "TestingSupport/SubsystemRAII.h"

lldb/unittests/Protocol/ProtocolMCPTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "ProtocolMCPTestUtilities.h"
910
#include "TestingSupport/TestUtilities.h"
1011
#include "lldb/Protocol/MCP/Protocol.h"
1112
#include "llvm/Testing/Support/Error.h"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_UNITTESTS_PROTOCOL_PROTOCOLMCPTESTUTILITIES_H
10+
#define LLDB_UNITTESTS_PROTOCOL_PROTOCOLMCPTESTUTILITIES_H
11+
12+
#include "lldb/Protocol/MCP/Protocol.h"
13+
#include "llvm/Support/FormatVariadic.h"
14+
#include "llvm/Support/JSON.h" // IWYU pragma: keep
15+
#include "gtest/gtest.h" // IWYU pragma: keep
16+
#include <ostream>
17+
#include <variant>
18+
19+
namespace lldb_protocol::mcp {
20+
21+
inline void PrintTo(const Request &req, std::ostream *os) {
22+
*os << llvm::formatv("{0}", toJSON(req)).str();
23+
}
24+
25+
inline void PrintTo(const Response &resp, std::ostream *os) {
26+
*os << llvm::formatv("{0}", toJSON(resp)).str();
27+
}
28+
29+
inline void PrintTo(const Notification &note, std::ostream *os) {
30+
*os << llvm::formatv("{0}", toJSON(note)).str();
31+
}
32+
33+
inline void PrintTo(const Message &message, std::ostream *os) {
34+
return std::visit([os](auto &&message) { return PrintTo(message, os); },
35+
message);
36+
}
37+
38+
} // namespace lldb_protocol::mcp
39+
40+
#endif

0 commit comments

Comments
 (0)