Commit 59382630 by Abseil Team Committed by Copybara-Service

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
parent c16a2f43
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment