Commit 19a44466 by Abseil Team Committed by Copybara-Service

Fix absl/log:stripping_test when ABSL_MIN_LOG_LEVEL is defined

The test was getting tripped by EXPECT_DEATH_IF_SUPPORTED keeping a literal
copy of the test statement.

PiperOrigin-RevId: 509299343
Change-Id: I63da29d844cc630d750535fd4bb13a2895d32541
parent 2312dbb6
...@@ -546,6 +546,7 @@ cc_test( ...@@ -546,6 +546,7 @@ cc_test(
deps = [ deps = [
":check", ":check",
":log", ":log",
"//absl/base:log_severity",
"//absl/base:strerror", "//absl/base:strerror",
"//absl/flags:program_name", "//absl/flags:program_name",
"//absl/log/internal:test_helpers", "//absl/log/internal:test_helpers",
......
...@@ -1014,6 +1014,7 @@ absl_cc_test( ...@@ -1014,6 +1014,7 @@ absl_cc_test(
absl::flags_program_name absl::flags_program_name
absl::log absl::log
absl::log_internal_test_helpers absl::log_internal_test_helpers
absl::log_severity
absl::strerror absl::strerror
absl::strings absl::strings
absl::str_format absl::str_format
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/internal/strerror.h" #include "absl/base/internal/strerror.h"
#include "absl/base/log_severity.h"
#include "absl/flags/internal/program_name.h" #include "absl/flags/internal/program_name.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/internal/test_helpers.h" #include "absl/log/internal/test_helpers.h"
...@@ -57,6 +58,10 @@ ...@@ -57,6 +58,10 @@
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
// Set a flag that controls whether we actually execute fatal statements, but
// prevent the compiler from optimizing it out.
static volatile bool kReallyDie = false;
namespace { namespace {
using ::testing::_; using ::testing::_;
using ::testing::Eq; using ::testing::Eq;
...@@ -304,7 +309,10 @@ TEST_F(StrippingTest, Fatal) { ...@@ -304,7 +309,10 @@ TEST_F(StrippingTest, Fatal) {
// as would happen if we used a literal. We might (or might not) leave it // as would happen if we used a literal. We might (or might not) leave it
// lying around later; that's what the tests are for! // lying around later; that's what the tests are for!
const std::string needle = absl::Base64Escape("StrippingTest.Fatal"); const std::string needle = absl::Base64Escape("StrippingTest.Fatal");
EXPECT_DEATH_IF_SUPPORTED(LOG(FATAL) << "U3RyaXBwaW5nVGVzdC5GYXRhbA==", ""); // We don't care if the LOG statement is actually executed, we're just
// checking that it's stripped.
if (kReallyDie) LOG(FATAL) << "U3RyaXBwaW5nVGVzdC5GYXRhbA==";
std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable(); std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
ASSERT_THAT(exe, NotNull()); ASSERT_THAT(exe, NotNull());
if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) { if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
......
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