summaryrefslogtreecommitdiff
path: root/source/base/base_test.h
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-03-13 22:31:21 +0100
committernasr <nsrddyn@gmail.com>2026-03-13 22:31:21 +0100
commit444bfa2f41143aff7490e4fa21565947565b7d30 (patch)
tree696b06d40140c85805d171597e37deb8290ead73 /source/base/base_test.h
parent3913d1778318cd0c6bfb871148d38abb33ec7fd3 (diff)
cleanup: generalisation
Diffstat (limited to 'source/base/base_test.h')
-rw-r--r--source/base/base_test.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/source/base/base_test.h b/source/base/base_test.h
new file mode 100644
index 0000000..11028f4
--- /dev/null
+++ b/source/base/base_test.h
@@ -0,0 +1,61 @@
1#ifndef BASE_TEST_H
2#define BASE_TEST_H
3
4void
5write_int(i32 num);
6
7#define RED "\x1b[31m"
8#define GREEN "\x1b[32m"
9#define RESET "\x1b[0m"
10#define BLUE "\x1b[34m"
11
12#define LEN(s) (sizeof(s) - 1)
13
14#define show \
15 do \
16 { \
17 write(STDOUT_FILENO, __FILE__, sizeof(__FILE__) - 1); \
18 write(STDOUT_FILENO, ":", 1); \
19 write(STDOUT_FILENO, __func__, sizeof(__func__) - 1); \
20 write(STDOUT_FILENO, ":", 1); \
21 write_int(__LINE__); \
22 write(STDOUT_FILENO, "\n", 1); \
23 } while (0)
24
25#define test(expr) \
26 { \
27 if ((expr) != 0) \
28 { \
29 write(STDERR_FILENO, "[FAILED] ", LEN("[FAILED] ")); \
30 show; \
31 _exit(1); \
32 } \
33 }
34
35#define check(expr) \
36 { \
37 if ((expr) != 0) \
38 { \
39 write(STDERR_FILENO, RED "[ERROR] ", LEN(RED "[ERROR] ")); \
40 show; \
41 write(STDERR_FILENO, RESET, LEN(RESET)); \
42 _exit(1); \
43 } \
44 else \
45 { \
46 write(STDERR_FILENO, GREEN "[SUCCESS] ", LEN(GREEN "[SUCCESS] ")); \
47 show; \
48 write(STDERR_FILENO, RESET, LEN(RESET)); \
49 } \
50 }
51
52#define checkpoint_output "<<CHECKPOINT>>\n"
53#define checkpoint_end_output "^^^^^^^^^^^^^^\n\n\n"
54#define checkpoint \
55 { \
56 write(STDERR_FILENO, BLUE checkpoint_output, LEN(BLUE checkpoint_output)); \
57 show; \
58 write(STDERR_FILENO, BLUE checkpoint_end_output, LEN(BLUE checkpoint_end_output)); \
59 }
60
61#endif /* BASE_TEST_H */