From aef19fe383a70f47fa83a70cfce70fa4a713c1d1 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Mon, 31 Aug 2020 14:30:28 +0200 Subject: test: Add test_run and test_assert macros test_run and test_assert replaces regular assert with better logging which include the currently running test name. The tests can now also be built without DEBUG. --- include/test.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 include/test.h (limited to 'include') diff --git a/include/test.h b/include/test.h new file mode 100644 index 0000000..64716cc --- /dev/null +++ b/include/test.h @@ -0,0 +1,23 @@ +#ifndef _TEST_H +#define _TEST_H + +char *__curtestname = ""; + +#define test_run(func) \ + do { \ + char *orig = __curtestname; \ + __curtestname = #func; \ + func(); \ + __curtestname = orig; \ + } while (0) + +#define test_assert(cond) \ + do { \ + if (!(cond)) { \ + fprintf(stderr, "%s:%d: %s: test_assert failed: %s\n", __FILE__, __LINE__, \ + __curtestname, #cond); \ + abort(); \ + } \ + } while (0) + +#endif -- cgit v1.2.3