#include "test.h" #include #include #include 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); }