1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "test.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
const UnitTest TESTS[] = {
(UnitTest) { .Name = "Arena out of mem", .Function = ArenaOutOfMemory },
(UnitTest) { .Name = "Arena allocation", .Function = ArenaAllocation },
(UnitTest) { .Name = "Test difficulty calculation", .Function = difficultyCalculator },
(UnitTest) { .Name = "Timer display", .Function = timerPrintDisplay },
};
void SetGreenColor() {
printf("\x1b[32m");
}
void SetRedColor() {
printf("\x1b[31m");
}
void ResetColor() {
printf("\x1b[39m");
}
int main(void) {
size_t length = sizeof(TESTS) / sizeof(TESTS[0]);
SetGreenColor();
for (size_t i = 0; i < length; ++i) {
const UnitTest *test = &TESTS[i];
char *outp = test->Function();
if (outp == NULL) {
printf("Test '%s' passed\n", test->Name);
} else {
SetRedColor();
printf("test '%s' failed: %s\n", test->Name, outp);
return 1;
}
}
ResetColor();
return 0;
}
char *reportError(const char *format, ...) {
char outp[16656];
va_list argptr;
va_start(argptr, format);
vsprintf(outp, format, argptr);
va_end(argptr);
return strdup(outp);
}
|