diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 70 |
1 files changed, 70 insertions, 0 deletions
@@ -4,6 +4,11 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + // -Dtrace: make the e2e runner print the captured screen state (after each + // pump/waitFor and on every assertion) so failures can be inspected live. + // Usage: `zig build test -Dtrace`. + const trace = b.option(bool, "trace", "print captured tty/screen state during e2e tests") orelse false; + const exe = b.addExecutable(.{ .name = "pardes", .root_module = b.createModule(.{ @@ -67,6 +72,10 @@ pub fn build(b: *std.Build) void { const ghostty_vt = dep.module("ghostty-vt"); ghostty_vt.addImport("uucode", uucode_mod); exe.root_module.addImport("ghostty-vt", ghostty_vt); + // The e2e test harness parses the app's pty output with its own ghostty + // terminal (reads the 2D screen grid, not raw bytes), so it needs the + // same module. + tests.root_module.addImport("ghostty-vt", ghostty_vt); } // Override uucode on vaxis last, so it wins over ghostty's build() above. @@ -78,8 +87,69 @@ pub fn build(b: *std.Build) void { const run = b.step("run", "descend to the pardes"); run.dependOn(&run_exe.step); + // tutor_gen: a separate binary that parses tutor.txt and writes + // tutor_cases.zig (a file of `test` blocks, one per practice block). + // `zig build tutor-gen` runs it; the unit-test step depends on the output. + const tutor_gen = b.addExecutable(.{ + .name = "tutor-gen", + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("tutor_gen.zig"), + }), + }); + const run_tutor_gen = b.addRunArtifact(tutor_gen); + run_tutor_gen.addArg("tutor.txt"); + const tutor_cases_lazy = run_tutor_gen.addOutputFileArg("tutor_cases.zig"); + const tutor_gen_step = b.step("tutor-gen", "regenerate tutor_cases.zig from tutor.txt"); + tutor_gen_step.dependOn(&run_tutor_gen.step); + const run_tests = b.addRunArtifact(tests); run_tests.addArtifactArg(exe); + + // Expose build-time flags (e.g. -Dtrace) to the test runner as an importable + // `config` module. tests.zig reads `config.trace` and hands it to the harness. + const test_opts = b.addOptions(); + test_opts.addOption(bool, "trace", trace); + tests.root_module.addOptions("config", test_opts); + const test_step = b.step("test", "run deterministic tests"); test_step.dependOn(&run_tests.step); + + // Unit tests for the pure modal-editing math (modal.zig has no vaxis/ghostty + // deps, so `zig test` on it is fast and needs no wired-in modules). + const unit_tests = b.addTest(.{ + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("modal.zig"), + }), + }); + const run_unit = b.addRunArtifact(unit_tests); + const unit_step = b.step("unit-test", "run modal.zig unit tests"); + unit_step.dependOn(&run_unit.step); + test_step.dependOn(&run_unit.step); + + // Tutor practice blocks as unit tests: a second `zig test` target over the + // generated tutor_cases.zig (which imports modal.zig). Depends on tutor-gen + // so the file is (re)generated first. + const tutor_tests = b.addTest(.{ + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = tutor_cases_lazy, + }), + }); + // The generated cases `@import("modal")` (a module name, not a relative + // path, since the generated file lives in the cache dir, not next to modal.zig). + const modal_for_tutor = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = b.path("modal.zig"), + }); + tutor_tests.root_module.addImport("modal", modal_for_tutor); + const run_tutor = b.addRunArtifact(tutor_tests); + const tutor_step = b.step("tutor-test", "run the tutor practice-block tests"); + tutor_step.dependOn(&run_tutor.step); + test_step.dependOn(&run_tutor.step); } |
