summaryrefslogtreecommitdiff
path: root/absl/log/scoped_mock_log_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-02-23 13:05:39 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-02-23 13:06:27 -0800
commit4825ef40953aeb4a71e3625203b760381da6b0d7 (patch)
treed8931476e759cd07d9b22ebad887700161b7e725 /absl/log/scoped_mock_log_test.cc
parent6d16237574fed8538a4864954a5e2b5a098f32f2 (diff)
Initialize ScopedMockLog.is_triggered_ with false.
In C++20, this happens by default, but in C++17, it's left uninitialized if no logs are sent and StartCapturingLogs is never called. The destructor then makes an attempt to access it, which is both unsafe and not very useful while it is uninitialized. Also add a test that expects the appropriate CHECK fail when StartCapturingLogs is not called. PiperOrigin-RevId: 511865440 Change-Id: Ie23ff3f901e926761d5f487e10d33c21c3bd43d3
Diffstat (limited to 'absl/log/scoped_mock_log_test.cc')
-rw-r--r--absl/log/scoped_mock_log_test.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/absl/log/scoped_mock_log_test.cc b/absl/log/scoped_mock_log_test.cc
index 44b8d737..42736939 100644
--- a/absl/log/scoped_mock_log_test.cc
+++ b/absl/log/scoped_mock_log_test.cc
@@ -71,6 +71,11 @@ TEST(ScopedMockLogDeathTest, StopCapturingLogsCannotBeCalledWhenNotCapturing) {
},
"StopCapturingLogs");
}
+
+TEST(ScopedMockLogDeathTest, FailsCheckIfStartCapturingLogsIsNeverCalled) {
+ EXPECT_DEATH({ absl::ScopedMockLog log; },
+ "Did you forget to call StartCapturingLogs");
+}
#endif
// Tests that ScopedMockLog intercepts LOG()s when it's alive.