summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-17 14:33:23 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-17 14:33:30 +0000
commite0cf5aca2a17fae1f89860d5106aa901dde32782 (patch)
tree4935e9438f15bb7ec377fd54802b21ec3f4c68f1
parent03bf3217d2c3860ecb55dbd0151ba0adc105fa01 (diff)
Working on new type of tests (related to codegen).
-rw-r--r--Makefile1
-rw-r--r--tests/codegen/dedup_typedefs.zc18
-rwxr-xr-xtests/run_codegen_tests.sh51
3 files changed, 70 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 82d75b8..5eb4040 100644
--- a/Makefile
+++ b/Makefile
@@ -100,6 +100,7 @@ clean:
# Test
test: $(TARGET)
./tests/run_tests.sh
+ ./tests/run_codegen_tests.sh
# Build with alternative compilers
zig:
diff --git a/tests/codegen/dedup_typedefs.zc b/tests/codegen/dedup_typedefs.zc
new file mode 100644
index 0000000..c6e8099
--- /dev/null
+++ b/tests/codegen/dedup_typedefs.zc
@@ -0,0 +1,18 @@
+struct Vec2f {
+ x: f32;
+ y: f32;
+}
+
+struct Node {
+ val: int;
+ next: Node*;
+}
+
+fn main() {
+ var v: Vec2f;
+ v.x = 1.0;
+ v.y = 2.0;
+
+ var n: Node;
+ n.val = 1;
+}
diff --git a/tests/run_codegen_tests.sh b/tests/run_codegen_tests.sh
new file mode 100755
index 0000000..179af52
--- /dev/null
+++ b/tests/run_codegen_tests.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# Codegen Verification Test Runner
+ZC="./zc"
+TEST_DIR="tests/codegen"
+PASSED=0
+FAILED=0
+
+if [ ! -f "$ZC" ]; then
+ echo "Error: zc binary not found."
+ exit 1
+fi
+
+echo "** Running Codegen Verification Tests **"
+
+# Test 1: Duplicate Typedefs
+TEST_NAME="dedup_typedefs.zc"
+echo -n "Testing $TEST_DIR/$TEST_NAME (Duplicate Typedefs)... "
+
+$ZC "$TEST_DIR/$TEST_NAME" --emit-c > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+ echo "FAIL (Compilation error)"
+ ((FAILED++))
+else
+ # Check out.c for duplicates
+ # We expect "typedef struct Vec2f Vec2f;" to appear exactly once
+ COUNT=$(grep -c "typedef struct Vec2f Vec2f;" out.c)
+
+ if [ "$COUNT" -eq 1 ]; then
+ echo "PASS"
+ ((PASSED++))
+ else
+ echo "FAIL (Found $COUNT typedefs for Vec2f, expected 1)"
+ ((FAILED++))
+ fi
+fi
+
+# Cleanup
+rm -f out.c a.out
+
+echo "----------------------------------------"
+echo "Summary:"
+echo "-> Passed: $PASSED"
+echo "-> Failed: $FAILED"
+echo "----------------------------------------"
+
+if [ $FAILED -ne 0 ]; then
+ exit 1
+else
+ exit 0
+fi