================
@@ -335,6 +336,47 @@ TEST_F(LogChannelEnabledTest, log_options) {
logAndTakeOutput("Hello World"));
}
+TEST_F(LogChannelEnabledTest, JSONLOutput) {
+ std::string Err;
+
+ // With only the JSON flag set, every line must parse as JSON and contain
+ // exactly the message we logged.
+ EXPECT_TRUE(
+ EnableChannel(getLogHandler(), LLDB_LOG_OPTION_JSON, "chan", {}, Err));
+ llvm::StringRef Msg = logAndTakeOutput("Hello \"World\"\nsecond line");
+ ASSERT_TRUE(Msg.ends_with("\n"));
+ ASSERT_EQ(Msg.count('\n'), 1u) << "expected one JSON object per line";
+ llvm::Expected<llvm::json::Value> Parsed = llvm::json::parse(Msg);
+ ASSERT_TRUE(static_cast<bool>(Parsed)) << llvm::toString(Parsed.takeError());
+ llvm::json::Object *Obj = Parsed->getAsObject();
+ ASSERT_NE(Obj, nullptr);
+ llvm::StringRef Got = Obj->getString("message").value_or("");
+ EXPECT_EQ(Got, "Hello \"World\"\nsecond line");
+ EXPECT_EQ(Obj->size(), 1u);
+
+ // Combining JSON with metadata flags: each metadata flag becomes a JSON
+ // field instead of a prefix on the line.
----------------
Teemperor wrote:
Done (I think). At least if I understood this correctly you just wanted to see
one single metadata flag turned on and make sure it's the only emitted (and not
the others)?
https://github.com/llvm/llvm-project/pull/205758
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits