Follow up with the PR #31819
This commit is contained in:
committed by
Luca Boccassi
parent
c3a55dc469
commit
c0cd99eee6
+52
-33
@@ -201,41 +201,60 @@ static inline int run_test_table(void) {
|
||||
#define DEFINE_TEST_MAIN(log_level) \
|
||||
DEFINE_TEST_MAIN_FULL(log_level, NULL, NULL)
|
||||
|
||||
#define ASSERT_OK(expr) \
|
||||
({ \
|
||||
int _result = (expr); \
|
||||
if (_result < 0) { \
|
||||
log_error_errno("Assertion failed: %s (result: %d, error: %m)", #expr, _result); \
|
||||
abort(); \
|
||||
} \
|
||||
#define ASSERT_OK(expr) \
|
||||
({ \
|
||||
typeof(expr) _result = (expr); \
|
||||
if (_result < 0) { \
|
||||
log_error_errno(_result, "%s:%i: Assertion failed: %s: %m", \
|
||||
PROJECT_FILE, __LINE__, #expr); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
/* DECIMAL_STR_FMT() uses _Generic which cannot be used in string concatenation so we have to format the
|
||||
* input into strings first and then format those into the final assertion message. */
|
||||
|
||||
#define ASSERT_EQ(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
if (_expr1 != _expr2) { \
|
||||
char _sexpr1[DECIMAL_STR_MAX(typeof(expr1))]; \
|
||||
char _sexpr2[DECIMAL_STR_MAX(typeof(expr2))]; \
|
||||
xsprintf(_sexpr1, DECIMAL_STR_FMT(_expr1), _expr1); \
|
||||
xsprintf(_sexpr2, DECIMAL_STR_FMT(_expr2), _expr2); \
|
||||
log_error("%s:%i: Assertion failed: expected \"%s == %s\", but \"%s != %s\"", \
|
||||
PROJECT_FILE, __LINE__, #expr1, #expr2, _sexpr1, _sexpr2); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define ASSERT_EQ(expr1, expr2) \
|
||||
({ \
|
||||
int _expr1 = (expr1); \
|
||||
int _expr2 = (expr2); \
|
||||
if (_expr1 != _expr2) { \
|
||||
log_error("Assertion failed: expected %s == %s, but %d != %d", #expr1, #expr2, _expr1, _expr2); \
|
||||
abort(); \
|
||||
} \
|
||||
#define ASSERT_GE(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
if (_expr1 < _expr2) { \
|
||||
char _sexpr1[DECIMAL_STR_MAX(typeof(expr1))]; \
|
||||
char _sexpr2[DECIMAL_STR_MAX(typeof(expr2))]; \
|
||||
xsprintf(_sexpr1, DECIMAL_STR_FMT(_expr1), _expr1); \
|
||||
xsprintf(_sexpr2, DECIMAL_STR_FMT(_expr2), _expr2); \
|
||||
log_error("%s:%i: Assertion failed: expected \"%s >= %s\", but \"%s < %s\"", \
|
||||
PROJECT_FILE, __LINE__, #expr1, #expr2, _sexpr1, _sexpr2); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define ASSERT_GE(expr1, expr2) \
|
||||
({ \
|
||||
int _expr1 = (expr1); \
|
||||
int _expr2 = (expr2); \
|
||||
if (_expr1 < _expr2) { \
|
||||
log_error("Assertion failed: expected %s >= %s, but %d < %d", #expr1, #expr2, _expr1, _expr2); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define ASSERT_LE(expr1, expr2) \
|
||||
({ \
|
||||
int _expr1 = (expr1); \
|
||||
int _expr2 = (expr2); \
|
||||
if (_expr1 > _expr2) { \
|
||||
log_error("Assertion failed: expected %s <= %s, but %d > %d", #expr1, #expr2, _expr1, _expr2); \
|
||||
abort(); \
|
||||
} \
|
||||
#define ASSERT_LE(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
if (_expr1 > _expr2) { \
|
||||
char _sexpr1[DECIMAL_STR_MAX(typeof(expr1))]; \
|
||||
char _sexpr2[DECIMAL_STR_MAX(typeof(expr2))]; \
|
||||
xsprintf(_sexpr1, DECIMAL_STR_FMT(_expr1), _expr1); \
|
||||
xsprintf(_sexpr2, DECIMAL_STR_FMT(_expr2), _expr2); \
|
||||
log_error("%s:%i: Assertion failed: expected \"%s <= %s\", but \"%s > %s\"", \
|
||||
PROJECT_FILE, __LINE__, #expr1, #expr2, _sexpr1, _sexpr2); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user