Fix valgrind errors
This commit is contained in:
+3
-1
@@ -252,9 +252,11 @@ Module* parser_parse(TokenStream* ts) {
|
|||||||
} while (!terminal);
|
} while (!terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(p);
|
||||||
return module;
|
return module;
|
||||||
fail:
|
fail:
|
||||||
free(module);
|
free(p);
|
||||||
|
parser_free(module);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static jmp_buf s_testJmp;
|
static jmp_buf s_testJmp;
|
||||||
static const char* s_failMsg;
|
static const char* s_failMsg = NULL;
|
||||||
static char* s_logOutput = NULL;
|
static char* s_logOutput = NULL;
|
||||||
static const char* s_currentTestName = NULL;
|
static const char* s_currentTestName = NULL;
|
||||||
static char* s_testSource = NULL;
|
static char* s_testSource = NULL;
|
||||||
@@ -75,8 +75,8 @@ TokenStream* test_get_tokenstream(void) {
|
|||||||
s_testSource = read_file_content(filepath);
|
s_testSource = read_file_content(filepath);
|
||||||
if (!s_testSource) {
|
if (!s_testSource) {
|
||||||
puts(filepath);
|
puts(filepath);
|
||||||
fail("could not read test source file");
|
|
||||||
free(filepath);
|
free(filepath);
|
||||||
|
fail("could not read test source file");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s_currentTokenStream = tokenstream_open(filepath, s_testSource);
|
s_currentTokenStream = tokenstream_open(filepath, s_testSource);
|
||||||
@@ -108,24 +108,29 @@ void assert_log_file(const char* msg) {
|
|||||||
if (generate && strcmp(generate, "1") == 0) {
|
if (generate && strcmp(generate, "1") == 0) {
|
||||||
FILE* f = fopen(filepath, "w");
|
FILE* f = fopen(filepath, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
free(filepath);
|
||||||
fail("could not open golden file for writing");
|
fail("could not open golden file for writing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fputs(s_logOutput ? s_logOutput : "", f);
|
fputs(s_logOutput ? s_logOutput : "", f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
free(filepath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = read_file_content(filepath);
|
content = read_file_content(filepath);
|
||||||
if (!content) {
|
if (!content) {
|
||||||
fail("could not open golden file for reading");
|
|
||||||
free(filepath);
|
free(filepath);
|
||||||
|
fail("could not open golden file for reading");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_str(content, s_logOutput, msg);
|
bool match = strcmp(content, s_logOutput ? s_logOutput : "") == 0;
|
||||||
free(content);
|
free(content);
|
||||||
free(filepath);
|
free(filepath);
|
||||||
|
if (!match) {
|
||||||
|
fail(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void assert_int(int expected, int actual, const char* msg) {
|
void assert_int(int expected, int actual, const char* msg) {
|
||||||
@@ -245,7 +250,7 @@ int main(int argc, char** argv) {
|
|||||||
printf(" [OK]\n");
|
printf(" [OK]\n");
|
||||||
s_greenTests++;
|
s_greenTests++;
|
||||||
} else {
|
} else {
|
||||||
printf(" [FAIL]: %s\n", s_failMsg ? s_failMsg : "");
|
printf(" [FAIL]: %s\n", s_failMsg[0] ? s_failMsg : "");
|
||||||
failedTests[failedCount++] = s_tests[i].name;
|
failedTests[failedCount++] = s_tests[i].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user