summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-07-14 10:15:09 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-07-14 10:16:07 -0700
commit593826300ac2d1a8a6538bbdefc20d441db648e6 (patch)
tree01f20071e3833744c04a2b9914ee6b12e6add529
parentc16a2f43206b0235d49d4f6155f285a4d4939c58 (diff)
Test that CHECK respects ABSL_MIN_LOG_LEVEL
Ensure that the CHECK expression and message are stripped when FATAL is below ABSL_MIN_LOG_LEVEL. PiperOrigin-RevId: 548157637 Change-Id: I4308ff7ff75aabebdd2dcefa2771cd7e77112817
-rw-r--r--absl/log/stripping_test.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/absl/log/stripping_test.cc b/absl/log/stripping_test.cc
index 8b711ec7..aff91495 100644
--- a/absl/log/stripping_test.cc
+++ b/absl/log/stripping_test.cc
@@ -345,4 +345,30 @@ TEST_F(StrippingTest, Level) {
}
}
+TEST_F(StrippingTest, Check) {
+ // Here we also need a variable name with enough entropy that it's unlikely to
+ // appear in the binary by chance. `volatile` keeps the tautological
+ // comparison (and the rest of the `CHECK`) from being optimized away.
+ const std::string var_needle = absl::Base64Escape("StrippingTestCheckVar");
+ const std::string msg_needle = absl::Base64Escape("StrippingTest.Check");
+ volatile int U3RyaXBwaW5nVGVzdENoZWNrVmFy = 0xCAFE;
+ // We don't care if the CHECK is actually executed, just that stripping works.
+ // Hiding it behind `kReallyDie` works around some overly aggressive
+ // optimizations in older versions of MSVC.
+ if (kReallyDie) {
+ CHECK(U3RyaXBwaW5nVGVzdENoZWNrVmFy != U3RyaXBwaW5nVGVzdENoZWNrVmFy)
+ << "U3RyaXBwaW5nVGVzdC5DaGVjaw==";
+ }
+
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
+ ASSERT_THAT(exe, NotNull());
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle));
+ EXPECT_THAT(exe.get(), FileHasSubstr(msg_needle));
+ } else {
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle)));
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(msg_needle)));
+ }
+}
+
} // namespace