diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:51:07 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 09:54:56 -0300 |
| commit | a02b53ca54b778cdb938d0cfb8a9b4261f9505a3 (patch) | |
| tree | 3fd3a533f0c0790f7d265f3002b84b9cce4cc2ca | |
| parent | 2ffc4abedcef7f077ebc7290b653415243da0975 (diff) | |
| download | pardes-a02b53ca54b778cdb938d0cfb8a9b4261f9505a3.tar.gz pardes-a02b53ca54b778cdb938d0cfb8a9b4261f9505a3.zip | |
build: a unit-test program is wired by one Units.add (test-build, unit-test, its one filter check, and a step of its own with its own check), where pane, behaviour, kitty, deck, shell, the freestanding roots and the perf and fs bench tests each spelled it out
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | build.zig | 92 |
1 files changed, 35 insertions, 57 deletions
@@ -1517,9 +1517,6 @@ pub fn build(b: *std.Build) void { .filters = test_filters, }); perf_tests.root_module.addOptions("perf_options", perf_options); - if (test_nonce) |nonce| perf_tests.root_module.addImport("test_rebuild_nonce", nonce); - const run_perf_test = b.addRunArtifact(perf_tests); - run_perf_test.has_side_effects = true; const fs_bench = b.addExecutable(.{ .name = "pardes-fs-bench", @@ -1545,8 +1542,6 @@ pub fn build(b: *std.Build) void { }), .filters = test_filters, }); - const run_fs_bench_test = b.addRunArtifact(fs_bench_test); - run_fs_bench_test.has_side_effects = true; const syntax_module = b.createModule(.{ .target = target, @@ -1617,13 +1612,10 @@ pub fn build(b: *std.Build) void { // The perf gate runs with every unit-test (a regression like a // contrast search per grapheme costs 100x, far past the gate). unit_step.dependOn(perf_gate_step); - const unit_match = testMatch(b, unit_profile, test_filters, unit_step); + const units: Units = .{ .nonce = test_nonce, .build = test_build, .unit = unit_step, .match = testMatch(b, unit_profile, test_filters, unit_step), .profiler = unit_profile, .filters = test_filters }; // The perf and fs bench programs' own tests: they compile no editor. - for ([_]*std.Build.Step.Compile{ perf_tests, fs_bench_test }, [_]*std.Build.Step.Run{ run_perf_test, run_fs_bench_test }) |t, run| { - test_build.dependOn(&t.step); - unit_step.dependOn(&run.step); - if (unit_match) |check| check.addArtifactArg(t); - } + _ = units.add(b, perf_tests, null); + _ = units.add(b, fs_bench_test, null); const core_test = b.addTest(.{ .root_module = core_module, .filters = test_filters }); const run_core_test = b.addRunArtifact(core_test); run_core_test.has_side_effects = true; @@ -1639,15 +1631,7 @@ pub fn build(b: *std.Build) void { pane_module.addImport("pardes", core_module); pane_module.addImport("pardes_config", core_module.import_table.get("pardes_config").?); const pane_tests = b.addTest(.{ .root_module = pane_module, .filters = test_filters }); - if (test_nonce) |nonce| pane_tests.root_module.addImport("test_rebuild_nonce", nonce); - test_build.dependOn(&pane_tests.step); - const run_pane_tests = b.addRunArtifact(pane_tests); - run_pane_tests.has_side_effects = true; - unit_step.dependOn(&run_pane_tests.step); - if (unit_match) |check| check.addArtifactArg(pane_tests); - const pane_test_step = b.step("pane-test", "run pane, output, PDF and namespace integration tests"); - pane_test_step.dependOn(&run_pane_tests.step); - if (testMatch(b, unit_profile, test_filters, pane_test_step)) |check| check.addArtifactArg(pane_tests); + _ = units.add(b, pane_tests, b.step("pane-test", "run pane, output, PDF and namespace integration tests")); // The behavioural tests (docs/next-tests.md): their module has the // session alone, so none can reach past what a 9P client sees. @@ -1669,15 +1653,8 @@ pub fn build(b: *std.Build) void { // window's word knows which build it runs in. behaviour_module.addImport("pardes_config", core_module.import_table.get("pardes_config").?); const behaviour_tests = b.addTest(.{ .root_module = behaviour_module, .filters = test_filters }); - if (test_nonce) |nonce| behaviour_tests.root_module.addImport("test_rebuild_nonce", nonce); - test_build.dependOn(&behaviour_tests.step); - const run_behaviour_tests = b.addRunArtifact(behaviour_tests); - run_behaviour_tests.has_side_effects = true; - unit_step.dependOn(&run_behaviour_tests.step); - if (unit_match) |check| check.addArtifactArg(behaviour_tests); const behaviour_test_step = b.step("behaviour-test", "run the behavioural tests, through the 9P tree alone (test/behaviour/)"); - behaviour_test_step.dependOn(&run_behaviour_tests.step); - if (testMatch(b, unit_profile, test_filters, behaviour_test_step)) |check| check.addArtifactArg(behaviour_tests); + _ = units.add(b, behaviour_tests, behaviour_test_step); // The 9P monkey at T1 (test/monkey9p.zig): random requests against // an in-process session, the documented rules checked after each. // Its fixed-seed smoke run is part of behaviour-test. @@ -1714,15 +1691,7 @@ pub fn build(b: *std.Build) void { }); kitty_module.addImport("pardes", core_module); const kitty_tests = b.addTest(.{ .root_module = kitty_module, .filters = test_filters }); - if (test_nonce) |nonce| kitty_tests.root_module.addImport("test_rebuild_nonce", nonce); - test_build.dependOn(&kitty_tests.step); - const run_kitty_tests = b.addRunArtifact(kitty_tests); - run_kitty_tests.has_side_effects = true; - unit_step.dependOn(&run_kitty_tests.step); - if (unit_match) |check| check.addArtifactArg(kitty_tests); - const kitty_test_step = b.step("kitty-test", "run the kitty graphics conformance cases for terminal panes"); - kitty_test_step.dependOn(&run_kitty_tests.step); - if (testMatch(b, unit_profile, test_filters, kitty_test_step)) |check| check.addArtifactArg(kitty_tests); + _ = units.add(b, kitty_tests, b.step("kitty-test", "run the kitty graphics conformance cases for terminal panes")); // 9p_io.zig's and fs.zig's tests as roots of their own, on the // core's imports and C libraries: native transport integration @@ -1761,12 +1730,7 @@ pub fn build(b: *std.Build) void { .filters = test_filters, }); tests.root_module.addImport("cloud9", cloud9); - if (test_nonce) |nonce| tests.root_module.addImport("test_rebuild_nonce", nonce); - test_build.dependOn(&tests.step); - const run_tests = b.addRunArtifact(tests); - run_tests.has_side_effects = true; - unit_step.dependOn(&run_tests.step); - if (unit_match) |check| check.addArtifactArg(tests); + const run_tests = units.add(b, tests, null); if (std.mem.eql(u8, entry.path, "src/9p.zig")) { protocol_step.dependOn(&run_tests.step); if (protocol_match) |check| check.addArtifactArg(tests); @@ -1783,22 +1747,10 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .root_source_file = b.path("src/gui/deck.zig"), })); - const deck_test = b.addTest(.{ .root_module = deck_module, .filters = test_filters }); - if (test_nonce) |nonce| deck_test.root_module.addImport("test_rebuild_nonce", nonce); - test_build.dependOn(&deck_test.step); - const run_deck_test = b.addRunArtifact(deck_test); - run_deck_test.has_side_effects = true; - unit_step.dependOn(&run_deck_test.step); - if (unit_match) |check| check.addArtifactArg(deck_test); + _ = units.add(b, b.addTest(.{ .root_module = deck_module, .filters = test_filters }), null); if (platform == .tui or platform == .gui) { - const shell_test = b.addTest(.{ .root_module = root_mod, .filters = test_filters }); - if (test_nonce) |nonce| shell_test.root_module.addImport("test_rebuild_nonce", nonce); - test_build.dependOn(&shell_test.step); - const run_shell_test = b.addRunArtifact(shell_test); - run_shell_test.has_side_effects = true; - unit_step.dependOn(&run_shell_test.step); - if (unit_match) |check| check.addArtifactArg(shell_test); + const run_shell_test = units.add(b, b.addTest(.{ .root_module = root_mod, .filters = test_filters }), null); // The native shell's tests alone, without the perf gate's // ReleaseFast build: what a -Dtest-filter iteration wants. b.step("shell-test", "run the native shell's unit tests (src/main.zig's)").dependOn(&run_shell_test.step); @@ -1836,6 +1788,32 @@ pub fn build(b: *std.Build) void { } } +/// What every unit-test program is wired into: test-build, unit-test, and +/// unit-test's one filter check (`match`: a filter need match in one only). +const Units = struct { + nonce: ?*std.Build.Module, + build: *std.Build.Step, + unit: *std.Build.Step, + match: ?*std.Build.Step.Run, + profiler: *std.Build.Step.Compile, + filters: []const []const u8, + + /// `t` wired in, and run by `own` too, with a filter check of its own, + /// when it has a step of its own. + fn add(u: Units, b: *std.Build, t: *std.Build.Step.Compile, own: ?*std.Build.Step) *std.Build.Step.Run { + if (u.nonce) |nonce| t.root_module.addImport("test_rebuild_nonce", nonce); + u.build.dependOn(&t.step); + const run = b.addRunArtifact(t); + run.has_side_effects = true; + u.unit.dependOn(&run.step); + if (u.match) |check| check.addArtifactArg(t); + const step = own orelse return run; + step.dependOn(&run.step); + if (testMatch(b, u.profiler, u.filters, step)) |check| check.addArtifactArg(t); + return run; + } +}; + fn testMatch(b: *std.Build, profiler: *std.Build.Step.Compile, filters: []const []const u8, step: *std.Build.Step) ?*std.Build.Step.Run { if (filters.len == 0) return null; const check = b.addRunArtifact(profiler); |
