diff options
-rw-r--r-- | absl/log/absl_check.h | 4 | ||||
-rw-r--r-- | absl/log/check.h | 4 | ||||
-rw-r--r-- | absl/log/check_test_impl.h | 13 | ||||
-rw-r--r-- | absl/log/internal/check_impl.h | 15 |
4 files changed, 25 insertions, 11 deletions
diff --git a/absl/log/absl_check.h b/absl/log/absl_check.h index b8428bf7..2775adbe 100644 --- a/absl/log/absl_check.h +++ b/absl/log/absl_check.h @@ -37,8 +37,8 @@ #include "absl/log/internal/check_impl.h" -#define ABSL_CHECK(condition) ABSL_CHECK_IMPL(condition) -#define ABSL_QCHECK(condition) ABSL_QCHECK_IMPL(condition) +#define ABSL_CHECK(condition) ABSL_CHECK_IMPL(condition, #condition) +#define ABSL_QCHECK(condition) ABSL_QCHECK_IMPL(condition, #condition) #define ABSL_PCHECK(condition) ABSL_PCHECK_IMPL(condition) #define ABSL_DCHECK(condition) ABSL_DCHECK_IMPL(condition) diff --git a/absl/log/check.h b/absl/log/check.h index 172436a6..ef1bd531 100644 --- a/absl/log/check.h +++ b/absl/log/check.h @@ -54,7 +54,7 @@ // Might produce a message like: // // Check failed: !cheese.empty() Out of Cheese -#define CHECK(condition) ABSL_CHECK_IMPL(condition) +#define CHECK(condition) ABSL_CHECK_IMPL(condition, #condition) // QCHECK() // @@ -62,7 +62,7 @@ // not run registered error handlers (as `QFATAL`). It is useful when the // problem is definitely unrelated to program flow, e.g. when validating user // input. -#define QCHECK(condition) ABSL_QCHECK_IMPL(condition) +#define QCHECK(condition) ABSL_QCHECK_IMPL(condition, #condition) // PCHECK() // diff --git a/absl/log/check_test_impl.h b/absl/log/check_test_impl.h index bcf5711f..2c09a60c 100644 --- a/absl/log/check_test_impl.h +++ b/absl/log/check_test_impl.h @@ -120,6 +120,19 @@ TEST(CHECKDeathTest, TestChecksWithSideEffects) { #if GTEST_HAS_DEATH_TEST +TEST(CHECKTest, TestMacroExpansionInMessage) { +#define MACRO(x) x + auto MessageGen = []() { ABSL_TEST_CHECK(MACRO(false)); }; + EXPECT_DEATH(MessageGen(), HasSubstr("MACRO(false)")); +#undef MACRO +} + +TEST(CHECKTest, TestNestedMacroExpansionInMessage) { +#define MACRO(x) x + EXPECT_DEATH(ABSL_TEST_CHECK(MACRO(false)), HasSubstr("MACRO(false)")); +#undef MACRO +} + TEST(CHECKDeachTest, TestOrderOfInvocationsBetweenCheckAndMessage) { int counter = 0; diff --git a/absl/log/internal/check_impl.h b/absl/log/internal/check_impl.h index 301b2915..d3238861 100644 --- a/absl/log/internal/check_impl.h +++ b/absl/log/internal/check_impl.h @@ -22,22 +22,23 @@ #include "absl/log/internal/strip.h" // CHECK -#define ABSL_CHECK_IMPL(condition) \ +#define ABSL_CHECK_IMPL(condition, condition_str) \ ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \ ABSL_PREDICT_FALSE(!(condition))) \ - ABSL_LOG_INTERNAL_CHECK(#condition).InternalStream() + ABSL_LOG_INTERNAL_CHECK(condition_str).InternalStream() -#define ABSL_QCHECK_IMPL(condition) \ +#define ABSL_QCHECK_IMPL(condition, condition_str) \ ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \ ABSL_PREDICT_FALSE(!(condition))) \ - ABSL_LOG_INTERNAL_QCHECK(#condition).InternalStream() + ABSL_LOG_INTERNAL_QCHECK(condition_str).InternalStream() -#define ABSL_PCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition).WithPerror() +#define ABSL_PCHECK_IMPL(condition) \ + ABSL_CHECK_IMPL(condition, #condition).WithPerror() #ifndef NDEBUG -#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition) +#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(condition, #condition) #else -#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition)) +#define ABSL_DCHECK_IMPL(condition) ABSL_CHECK_IMPL(true || (condition), "true") #endif // CHECK_EQ |