Make assert_true(), assert_false() more verbose

Both assert_true(expression) and assert_false(expression)
print the expression when the assertion fails. Its not very
clear on seeing the expression that what exactly is the error,
whether its the expression being true or it being false.

This commit changes the assert_true() and assert_false()
such that on failure of assertion:
- assert_true(expression) prints : expression is not true
- assert_false(expression) prints : expression is not false

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Eshan Kelkar 2023-12-18 11:40:26 +05:30 committed by Andreas Schneider
parent 109645a20f
commit ad567f8d85
2 changed files with 16 additions and 3 deletions

View File

@ -1482,8 +1482,8 @@ void assert_true(scalar expression);
*/
void assert_false(scalar expression);
#else
#define assert_false(c) _assert_true(!(cast_to_uintmax_type(c)), #c, \
__FILE__, __LINE__)
#define assert_false(c) _assert_false(cast_to_uintmax_type(c), #c, \
__FILE__, __LINE__)
#endif
#ifdef DOXYGEN
@ -2912,6 +2912,9 @@ void _will_return(const char *const function_name,
void _assert_true(const uintmax_t result,
const char* const expression,
const char * const file, const int line);
void _assert_false(const uintmax_t result,
const char * const expression,
const char * const file, const int line);
void _assert_return_code(const intmax_t result,
const int32_t error,
const char * const expression,

View File

@ -2040,7 +2040,17 @@ void _assert_true(const uintmax_t result,
const char * const expression,
const char * const file, const int line) {
if (!result) {
cmocka_print_error("%s\n", expression);
cmocka_print_error("%s is not true\n", expression);
_fail(file, line);
}
}
void _assert_false(const uintmax_t result,
const char * const expression,
const char * const file, const int line)
{
if (result) {
cmocka_print_error("%s is not false\n", expression);
_fail(file, line);
}
}