Refactor golden files to follow xyz_log_ and xyz_src_ naming convention
This commit is contained in:
@@ -42,29 +42,31 @@ void assert_log_file(const char* filepath, const char* msg) {
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* f = fopen(filepath, "r");
|
||||
if (!f) {
|
||||
char* content = read_file_content(filepath);
|
||||
if (!content) {
|
||||
fail("could not open golden file for reading");
|
||||
return;
|
||||
}
|
||||
|
||||
assert_str(content, s_logOutput, msg);
|
||||
free(content);
|
||||
}
|
||||
|
||||
char* read_file_content(const char* filepath) {
|
||||
FILE* f = fopen(filepath, "r");
|
||||
if (!f) return NULL;
|
||||
fseek(f, 0, SEEK_END);
|
||||
long size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
char* content = malloc(size + 1);
|
||||
if (!content) {
|
||||
fclose(f);
|
||||
fail("could not allocate memory for golden file content");
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fread(content, 1, size, f);
|
||||
content[size] = '\0';
|
||||
fclose(f);
|
||||
|
||||
assert_str(content, s_logOutput, msg);
|
||||
free(content);
|
||||
return content;
|
||||
}
|
||||
|
||||
void assert_int(int expected, int actual, const char* msg) {
|
||||
@@ -177,4 +179,4 @@ int main(int argc, char** argv) {
|
||||
|
||||
printf("\n%d/%d tests passed.\n", s_greenTests, s_totalTests);
|
||||
return failedCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user