commit 3f315398fc92dbb08af2ce423cd4ce95c579fdb4 (tree)
parent 8f5c0177e2b6630a8cfb3ac57f1bd61dee30e7cc
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Sat, 14 Feb 2026 14:19:15 +0000
simplify zig0 test setup: single test module, remove zig0_test.zig
Consolidate the two separate test modules (test_mod via
lib/std/zig/zig0_test.zig + astgen_test_mod via stage0_test_root.zig)
into a single test module rooted at stage0_test_root.zig.
The zig0_test.zig bridge approach ran std's parser/tokenizer tests with
C comparison enabled, but the stage0/ test files already do the same
C-vs-Zig comparison directly via @cImport. The only "lost" tests are an
unnamed root test block and a Zig-only fuzz test — no zig0 coverage lost.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
3 files changed, 30 insertions(+), 56 deletions(-)
diff --git a/build.zig b/build.zig
@@ -1606,65 +1606,43 @@ fn addZig0TestStep(
valgrind: bool,
test_timeout: ?[]const u8,
) void {
- const bridge_mod = b.createModule(.{
- .root_source_file = b.path("stage0/zig0_bridge.zig"),
- .target = target,
- .optimize = optimize,
- });
- bridge_mod.addIncludePath(b.path("stage0"));
-
- // Parser + tokenizer tests (hooks into std's test files via zig0 bridge)
const test_mod = b.createModule(.{
- .root_source_file = b.path("lib/std/zig/zig0_test.zig"),
- .optimize = optimize,
- .target = target,
- });
- test_mod.addImport("zig0_bridge", bridge_mod);
-
- // AstGen tests (standalone C-vs-Zig ZIR comparison)
- const astgen_test_mod = b.createModule(.{
.root_source_file = b.path("stage0_test_root.zig"),
.optimize = optimize,
.target = target,
});
- astgen_test_mod.addIncludePath(b.path("stage0"));
+ test_mod.addIncludePath(b.path("stage0"));
+ addZig0CSources(b, test_mod, cc, optimize);
+ test_mod.linkSystemLibrary("c", .{});
const timeout: ?[]const u8 = test_timeout orelse if (valgrind) null else "10";
- for ([_]struct { mod: *std.Build.Module, name: []const u8 }{
- .{ .mod = test_mod, .name = "test" },
- .{ .mod = astgen_test_mod, .name = "astgen_test" },
- }) |entry| {
- addZig0CSources(b, entry.mod, cc, optimize);
- entry.mod.linkSystemLibrary("c", .{});
-
- const test_exe = b.addTest(.{
- .root_module = entry.mod,
- .use_llvm = false,
- .use_lld = false,
+ const test_exe = b.addTest(.{
+ .root_module = test_mod,
+ .use_llvm = false,
+ .use_lld = false,
+ });
+ if (valgrind) {
+ test_exe.setExecCmd(&.{
+ "valgrind",
+ "--error-exitcode=2",
+ "--leak-check=full",
+ "--show-leak-kinds=all",
+ "--errors-for-leak-kinds=all",
+ "--track-fds=yes",
+ "--quiet",
+ null,
});
- if (valgrind) {
- test_exe.setExecCmd(&.{
- "valgrind",
- "--error-exitcode=2",
- "--leak-check=full",
- "--show-leak-kinds=all",
- "--errors-for-leak-kinds=all",
- "--track-fds=yes",
- "--quiet",
- null,
- });
- } else {
- test_exe.setExecCmd(&.{ "timeout", timeout orelse "10", null });
- }
- if (no_exec) {
- const install = b.addInstallArtifact(test_exe, .{});
- step.dependOn(&install.step);
- } else {
- const run = b.addRunArtifact(test_exe);
- run.step.name = b.fmt("{s} ({s})", .{ entry.name, cc });
- step.dependOn(&run.step);
- }
+ } else {
+ test_exe.setExecCmd(&.{ "timeout", timeout orelse "10", null });
+ }
+ if (no_exec) {
+ const install = b.addInstallArtifact(test_exe, .{});
+ step.dependOn(&install.step);
+ } else {
+ const run = b.addRunArtifact(test_exe);
+ run.step.name = b.fmt("test ({s})", .{cc});
+ step.dependOn(&run.step);
}
}
diff --git a/lib/std/zig/zig0_test.zig b/lib/std/zig/zig0_test.zig
@@ -1,6 +0,0 @@
-pub const zig0 = @import("zig0_bridge");
-
-test {
- _ = @import("parser_test.zig");
- _ = @import("tokenizer.zig");
-}
diff --git a/stage0_test_root.zig b/stage0_test_root.zig
@@ -1,3 +1,5 @@
test {
+ _ = @import("stage0/tokenizer_test.zig");
+ _ = @import("stage0/parser_test.zig");
_ = @import("stage0/astgen_test.zig");
}