summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-22 22:56:40 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-22 22:56:40 +0000
commit5d31f28bedc3d045f01f390245b5afbbb316e414 (patch)
treeb6f6e8a6c027931b34b7db2435d6f462f4984373
parented4bbfd8cf4a72fdf4a5d6cba94d537cab340356 (diff)
Fix for #91
-rw-r--r--src/codegen/codegen.h2
-rw-r--r--src/codegen/codegen_decl.c9
-rw-r--r--src/codegen/codegen_main.c4
-rw-r--r--tests/features/_fstring_mod.zc (renamed from tests/features/fstring_mod.zc)0
-rw-r--r--tests/features/test_fstring.zc2
-rw-r--r--tests/modules/test_aliasing.zc4
-rw-r--r--tests/modules/test_modules/_math.zc (renamed from tests/modules/test_modules/math.zc)0
-rw-r--r--tests/modules/test_modules/_physics.zc (renamed from tests/modules/test_modules/physics.zc)0
-rw-r--r--tests/modules/test_modules/_simple.zc (renamed from tests/modules/test_modules/simple.zc)0
-rw-r--r--tests/modules/test_namespaced.zc4
-rwxr-xr-xtests/run_tests.sh2
11 files changed, 12 insertions, 15 deletions
diff --git a/src/codegen/codegen.h b/src/codegen/codegen.h
index 0a1cbaf..d27356a 100644
--- a/src/codegen/codegen.h
+++ b/src/codegen/codegen.h
@@ -39,7 +39,7 @@ void emit_globals(ParserContext *ctx, ASTNode *node, FILE *out);
void emit_lambda_defs(ParserContext *ctx, FILE *out);
void emit_protos(ASTNode *node, FILE *out);
void emit_impl_vtables(ParserContext *ctx, FILE *out);
-void emit_tests_and_runner(ParserContext *ctx, ASTNode *node, FILE *out);
+int emit_tests_and_runner(ParserContext *ctx, ASTNode *node, FILE *out);
void print_type_defs(ParserContext *ctx, FILE *out, ASTNode *nodes);
// Global state (shared across modules).
diff --git a/src/codegen/codegen_decl.c b/src/codegen/codegen_decl.c
index 4e6db6a..109aa9a 100644
--- a/src/codegen/codegen_decl.c
+++ b/src/codegen/codegen_decl.c
@@ -958,8 +958,8 @@ void emit_impl_vtables(ParserContext *ctx, FILE *out)
}
}
-// Emit test functions and runner
-void emit_tests_and_runner(ParserContext *ctx, ASTNode *node, FILE *out)
+// Emit test functions and runner. Returns number of tests emitted.
+int emit_tests_and_runner(ParserContext *ctx, ASTNode *node, FILE *out)
{
ASTNode *cur = node;
int test_count = 0;
@@ -983,10 +983,7 @@ void emit_tests_and_runner(ParserContext *ctx, ASTNode *node, FILE *out)
}
fprintf(out, "}\n\n");
}
- else
- {
- fprintf(out, "void _z_run_tests() {}\n");
- }
+ return test_count;
}
// Emit type definitions-
diff --git a/src/codegen/codegen_main.c b/src/codegen/codegen_main.c
index 7363e61..61269ef 100644
--- a/src/codegen/codegen_main.c
+++ b/src/codegen/codegen_main.c
@@ -547,7 +547,7 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out)
emit_lambda_defs(ctx, out);
- emit_tests_and_runner(ctx, kids, out);
+ int test_count = emit_tests_and_runner(ctx, kids, out);
ASTNode *iter = merged_funcs;
while (iter)
@@ -656,7 +656,7 @@ void codegen_node(ParserContext *ctx, ASTNode *node, FILE *out)
chk = chk->next;
}
- if (!has_user_main)
+ if (!has_user_main && test_count > 0)
{
fprintf(out, "\nint main() { _z_run_tests(); return 0; }\n");
}
diff --git a/tests/features/fstring_mod.zc b/tests/features/_fstring_mod.zc
index 78b16ef..78b16ef 100644
--- a/tests/features/fstring_mod.zc
+++ b/tests/features/_fstring_mod.zc
diff --git a/tests/features/test_fstring.zc b/tests/features/test_fstring.zc
index 3ef64a7..b2a8f36 100644
--- a/tests/features/test_fstring.zc
+++ b/tests/features/test_fstring.zc
@@ -1,4 +1,4 @@
-import "tests/features/fstring_mod.zc" as Mod;
+import "tests/features/_fstring_mod.zc" as Mod;
test "alias namespace fstring" {
// Tests that {Mod::get_val()} is parsed correctly (Mod_get_val)
diff --git a/tests/modules/test_aliasing.zc b/tests/modules/test_aliasing.zc
index 96b200c..468e558 100644
--- a/tests/modules/test_aliasing.zc
+++ b/tests/modules/test_aliasing.zc
@@ -1,6 +1,6 @@
-import { Vector as MathVec } from "./test_modules/math.zc";
-import { Vector as PhysicsVec } from "./test_modules/physics.zc";
+import { Vector as MathVec } from "./test_modules/_math.zc";
+import { Vector as PhysicsVec } from "./test_modules/_physics.zc";
test "test_selective_aliasing" {
var mv = MathVec::new(3, 4);
diff --git a/tests/modules/test_modules/math.zc b/tests/modules/test_modules/_math.zc
index be65a5c..be65a5c 100644
--- a/tests/modules/test_modules/math.zc
+++ b/tests/modules/test_modules/_math.zc
diff --git a/tests/modules/test_modules/physics.zc b/tests/modules/test_modules/_physics.zc
index ee56f7e..ee56f7e 100644
--- a/tests/modules/test_modules/physics.zc
+++ b/tests/modules/test_modules/_physics.zc
diff --git a/tests/modules/test_modules/simple.zc b/tests/modules/test_modules/_simple.zc
index ed002e2..ed002e2 100644
--- a/tests/modules/test_modules/simple.zc
+++ b/tests/modules/test_modules/_simple.zc
diff --git a/tests/modules/test_namespaced.zc b/tests/modules/test_namespaced.zc
index d2aa8cd..afc1d6c 100644
--- a/tests/modules/test_namespaced.zc
+++ b/tests/modules/test_namespaced.zc
@@ -1,6 +1,6 @@
-import "./test_modules/math.zc" as math;
-import "./test_modules/physics.zc" as physics;
+import "./test_modules/_math.zc" as math;
+import "./test_modules/_physics.zc" as physics;
test "test_namespaced_imports" {
var mv = math::Vector::new(3, 4);
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index ab2601a..b01906a 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -49,7 +49,7 @@ while read -r test_file; do
((FAILED++))
FAILED_TESTS="$FAILED_TESTS\n- $test_file"
fi
-done < <(find "$TEST_DIR" -name "*.zc" | sort)
+done < <(find "$TEST_DIR" -name "*.zc" -not -name "_*.zc" | sort)
echo "----------------------------------------"
echo "Summary:"