diff --git a/v0/parser.c b/v0/parser.c index 157d892..23cfdf4 100644 --- a/v0/parser.c +++ b/v0/parser.c @@ -252,9 +252,11 @@ Module* parser_parse(TokenStream* ts) { } while (!terminal); } + free(p); return module; fail: - free(module); + free(p); + parser_free(module); return NULL; } diff --git a/v0/test.c b/v0/test.c index 00f91b4..dc5dd48 100644 --- a/v0/test.c +++ b/v0/test.c @@ -9,7 +9,7 @@ #include static jmp_buf s_testJmp; -static const char* s_failMsg; +static const char* s_failMsg = NULL; static char* s_logOutput = NULL; static const char* s_currentTestName = NULL; static char* s_testSource = NULL; @@ -75,8 +75,8 @@ TokenStream* test_get_tokenstream(void) { s_testSource = read_file_content(filepath); if (!s_testSource) { puts(filepath); - fail("could not read test source file"); free(filepath); + fail("could not read test source file"); return NULL; } s_currentTokenStream = tokenstream_open(filepath, s_testSource); @@ -108,24 +108,29 @@ void assert_log_file(const char* msg) { if (generate && strcmp(generate, "1") == 0) { FILE* f = fopen(filepath, "w"); if (!f) { + free(filepath); fail("could not open golden file for writing"); return; } fputs(s_logOutput ? s_logOutput : "", f); fclose(f); + free(filepath); return; } content = read_file_content(filepath); if (!content) { - fail("could not open golden file for reading"); free(filepath); + fail("could not open golden file for reading"); return; } - assert_str(content, s_logOutput, msg); + bool match = strcmp(content, s_logOutput ? s_logOutput : "") == 0; free(content); free(filepath); + if (!match) { + fail(msg); + } } void assert_int(int expected, int actual, const char* msg) { @@ -245,7 +250,7 @@ int main(int argc, char** argv) { printf(" [OK]\n"); s_greenTests++; } else { - printf(" [FAIL]: %s\n", s_failMsg ? s_failMsg : ""); + printf(" [FAIL]: %s\n", s_failMsg[0] ? s_failMsg : ""); failedTests[failedCount++] = s_tests[i].name; }