Skip to content

Commit 386243e

Browse files
committed
Add test for opt mode
1 parent 8e63bc5 commit 386243e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

llvm/unittests/Support/DebugLogTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <string>
1515
using namespace llvm;
16+
using testing::Eq;
1617
using testing::HasSubstr;
1718

1819
#ifndef NDEBUG
@@ -50,6 +51,28 @@ TEST(DebugLogTest, Basic) {
5051
DEBUGLOG_WITH_STREAM_AND_TYPE(os, "A") << "B";
5152
DEBUGLOG_WITH_STREAM_AND_TYPE(os, "B") << "B";
5253
EXPECT_THAT(os.str(), AllOf(HasSubstr("A\n"), Not(HasSubstr("B\n"))));
54+
55+
int count = 0;
56+
auto inc = [&]() { return ++count; };
57+
EXPECT_THAT(count, Eq(0));
58+
DEBUGLOG_WITH_STREAM_AND_TYPE(os, "A") << inc();
59+
EXPECT_THAT(count, Eq(1));
60+
DEBUGLOG_WITH_STREAM_AND_TYPE(os, "B") << inc();
61+
EXPECT_THAT(count, Eq(1));
5362
}
63+
64+
}
65+
#else
66+
TEST(DebugLogTest, Basic) {
67+
// LDBG should be compiled out in NDEBUG, so just check it compiles and has
68+
// no effect.
69+
llvm::DebugFlag = true;
70+
static const char *DT[] = {};
71+
setCurrentDebugTypes(DT, 0);
72+
int count = 0;
73+
auto inc = [&]() { return ++count; };
74+
EXPECT_THAT(count, Eq(0));
75+
LDBG() << inc();
76+
EXPECT_THAT(count, Eq(0));
5477
}
5578
#endif

0 commit comments

Comments
 (0)