summaryrefslogtreecommitdiff
path: root/absl/log
diff options
context:
space:
mode:
authorGravatar Andy Getzendanner <durandal@google.com>2023-12-21 12:00:50 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-21 12:01:50 -0800
commit8184f16e898fcb13b310b40430e13ba40679cf0e (patch)
tree2216371d4feb7f6e1bc3c1721764180872cfd0f9 /absl/log
parent258e5a15759cc3d122d4a4826bc499af91d40aa9 (diff)
Release a few bits and pieces of DFATAL that were left behind: flag parsing & some tests.
PiperOrigin-RevId: 592918704 Change-Id: Iacef0e069c012a04960211c032454244822f9634
Diffstat (limited to 'absl/log')
-rw-r--r--absl/log/log_basic_test_impl.inc90
1 files changed, 90 insertions, 0 deletions
diff --git a/absl/log/log_basic_test_impl.inc b/absl/log/log_basic_test_impl.inc
index f3400095..e2f33566 100644
--- a/absl/log/log_basic_test_impl.inc
+++ b/absl/log/log_basic_test_impl.inc
@@ -277,6 +277,96 @@ TEST_P(BasicLogDeathTest, QFatal) {
}
#endif
+#ifdef NDEBUG
+TEST_P(BasicLogTest, DFatal) {
+ absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
+
+ absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
+
+ const int log_line = __LINE__ + 1;
+ auto do_log = [] { ABSL_TEST_LOG(DFATAL) << "hello world"; };
+
+ if (LoggingEnabledAt(absl::LogSeverity::kError)) {
+ EXPECT_CALL(
+ test_sink,
+ Send(AllOf(SourceFilename(Eq(__FILE__)),
+ SourceBasename(Eq("log_basic_test_impl.inc")),
+ SourceLine(Eq(log_line)), Prefix(IsTrue()),
+ LogSeverity(Eq(absl::LogSeverity::kError)),
+ TimestampInMatchWindow(),
+ ThreadID(Eq(absl::base_internal::GetTID())),
+ TextMessage(Eq("hello world")),
+ Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
+ ENCODED_MESSAGE(EqualsProto(R"pb(value {
+ literal: "hello world"
+ })pb")),
+ Stacktrace(IsEmpty()))));
+ }
+
+ test_sink.StartCapturingLogs();
+ do_log();
+}
+
+#elif GTEST_HAS_DEATH_TEST
+TEST_P(BasicLogDeathTest, DFatal) {
+ // TODO(b/242568884): re-enable once bug is fixed.
+ // absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());
+
+ const int log_line = __LINE__ + 1;
+ auto do_log = [] { ABSL_TEST_LOG(DFATAL) << "hello world"; };
+
+ EXPECT_EXIT(
+ {
+ absl::ScopedMockLog test_sink(
+ absl::MockLogDefault::kDisallowUnexpected);
+
+ EXPECT_CALL(test_sink, Send)
+ .Times(AnyNumber())
+ .WillRepeatedly(DeathTestUnexpectedLogging());
+
+ ::testing::InSequence s;
+
+ if (LoggingEnabledAt(absl::LogSeverity::kFatal)) {
+ // The first call without the stack trace.
+ EXPECT_CALL(
+ test_sink,
+ Send(AllOf(SourceFilename(Eq(__FILE__)),
+ SourceBasename(Eq("log_basic_test_impl.inc")),
+ SourceLine(Eq(log_line)), Prefix(IsTrue()),
+ LogSeverity(Eq(absl::LogSeverity::kFatal)),
+ TimestampInMatchWindow(),
+ ThreadID(Eq(absl::base_internal::GetTID())),
+ TextMessage(Eq("hello world")),
+ Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
+ ENCODED_MESSAGE(EqualsProto(
+ R"pb(value { literal: "hello world" })pb")),
+ Stacktrace(IsEmpty()))))
+ .WillOnce(DeathTestExpectedLogging());
+
+ // The second call with the stack trace.
+ EXPECT_CALL(
+ test_sink,
+ Send(AllOf(SourceFilename(Eq(__FILE__)),
+ SourceBasename(Eq("log_basic_test_impl.inc")),
+ SourceLine(Eq(log_line)), Prefix(IsTrue()),
+ LogSeverity(Eq(absl::LogSeverity::kFatal)),
+ TimestampInMatchWindow(),
+ ThreadID(Eq(absl::base_internal::GetTID())),
+ TextMessage(Eq("hello world")),
+ Verbosity(Eq(absl::LogEntry::kNoVerbosityLevel)),
+ ENCODED_MESSAGE(EqualsProto(
+ R"pb(value { literal: "hello world" })pb")),
+ Stacktrace(Not(IsEmpty())))))
+ .WillOnce(DeathTestExpectedLogging());
+ }
+
+ test_sink.StartCapturingLogs();
+ do_log();
+ },
+ DiedOfFatal, DeathTestValidateExpectations());
+}
+#endif
+
TEST_P(BasicLogTest, Level) {
absl::log_internal::ScopedMinLogLevel scoped_min_log_level(GetParam());