================
@@ -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.
+ uint32_t Opts = LLDB_LOG_OPTION_JSON | LLDB_LOG_OPTION_PREPEND_SEQUENCE |
+ LLDB_LOG_OPTION_PREPEND_TIMESTAMP |
+ LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD |
+ LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION;
----------------
DavidSpickett wrote:
LLDB_LOG_OPTION_PREPEND_THREAD_NAME and LLDB_LOG_OPTION_BACKTRACE are missing
here. Intentional?
I see for some you're just checking that there is a value, not what it is, and
that would be fine for those two I think.
https://github.com/llvm/llvm-project/pull/205758
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits