aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/DebugLogTest.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/llvm/unittests/Support/DebugLogTest.cpp b/llvm/unittests/Support/DebugLogTest.cpp
index 22dffd8..c34d888 100644
--- a/llvm/unittests/Support/DebugLogTest.cpp
+++ b/llvm/unittests/Support/DebugLogTest.cpp
@@ -27,7 +27,7 @@ TEST(DebugLogTest, Basic) {
std::string str;
raw_string_ostream os(str);
DEBUGLOG_WITH_STREAM_AND_TYPE(os, nullptr) << "NoType";
- EXPECT_TRUE(StringRef(os.str()).starts_with('['));
+ EXPECT_FALSE(StringRef(os.str()).starts_with('['));
EXPECT_TRUE(StringRef(os.str()).ends_with("NoType\n"));
}
@@ -37,6 +37,7 @@ TEST(DebugLogTest, Basic) {
raw_string_ostream os(str);
DEBUGLOG_WITH_STREAM_AND_TYPE(os, "A") << "A";
DEBUGLOG_WITH_STREAM_AND_TYPE(os, "B") << "B";
+ EXPECT_TRUE(StringRef(os.str()).starts_with('['));
EXPECT_THAT(os.str(), AllOf(HasSubstr("A\n"), HasSubstr("B\n")));
}
@@ -61,6 +62,28 @@ TEST(DebugLogTest, Basic) {
EXPECT_THAT(count, Eq(1));
}
}
+
+TEST(DebugLogTest, StreamPrefix) {
+ llvm::DebugFlag = true;
+ static const char *DT[] = {"A", "B"};
+ setCurrentDebugTypes(DT, 2);
+
+ std::string str;
+ raw_string_ostream os(str);
+ std::string expected = "PrefixA 1\nPrefixA 2\nPrefixA \nPrefixB "
+ "3\nPrefixB 4\nPrefixA 5";
+ {
+ llvm::impl::raw_ldbg_ostream ldbg_osB("PrefixB ", os);
+ llvm::impl::raw_ldbg_ostream ldbg_osA("PrefixA ", os);
+ ldbg_osA << "1\n2";
+ ldbg_osA << "\n\n";
+ ldbg_osB << "3\n4\n";
+ ldbg_osA << "5";
+ EXPECT_EQ(os.str(), expected);
+ }
+ // After destructors, there was a pending newline for stream B.
+ EXPECT_EQ(os.str(), expected + "\nPrefixB \n");
+}
#else
TEST(DebugLogTest, Basic) {
// LDBG should be compiled out in NDEBUG, so just check it compiles and has