From 15aa496900b73502f91ac56b9da7f9dd7cc70036 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 4 Nov 2025 13:39:26 +0100 Subject: [PATCH] tests/unit/test_xaprintf.c: Use assert_string_equal() This produces more useful test results. With assert_true(streq(...)), we only see the line of code that triggered the failure, while assert_string_equal() shows the contents of the strings. See the following example: alx@devuan:~/tmp$ cat cmocka.c #include #include #include #include #include #include #define streq(a,b) (!strcmp(a,b)) static void a(void **) { const char *s = "foo"; assert_true(streq(s, "bar")); } static void b(void **) { const char *s = "foo"; assert_string_equal(s, "bar"); } int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(a), cmocka_unit_test(b), }; return cmocka_run_group_tests(tests, NULL, NULL); } alx@devuan:~/tmp$ gcc cmocka.c -lcmocka alx@devuan:~/tmp$ ./a.out [==========] tests: Running 2 test(s). [ RUN ] a [ ERROR ] --- streq(s, "bar") [ LINE ] --- cmocka.c:15: error: Failure! [ FAILED ] a [ RUN ] b [ ERROR ] --- "foo" != "bar" [ LINE ] --- cmocka.c:22: error: Failure! [ FAILED ] b [==========] tests: 2 test(s) run. [ PASSED ] 0 test(s). [ FAILED ] tests: 2 test(s), listed below: [ FAILED ] a [ FAILED ] b 2 FAILED TEST(S) Tested-by: Silvan Mosberger Signed-off-by: Alejandro Colomar --- tests/unit/Makefile.am | 1 - tests/unit/test_exit_if_null.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 9a6387ebe..250004ef6 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -133,7 +133,6 @@ test_exit_if_null_SOURCES = \ ../../lib/exit_if_null.c \ ../../lib/shadowlog.c \ ../../lib/alloc/malloc.c \ - ../../lib/string/strcmp/streq.c \ test_exit_if_null.c \ $(NULL) test_exit_if_null_CFLAGS = \ diff --git a/tests/unit/test_exit_if_null.c b/tests/unit/test_exit_if_null.c index 4a66e870d..ce6b89858 100644 --- a/tests/unit/test_exit_if_null.c +++ b/tests/unit/test_exit_if_null.c @@ -16,7 +16,6 @@ #include #include "sizeof.h" -#include "string/strcmp/streq.h" #define assert_unreachable() assert_true(0) @@ -66,7 +65,7 @@ test_exit_if_null_exit(void **state) assert_unreachable(); break; case EXIT_CALLED: - assert_true(streq(p, "called")); + assert_string_equal(p, "called"); p = "test_ok"; break; default: @@ -74,7 +73,7 @@ test_exit_if_null_exit(void **state) break; } - assert_true(streq(p, "test_ok")); + assert_string_equal(p, "test_ok"); } -- 2.47.3