aboutsummaryrefslogtreecommitdiff
path: root/tools/server/test_util.h
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-06-20 20:10:56 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-21 05:57:19 +0200
commit6b969d25ce136eaf695222bd1a10bff1ecac0220 (patch)
treec23afb50c28b9deaddae5c6526a74ee11cf2d865 /tools/server/test_util.h
parentd4bdb8dae753462f621507d5fc3582e0e53da35c (diff)
downloadffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.tar.gz
ffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.zip
all: split Makefile and reorg library/tools
Diffstat (limited to 'tools/server/test_util.h')
-rw-r--r--tools/server/test_util.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/server/test_util.h b/tools/server/test_util.h
new file mode 100644
index 0000000..c6b6a13
--- /dev/null
+++ b/tools/server/test_util.h
@@ -0,0 +1,26 @@
+#ifndef FFWD_SERVER_TEST_UTIL_H
+#define FFWD_SERVER_TEST_UTIL_H
+
+/* Shared harness for the ffwd-server unit tests. TEST_ASSERT records failures
+ * (rather than aborting) so a single run reports every failure, not just the
+ * first. Each test file includes this, runs its checks, and ends main with
+ * `return TEST_REPORT("label");`, which prints a summary and yields the exit
+ * code (0 when clean, 1 otherwise). */
+
+#include <stdio.h>
+
+static int test_failures = 0;
+
+#define TEST_ASSERT(cond) \
+ do { \
+ if (!(cond)) { \
+ fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
+ test_failures++; \
+ } \
+ } while (0)
+
+#define TEST_REPORT(label) \
+ (test_failures ? (fprintf(stderr, "%s: %d failure(s)\n", (label), test_failures), 1) \
+ : (printf("ok: %s\n", (label)), 0))
+
+#endif /* FFWD_SERVER_TEST_UTIL_H */