diff --git a/v0/test.c b/v0/test.c index bfaad9b..ef60a6f 100644 --- a/v0/test.c +++ b/v0/test.c @@ -2,9 +2,11 @@ #include #include #include +#include static jmp_buf s_testJmp; static const char* s_failMsg; +static char* s_logOutput = NULL; void fail(const char* msg) { s_failMsg = msg; @@ -23,6 +25,27 @@ void assert_str(const char* expected, const char* actual, const char* msg) { } } +static void log_append(const char* msg) { + size_t oldLen = s_logOutput ? strlen(s_logOutput) : 0; + size_t newLen = oldLen + strlen(msg) + 1; + char* newOutput = malloc(newLen); + if (newOutput) { + if (s_logOutput) { + strcpy(newOutput, s_logOutput); + free(s_logOutput); + } else { + newOutput[0] = '\0'; + } + strcat(newOutput, msg); + s_logOutput = newOutput; + } +} + +static void log_clear() { + free(s_logOutput); + s_logOutput = NULL; +} + typedef struct { const char* name; Test func; @@ -59,11 +82,14 @@ int main(int argc, char** argv) { const char* failedTests[s_totalTests + 1]; int failedCount = 0; + log_set_output(log_append); + for (int i = 0; i < s_totalTests; i++) { printf("%s...", s_tests[i].name); s_failMsg = NULL; if (setjmp(s_testJmp) == 0) { + log_clear(); s_tests[i].func(); printf(" [OK]\n"); s_greenTests++;