From 154bf6f53529e88dfa03d6ff5034b575f92cdbb5 Mon Sep 17 00:00:00 2001 From: nasr Date: Tue, 14 Apr 2026 23:11:49 +0200 Subject: feature(setup): base implementation --- source/base/base_test.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 source/base/base_test.h (limited to 'source/base/base_test.h') diff --git a/source/base/base_test.h b/source/base/base_test.h new file mode 100644 index 0000000..072bec3 --- /dev/null +++ b/source/base/base_test.h @@ -0,0 +1,46 @@ +// TODO(nasr): metaprogram that takes an expected output and generates a test for that specified +// function +/* base library testing framework */ +#ifndef BASE_TEST_H +#define BASE_TEST_H + +// helper macro +#define show \ + do \ + { \ + write(STDOUT_FILENO, __FILE__, sizeof(__FILE__) - 1); \ + write(STDOUT_FILENO, ":", 1); \ + write(STDOUT_FILENO, __func__, sizeof(__func__) - 1); \ + write(STDOUT_FILENO, ":", 1); \ + write_int(__LINE__); \ + write(STDOUT_FILENO, "\n", 1); \ + } while (0) + +#define test(expr) \ + { \ + if ((expr) != 0) \ + { \ + write(STDERR_FILENO, "[FAILED] ", LEN("[FAILED] ")); \ + show; \ + _exit(1); \ + } \ + } + +#define verify(expr) \ + { \ + if ((expr) != 0) \ + { \ + write(STDERR_FILENO, Red "[ERROR] ", Len(Red "[ERROR] ")); \ + show; \ + write(STDERR_FILENO, Reset, Len(Reset)); \ + _exit(1); \ + } \ + else \ + { \ + write(STDERR_FILENO, Green "[SUCCESS] ", Len(Green "[SUCCESS] ")); \ + show; \ + write(STDERR_FILENO, Reset, Len(Reset)); \ + } \ + } + +#endif /* BASE_TEST_H */ -- cgit v1.3