File tree Expand file tree Collapse file tree 4 files changed +25
-11
lines changed Expand file tree Collapse file tree 4 files changed +25
-11
lines changed Original file line number Diff line number Diff line change 37
37
38
38
#include "absl/log/internal/check_impl.h"
39
39
40
- #define ABSL_CHECK (condition ) ABSL_CHECK_IMPL(condition)
41
- #define ABSL_QCHECK (condition ) ABSL_QCHECK_IMPL(condition)
40
+ #define ABSL_CHECK (condition ) ABSL_CHECK_IMPL(condition, #condition )
41
+ #define ABSL_QCHECK (condition ) ABSL_QCHECK_IMPL(condition, #condition )
42
42
#define ABSL_PCHECK (condition ) ABSL_PCHECK_IMPL(condition)
43
43
#define ABSL_DCHECK (condition ) ABSL_DCHECK_IMPL(condition)
44
44
Original file line number Diff line number Diff line change 54
54
// Might produce a message like:
55
55
//
56
56
// Check failed: !cheese.empty() Out of Cheese
57
- #define CHECK (condition ) ABSL_CHECK_IMPL(condition)
57
+ #define CHECK (condition ) ABSL_CHECK_IMPL(condition, #condition )
58
58
59
59
// QCHECK()
60
60
//
61
61
// `QCHECK` behaves like `CHECK` but does not print a full stack trace and does
62
62
// not run registered error handlers (as `QFATAL`). It is useful when the
63
63
// problem is definitely unrelated to program flow, e.g. when validating user
64
64
// input.
65
- #define QCHECK (condition ) ABSL_QCHECK_IMPL(condition)
65
+ #define QCHECK (condition ) ABSL_QCHECK_IMPL(condition, #condition )
66
66
67
67
// PCHECK()
68
68
//
Original file line number Diff line number Diff line change @@ -120,6 +120,19 @@ TEST(CHECKDeathTest, TestChecksWithSideEffects) {
120
120
121
121
#if GTEST_HAS_DEATH_TEST
122
122
123
+ TEST (CHECKTest, TestMacroExpansionInMessage) {
124
+ #define MACRO (x ) x
125
+ auto MessageGen = []() { ABSL_TEST_CHECK (MACRO (false )); };
126
+ EXPECT_DEATH (MessageGen (), HasSubstr (" MACRO(false)" ));
127
+ #undef MACRO
128
+ }
129
+
130
+ TEST (CHECKTest, TestNestedMacroExpansionInMessage) {
131
+ #define MACRO (x ) x
132
+ EXPECT_DEATH (ABSL_TEST_CHECK (MACRO (false )), HasSubstr (" MACRO(false)" ));
133
+ #undef MACRO
134
+ }
135
+
123
136
TEST (CHECKDeachTest, TestOrderOfInvocationsBetweenCheckAndMessage) {
124
137
int counter = 0 ;
125
138
Original file line number Diff line number Diff line change 22
22
#include "absl/log/internal/strip.h"
23
23
24
24
// CHECK
25
- #define ABSL_CHECK_IMPL (condition ) \
25
+ #define ABSL_CHECK_IMPL (condition , condition_str ) \
26
26
ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
27
27
ABSL_PREDICT_FALSE(!(condition))) \
28
- ABSL_LOG_INTERNAL_CHECK(#condition ).InternalStream()
28
+ ABSL_LOG_INTERNAL_CHECK(condition_str ).InternalStream()
29
29
30
- #define ABSL_QCHECK_IMPL (condition ) \
30
+ #define ABSL_QCHECK_IMPL (condition , condition_str ) \
31
31
ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
32
32
ABSL_PREDICT_FALSE(!(condition))) \
33
- ABSL_LOG_INTERNAL_QCHECK(#condition ).InternalStream()
33
+ ABSL_LOG_INTERNAL_QCHECK(condition_str ).InternalStream()
34
34
35
- #define ABSL_PCHECK_IMPL (condition ) ABSL_CHECK_IMPL(condition).WithPerror()
35
+ #define ABSL_PCHECK_IMPL (condition ) \
36
+ ABSL_CHECK_IMPL(condition, #condition).WithPerror()
36
37
37
38
#ifndef NDEBUG
38
- #define ABSL_DCHECK_IMPL (condition ) ABSL_CHECK_IMPL(condition)
39
+ #define ABSL_DCHECK_IMPL (condition ) ABSL_CHECK_IMPL(condition, #condition )
39
40
#else
40
- #define ABSL_DCHECK_IMPL (condition ) ABSL_CHECK_IMPL(true || (condition))
41
+ #define ABSL_DCHECK_IMPL (condition ) ABSL_CHECK_IMPL(true || (condition), "true" )
41
42
#endif
42
43
43
44
// CHECK_EQ
You can’t perform that action at this time.
0 commit comments