test: make zig build test actually run all tests + fix latent rot
root.zig had no `test` block, so the test binary discovered zero tests and trivially "passed" — every src test had silently rotted. Add `refAllDecls(@This())` to root.zig so all 185 tests run, then fix the rot it surfaced: - emit_llvm.test: operands were constants, so LLVM folded the very instructions being asserted (fadd/sub/icmp/insertvalue/extractvalue/sext). Rewrite to use function-parameter operands; `main` now returns i32 (entry convention); tagged-union enum_init lowers via memory, not insertvalue. - interp.test: switch the per-test allocator to an arena (the interpreter is arena-style and intentionally frees little) — clears the transient-Value leaks without an ownership-ambiguous source change. - lower.test: pass `is_imported` to lowerFunction; mark two helpers `pub`; the if/else block test now uses a runtime (param) condition since lowering folds `if true`. - print.test: SSA numbering — params occupy %0/%1, so consts start at %2. - jni_java_emit.test: nested-class refs render in Java source form (`SurfaceHolder.Callback`), not the JNI `$` form. Leaks fixed at the source where ownership was clear: Module gains an arena for the operand slices the Builder dupes (struct/call/branch/switch args, block params, lowerFunction params); objcDefinedStateStructType builds its field slice in that arena and frees its temp name string.
This commit is contained in:
@@ -26,7 +26,9 @@ fn str(module: *Module, s: []const u8) types.StringId {
|
||||
// ── Basic interpreter tests (migrated from interp.zig) ──────────────────
|
||||
|
||||
test "interpret: compute(5) = 25" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
|
||||
@@ -51,7 +53,9 @@ test "interpret: compute(5) = 25" {
|
||||
}
|
||||
|
||||
test "interpret: if/else branching" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
|
||||
@@ -89,7 +93,9 @@ test "interpret: if/else branching" {
|
||||
}
|
||||
|
||||
test "interpret: function calling another function" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
|
||||
@@ -129,7 +135,9 @@ test "interpret: function calling another function" {
|
||||
}
|
||||
|
||||
test "interpret: alloca/store/load" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
|
||||
@@ -164,7 +172,9 @@ test "interpret: alloca/store/load" {
|
||||
// Expected: 55
|
||||
|
||||
test "comptime: while loop — sumOf10 = 55" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -222,7 +232,9 @@ test "comptime: while loop — sumOf10 = 55" {
|
||||
// Expected: 42 + 99 = 141
|
||||
|
||||
test "comptime: optional coalesce — ct_sum = 141" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -267,7 +279,9 @@ test "comptime: optional coalesce — ct_sum = 141" {
|
||||
// Expected: 77
|
||||
|
||||
test "comptime: optional unwrap — 77" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -296,7 +310,9 @@ test "comptime: optional unwrap — 77" {
|
||||
// Expected: fib(10) = 55
|
||||
|
||||
test "comptime: recursive fibonacci — fib(10) = 55" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -341,7 +357,9 @@ test "comptime: recursive fibonacci — fib(10) = 55" {
|
||||
// Expected: compute(5) = 7
|
||||
|
||||
test "comptime: compute(5) = 7" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -370,7 +388,9 @@ test "comptime: compute(5) = 7" {
|
||||
// Simulates calling add(25, 5) to verify chaining works.
|
||||
|
||||
test "comptime: chained — add(add(10,15), 5) = 30" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -406,7 +426,9 @@ test "comptime: chained — add(add(10,15), 5) = 30" {
|
||||
// Expected: 7
|
||||
|
||||
test "comptime: struct init and field access — 7" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -438,7 +460,9 @@ test "comptime: struct init and field access — 7" {
|
||||
// Expected: compute(3.0) = 8.5
|
||||
|
||||
test "comptime: float arithmetic — 8.5" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -469,7 +493,9 @@ test "comptime: float arithmetic — 8.5" {
|
||||
// test(false, true) → (false and true) or (not false) = false or true = true
|
||||
|
||||
test "comptime: boolean logic" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -505,7 +531,9 @@ test "comptime: boolean logic" {
|
||||
// ── Test: negation ──────────────────────────────────────────────────────
|
||||
|
||||
test "comptime: negation — int and float" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -529,7 +557,9 @@ test "comptime: negation — int and float" {
|
||||
// ── Test: modulo ────────────────────────────────────────────────────────
|
||||
|
||||
test "comptime: modulo — 17 mod 5 = 2" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -554,7 +584,9 @@ test "comptime: modulo — 17 mod 5 = 2" {
|
||||
// Simulates: match tag { 0 => 10, 1 => 20, else => 30 }
|
||||
|
||||
test "comptime: switch_br dispatch" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -603,7 +635,9 @@ test "comptime: switch_br dispatch" {
|
||||
// ── Test: enum init + tag extraction ────────────────────────────────────
|
||||
|
||||
test "comptime: enum init and tag" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -627,7 +661,9 @@ test "comptime: enum init and tag" {
|
||||
// ── Test: conversion (widen/narrow passthrough) ─────────────────────────
|
||||
|
||||
test "comptime: widen/narrow passthrough" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -651,7 +687,9 @@ test "comptime: widen/narrow passthrough" {
|
||||
// ── Test: const_type produces a Value.type_tag ──────────────────────────
|
||||
|
||||
test "comptime: const_type yields type_tag" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -680,7 +718,9 @@ test "comptime: const_type yields type_tag" {
|
||||
// ── Test: type equality via cmp_eq on .type_tag operands ────────────────
|
||||
|
||||
test "comptime: type_tag comparison" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -717,7 +757,9 @@ test "comptime: type_tag comparison" {
|
||||
// ── Test: type_name builtin reads .type_tag, returns the typeName ───────
|
||||
|
||||
test "comptime: type_name builtin on type_tag" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
@@ -740,7 +782,9 @@ test "comptime: type_name builtin on type_tag" {
|
||||
// ── Test: type_eq builtin on two .type_tag operands ────────────────────
|
||||
|
||||
test "comptime: type_eq builtin on type_tag values" {
|
||||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
var module = Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var b = Builder.init(&module);
|
||||
|
||||
Reference in New Issue
Block a user