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:
@@ -3487,8 +3487,13 @@ test "parse void function with arrow body" {
|
||||
const decl = root.data.root.decls[0];
|
||||
try std.testing.expect(decl.data == .fn_decl);
|
||||
try std.testing.expectEqualStrings("foo", decl.data.fn_decl.name);
|
||||
try std.testing.expect(decl.data.fn_decl.body.data == .int_literal);
|
||||
try std.testing.expectEqual(@as(i64, 42), decl.data.fn_decl.body.data.int_literal.value);
|
||||
try std.testing.expect(decl.data.fn_decl.is_arrow);
|
||||
// Arrow bodies are wrapped in a block; the expression is the sole stmt.
|
||||
const body = decl.data.fn_decl.body;
|
||||
try std.testing.expect(body.data == .block);
|
||||
try std.testing.expectEqual(@as(usize, 1), body.data.block.stmts.len);
|
||||
try std.testing.expect(body.data.block.stmts[0].data == .int_literal);
|
||||
try std.testing.expectEqual(@as(i64, 42), body.data.block.stmts[0].data.int_literal.value);
|
||||
}
|
||||
|
||||
test "parse hex and binary literals" {
|
||||
@@ -3526,14 +3531,13 @@ test "parse lambda with generic params" {
|
||||
var parser = Parser.init(arena.allocator(), source);
|
||||
const root = try parser.parse();
|
||||
const decl = root.data.root.decls[0];
|
||||
try std.testing.expect(decl.data == .const_decl);
|
||||
const lambda = decl.data.const_decl.value;
|
||||
try std.testing.expect(lambda.data == .lambda);
|
||||
try std.testing.expectEqual(@as(usize, 1), lambda.data.lambda.params.len);
|
||||
try std.testing.expectEqualStrings("x", lambda.data.lambda.params[0].name);
|
||||
// has generic type param
|
||||
try std.testing.expectEqual(@as(usize, 1), lambda.data.lambda.type_params.len);
|
||||
try std.testing.expectEqualStrings("T", lambda.data.lambda.type_params[0].name);
|
||||
// A named `::` arrow function is a fn_decl (carrying its own type params).
|
||||
try std.testing.expect(decl.data == .fn_decl);
|
||||
const fd = decl.data.fn_decl;
|
||||
try std.testing.expectEqual(@as(usize, 1), fd.params.len);
|
||||
try std.testing.expectEqualStrings("x", fd.params[0].name);
|
||||
try std.testing.expectEqual(@as(usize, 1), fd.type_params.len);
|
||||
try std.testing.expectEqualStrings("T", fd.type_params[0].name);
|
||||
}
|
||||
|
||||
test "parse lambda with return type" {
|
||||
@@ -3543,12 +3547,11 @@ test "parse lambda with return type" {
|
||||
var parser = Parser.init(arena.allocator(), source);
|
||||
const root = try parser.parse();
|
||||
const decl = root.data.root.decls[0];
|
||||
try std.testing.expect(decl.data == .const_decl);
|
||||
const lambda = decl.data.const_decl.value;
|
||||
try std.testing.expect(lambda.data == .lambda);
|
||||
try std.testing.expect(lambda.data.lambda.return_type != null);
|
||||
try std.testing.expect(lambda.data.lambda.return_type.?.data == .type_expr);
|
||||
try std.testing.expectEqualStrings("s32", lambda.data.lambda.return_type.?.data.type_expr.name);
|
||||
try std.testing.expect(decl.data == .fn_decl);
|
||||
const fd = decl.data.fn_decl;
|
||||
try std.testing.expect(fd.return_type != null);
|
||||
try std.testing.expect(fd.return_type.?.data == .type_expr);
|
||||
try std.testing.expectEqualStrings("s32", fd.return_type.?.data.type_expr.name);
|
||||
}
|
||||
|
||||
test "parse match with else arm" {
|
||||
|
||||
Reference in New Issue
Block a user