summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEshan Kelkar <eshankelkar@galorithm.com>2023-12-18 11:40:26 +0530
committerAndreas Schneider <asn@cryptomilk.org>2024-01-05 07:51:51 +0100
commitad567f8d85e41c41e61b8a4d039837eb640e3c22 (patch)
tree57af84ae2f13767420eccd099b1b5080f2129aba
parent109645a20fe2983f54e318c23575e39cdb8b1d0a (diff)
downloadcmocka-ad567f8d85e41c41e61b8a4d039837eb640e3c22.zip
cmocka-ad567f8d85e41c41e61b8a4d039837eb640e3c22.tar.gz
cmocka-ad567f8d85e41c41e61b8a4d039837eb640e3c22.tar.bz2
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>
-rw-r--r--include/cmocka.h7
-rw-r--r--src/cmocka.c12
2 files changed, 16 insertions, 3 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 70dd603..307165f 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -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,
diff --git a/src/cmocka.c b/src/cmocka.c
index 43652d6..b1963d3 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -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);
}
}