shadow/tests/unit/Makefile.am
Alejandro Colomar 15aa496900 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 <string.h>

	#include <stdarg.h>
	#include <stddef.h>
	#include <setjmp.h>
	#include <stdint.h>
	#include <cmocka.h>

	#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 <github@infinisil.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-28 08:41:54 -06:00

149 lines
2.7 KiB
Makefile

AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)
if HAVE_CMOCKA
TESTS = $(check_PROGRAMS)
check_PROGRAMS = \
test_adds \
test_atoi_strtoi \
test_chkname \
test_snprintf \
test_strncpy \
test_strtcpy \
test_typetraits \
test_exit_if_null
if ENABLE_LOGIND
check_PROGRAMS += \
test_logind
endif # ENABLE_LOGIND
check_PROGRAMS += \
$(NULL)
test_adds_SOURCES = \
../../lib/adds.c \
../../lib/search/cmp/cmp.c \
test_adds.c \
$(NULL)
test_adds_CFLAGS = \
$(AM_FLAGS) \
$(NULL)
test_adds_LDFLAGS = \
$(NULL)
test_adds_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_atoi_strtoi_SOURCES = \
../../lib/atoi/strtoi/strtoi.c \
../../lib/atoi/strtoi/strtou_noneg.c \
test_atoi_strtoi.c \
$(NULL)
test_atoi_strtoi_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_atoi_strtoi_LDFLAGS = \
$(NULL)
test_atoi_strtoi_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_chkname_SOURCES = \
../../lib/chkname.c \
test_chkname.c \
$(NULL)
test_chkname_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_chkname_LDFLAGS = \
$(NULL)
test_chkname_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_logind_SOURCES = \
../../lib/logind.c \
test_logind.c \
$(NULL)
test_logind_CFLAGS = \
$(AM_CFLAGS) \
-lsystemd \
$(NULL)
test_logind_LDFLAGS = \
-Wl,-wrap,prefix_getpwnam \
-Wl,-wrap,sd_uid_get_sessions \
$(NULL)
test_logind_LDADD = \
$(CMOCKA_LIBS) \
$(LIBSYSTEMD) \
$(NULL)
test_snprintf_SOURCES = \
../../lib/string/sprintf/snprintf.c \
test_snprintf.c \
$(NULL)
test_snprintf_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_snprintf_LDFLAGS = \
$(NULL)
test_snprintf_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_strncpy_SOURCES = \
test_strncpy.c \
$(NULL)
test_strncpy_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_strncpy_LDFLAGS = \
$(NULL)
test_strncpy_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_strtcpy_SOURCES = \
../../lib/string/strcpy/strtcpy.c \
test_strtcpy.c \
$(NULL)
test_strtcpy_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_strtcpy_LDFLAGS = \
$(NULL)
test_strtcpy_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_typetraits_SOURCES = \
test_typetraits.c \
$(NULL)
test_typetraits_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_typetraits_LDFLAGS = \
$(NULL)
test_typetraits_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
test_exit_if_null_SOURCES = \
../../lib/exit_if_null.c \
../../lib/shadowlog.c \
../../lib/alloc/malloc.c \
test_exit_if_null.c \
$(NULL)
test_exit_if_null_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
test_exit_if_null_LDFLAGS = \
-Wl,-wrap,exit \
$(NULL)
test_exit_if_null_LDADD = \
$(CMOCKA_LIBS) \
$(NULL)
endif # HAVE_CMOCKA