|
13 | 13 |
|
14 | 14 | #include <string> |
15 | 15 | using namespace llvm; |
| 16 | +using testing::Eq; |
16 | 17 | using testing::HasSubstr; |
17 | 18 |
|
18 | 19 | #ifndef NDEBUG |
@@ -50,6 +51,28 @@ TEST(DebugLogTest, Basic) { |
50 | 51 | DEBUGLOG_WITH_STREAM_AND_TYPE(os, "A") << "B"; |
51 | 52 | DEBUGLOG_WITH_STREAM_AND_TYPE(os, "B") << "B"; |
52 | 53 | 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)); |
53 | 62 | } |
| 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)); |
54 | 77 | } |
55 | 78 | #endif |
0 commit comments