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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,11 @@ void assert_log_file(const char* filepath, const char* msg);
|
||||
*/
|
||||
void assert_int(int expected, int actual, const char* msg);
|
||||
|
||||
/**
|
||||
* Reads the content of a file into a newly allocated string.
|
||||
*/
|
||||
char* read_file_content(const char* filepath);
|
||||
|
||||
/**
|
||||
* Asserts that a condition is true.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| module my_module; import ;
|
||||
^
|
||||
expected module name to import
|
||||
@@ -0,0 +1 @@
|
||||
import ;
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| import other_module;
|
||||
^^^^^^
|
||||
expected 'module' keyword
|
||||
@@ -0,0 +1 @@
|
||||
import other_module;
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| int main() []
|
||||
^^
|
||||
unexpected token
|
||||
@@ -0,0 +1 @@
|
||||
int main() []
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| int main() []
|
||||
^^
|
||||
unexpected token 'x'
|
||||
@@ -0,0 +1 @@
|
||||
int main() []
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| module my_module; import other_module
|
||||
^
|
||||
expected ';' after import
|
||||
@@ -0,0 +1 @@
|
||||
module my_module; import other_module
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| module my_module
|
||||
^
|
||||
expected ';' after module name
|
||||
@@ -0,0 +1 @@
|
||||
module my_module
|
||||
@@ -0,0 +1,4 @@
|
||||
--- test.c ---
|
||||
1| %
|
||||
^
|
||||
unexpected token '%'
|
||||
@@ -0,0 +1 @@
|
||||
%
|
||||
Reference in New Issue
Block a user