summaryrefslogtreecommitdiff
path: root/source/base/base_test.h
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-04-14 23:11:49 +0200
committernasr <nsrddyn@gmail.com>2026-04-14 23:11:49 +0200
commit154bf6f53529e88dfa03d6ff5034b575f92cdbb5 (patch)
tree04acbc1039719c610f11712b57e1786092f89242 /source/base/base_test.h
parent4d2a2af0c7d4eec9a9e43e0ba08813fdebaf8f9c (diff)
feature(setup): base implementation
Diffstat (limited to 'source/base/base_test.h')
-rw-r--r--source/base/base_test.h46
1 files changed, 46 insertions, 0 deletions
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 @@
1// TODO(nasr): metaprogram that takes an expected output and generates a test for that specified
2// function
3/* base library testing framework */
4#ifndef BASE_TEST_H
5#define BASE_TEST_H
6
7// helper macro
8#define show \
9 do \
10 { \
11 write(STDOUT_FILENO, __FILE__, sizeof(__FILE__) - 1); \
12 write(STDOUT_FILENO, ":", 1); \
13 write(STDOUT_FILENO, __func__, sizeof(__func__) - 1); \
14 write(STDOUT_FILENO, ":", 1); \
15 write_int(__LINE__); \
16 write(STDOUT_FILENO, "\n", 1); \
17 } while (0)
18
19#define test(expr) \
20 { \
21 if ((expr) != 0) \
22 { \
23 write(STDERR_FILENO, "[FAILED] ", LEN("[FAILED] ")); \
24 show; \
25 _exit(1); \
26 } \
27 }
28
29#define verify(expr) \
30 { \
31 if ((expr) != 0) \
32 { \
33 write(STDERR_FILENO, Red "[ERROR] ", Len(Red "[ERROR] ")); \
34 show; \
35 write(STDERR_FILENO, Reset, Len(Reset)); \
36 _exit(1); \
37 } \
38 else \
39 { \
40 write(STDERR_FILENO, Green "[SUCCESS] ", Len(Green "[SUCCESS] ")); \
41 show; \
42 write(STDERR_FILENO, Reset, Len(Reset)); \
43 } \
44 }
45
46#endif /* BASE_TEST_H */