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