summaryrefslogtreecommitdiff
path: root/src
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 /src
parented4bbfd8cf4a72fdf4a5d6cba94d537cab340356 (diff)
Fix for #91
Diffstat (limited to 'src')
-rw-r--r--src/codegen/codegen.h2
-rw-r--r--src/codegen/codegen_decl.c9
-rw-r--r--src/codegen/codegen_main.c4
3 files changed, 6 insertions, 9 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");
}