Refactor golden files to follow xyz_log_ and xyz_src_ naming convention

This commit is contained in:
2026-04-25 20:05:16 +02:00
parent a6bdadac0c
commit e910c01348
16 changed files with 52 additions and 10 deletions
+11 -9
View File
@@ -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) {
+5
View File
@@ -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.
*/
+4
View File
@@ -0,0 +1,4 @@
--- test.c ---
1| module my_module; import ;
^
expected module name to import
+1
View File
@@ -0,0 +1 @@
import ;
+4
View File
@@ -0,0 +1,4 @@
--- test.c ---
1| import other_module;
^^^^^^
expected 'module' keyword
+1
View File
@@ -0,0 +1 @@
import other_module;
+4
View File
@@ -0,0 +1,4 @@
--- test.c ---
1| int main() []
^^
unexpected token
+1
View File
@@ -0,0 +1 @@
int main() []
+4
View File
@@ -0,0 +1,4 @@
--- test.c ---
1| int main() []
^^
unexpected token 'x'
+1
View File
@@ -0,0 +1 @@
int main() []
@@ -0,0 +1,4 @@
--- test.c ---
1| module my_module; import other_module
^
expected ';' after import
+1
View File
@@ -0,0 +1 @@
module my_module; import other_module
@@ -0,0 +1,4 @@
--- test.c ---
1| module my_module
^
expected ';' after module name
+1
View File
@@ -0,0 +1 @@
module my_module
+4
View File
@@ -0,0 +1,4 @@
--- test.c ---
1| %
^
unexpected token '%'
+1
View File
@@ -0,0 +1 @@
%