Fix valgrind errors
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user