From f24ec48b27d4cb8dd0555840206dedbb45f1423c Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 24 Oct 2026 01:17:50 +0200 Subject: Add a unit test harness and a first set of tests make check builds tests/runner from the modules that link without the io subsystem and runs it. --- tests/test.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/test.c (limited to 'tests/test.c') diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..4686369 --- /dev/null +++ b/tests/test.c @@ -0,0 +1,58 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. + + $id$ */ + +/* System */ +#include +#include + +/* Opentracker */ +#include "test.h" + +unsigned long test_checks; +unsigned long test_failures; + +static const char *current_module = ""; +static const char *current_case = ""; + +void test_module(const char *name) { + current_module = name; + current_case = ""; + printf("%s\n", name); +} + +void test_case(const char *name) { current_case = name; } + +static void test_where(const char *file, int line) { + ++test_failures; + printf(" FAIL %s/%s (%s:%d)\n ", current_module, current_case, file, line); +} + +void test_failf(const char *file, int line, const char *fmt, ...) { + va_list ap; + test_where(file, line); + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + printf("\n"); +} + +void test_failmem(const char *file, int line, const char *what, const void *got, const void *want, size_t len) { + const unsigned char *g = got, *w = want; + size_t i; + + test_where(file, line); + printf("%s: %zu bytes differ\n got ", what, len); + for (i = 0; i < len; ++i) + printf("%02x", g[i]); + printf("\n want "); + for (i = 0; i < len; ++i) + printf("%02x", w[i]); + printf("\n"); +} + +int test_summary(void) { + printf("\n%lu checks, %lu failures\n", test_checks, test_failures); + return test_failures != 0; +} -- cgit v1.3