summaryrefslogtreecommitdiff
path: root/build/tests.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build/tests.zig')
-rw-r--r--build/tests.zig65
1 files changed, 25 insertions, 40 deletions
diff --git a/build/tests.zig b/build/tests.zig
index 9d4399f8..efb3515f 100644
--- a/build/tests.zig
+++ b/build/tests.zig
@@ -1,5 +1,8 @@
const std = @import("std");
const Platform = @import("../build.zig").Platform;
+const core = @import("core.zig");
+const tools = @import("tools.zig");
+const program = tools.program;
/// unit-test and the test roots it runs, each with its own step where it
/// has one: core-test, shell-test, term-test, pane-test, behaviour-test,
@@ -8,29 +11,27 @@ pub fn add(b: *std.Build, c: struct {
addon_mod: *std.Build.Module,
atlas_test: ?*std.Build.Step.Compile,
cells_test: ?*std.Build.Step.Compile,
- cloud9: *std.Build.Module,
core_lean: *std.Build.Module,
core_module: *std.Build.Module,
+ /// core_module's configuration, for the test roots that run on its imports.
+ core_cfg: core.Core,
exe: *std.Build.Step.Compile,
- fs_bench_test: *std.Build.Step.Compile,
ghostty_vt_for_tests: ?*std.Build.Module,
image_addon: *std.Build.Step.Compile,
- image_mod: *std.Build.Module,
- lib_test_step: *std.Build.Step,
+ /// The scripted language server the sessions' language words ask.
+ lspmock: *std.Build.Step.Compile,
mupdf_check: *std.Build.Step,
optimize: std.lang.Optimize,
+ parts: core.Parts,
pdf_addon: ?*std.Build.Step.Compile,
- perf_gate_step: *std.Build.Step,
- perf_tests: *std.Build.Step.Compile,
- plain_mod: *std.Build.Module,
platform: Platform,
root_mod: *std.Build.Module,
snake_shader_lib: ?*std.Build.Step.Compile,
target: std.Build.ResolvedTarget,
- term_mod: *std.Build.Module,
test_build: *std.Build.Step,
test_filters: []const []const u8,
test_nonce: ?*std.Build.Module,
+ tools: tools.Tools,
unit_profile: *std.Build.Step.Compile,
}) void {
const unit_step = b.step("unit-test", "run native shell and module unit tests");
@@ -55,12 +56,12 @@ pub fn add(b: *std.Build, c: struct {
}
// 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(c.perf_gate_step);
- unit_step.dependOn(c.lib_test_step);
+ unit_step.dependOn(c.tools.perf_gate_step);
+ unit_step.dependOn(c.tools.lib_test_step);
const units: Units = .{ .nonce = c.test_nonce, .build = c.test_build, .unit = unit_step, .match = testMatch(b, c.unit_profile, c.test_filters, unit_step), .profiler = c.unit_profile, .filters = c.test_filters };
// The perf and fs bench programs' own tests: they compile no editor.
- _ = units.add(b, c.perf_tests, null);
- _ = units.add(b, c.fs_bench_test, null);
+ _ = units.add(b, c.tools.perf_tests, null);
+ _ = units.add(b, c.tools.fs_bench_test, null);
if (c.cells_test) |t| _ = units.add(b, t, null);
if (c.atlas_test) |t| _ = units.add(b, t, null);
const core_test = b.addTest(.{ .root_module = c.core_lean, .filters = c.test_filters });
@@ -70,7 +71,7 @@ pub fn add(b: *std.Build, c: struct {
core_test_step.dependOn(&run_core_test.step);
if (testMatch(b, c.unit_profile, c.test_filters, core_test_step)) |check| check.addArtifactArg(core_test);
// The terminal module's own tests (src/term/): the emulator without a core.
- const run_term_test = units.add(b, b.addTest(.{ .root_module = c.term_mod, .filters = c.test_filters }), null);
+ const run_term_test = units.add(b, b.addTest(.{ .root_module = c.parts.term, .filters = c.test_filters }), null);
b.step("term-test", "run the terminal module's own tests (src/term/)").dependOn(&run_term_test.step);
const pane_module = b.createModule(.{
.target = c.target,
@@ -80,9 +81,11 @@ pub fn add(b: *std.Build, c: struct {
});
pane_module.addImport("pardes", c.core_module);
// test/terminal.zig reads the emulator behind a core's terminal.
- pane_module.addImport("term", c.term_mod);
- pane_module.addImport("plain", c.plain_mod);
+ pane_module.addImport("term", c.parts.term);
+ pane_module.addImport("plain", c.parts.plain);
if (c.ghostty_vt_for_tests) |x| pane_module.addImport("ghostty-vt", x);
+ // The core's own options module, not another over the same file:
+ // a file is in one module of a compilation.
pane_module.addImport("pardes_config", c.core_module.import_table.get("pardes_config").?);
const test_addons = b.addOptions();
test_addons.addOptionPath("image", c.image_addon.getEmittedBin());
@@ -104,15 +107,7 @@ pub fn add(b: *std.Build, c: struct {
// The scripted language server its language words ask
// (Session.initLanguage), as the tty cases do.
const session_options = b.addOptions();
- session_options.addOptionPath("lspmock", b.addExecutable(.{
- .name = "pardes-lspmock",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/lspmock.zig"),
- .link_libc = true,
- }),
- }).getEmittedBin());
+ session_options.addOptionPath("lspmock", c.lspmock.getEmittedBin());
var fake_addon_lib: ?*std.Build.Step.Compile = null;
// The fake addon (addons/fake/fake.c) and three copies of it built
// wrong, which the loader must refuse (test/behaviour/addons.zig).
@@ -156,7 +151,7 @@ pub fn add(b: *std.Build, c: struct {
const snake_lib = b.addLibrary(.{ .name = "snake", .linkage = .dynamic, .root_module = snake_mod });
const life_mod = b.createModule(.{ .root_source_file = b.path("addons/life/life.zig"), .target = c.target, .optimize = c.optimize, .imports = &.{.{ .name = "addon", .module = c.addon_mod }} });
const life_lib = b.addLibrary(.{ .name = "life", .linkage = .dynamic, .root_module = life_mod });
- for ([_]*std.Build.Module{ snake_mod, life_mod, c.image_mod }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).step);
+ for ([_]*std.Build.Module{ snake_mod, life_mod, c.parts.image }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).step);
// ...and the pdf addon's, which mupdf-check runs too (its script
// opens docs/design.pdf, from the build root).
const libs = [_]struct { ?*std.Build.Step.Compile, []const u8 }{ .{ fake_addon_lib.?, "addons/fake/fake" }, .{ snake_lib, "addons/snake/snake" }, .{ c.snake_shader_lib, "addons/snake_shader/snake_shader" }, .{ life_lib, "addons/life/life" }, .{ c.pdf_addon, "addons/pdf/pdf" } };
@@ -178,16 +173,7 @@ pub fn add(b: *std.Build, c: struct {
// after each, random input hunting panics (`-- --monkey <seeds>`),
// and its seeds' tapes replayed (`-- --replay`). Bare, a short
// fixed-seed run of the first, part of behaviour-test.
- const t1_runner = b.addExecutable(.{
- .name = "pardes-monkey-session",
- .root_module = b.createModule(.{
- .target = c.target,
- .optimize = c.optimize,
- .root_source_file = b.path("test/monkey9p.zig"),
- .link_libc = true,
- }),
- });
- t1_runner.root_module.addImport("session", session_module);
+ const t1_runner = program(b, "pardes-monkey-session", "test/monkey9p.zig", c.target, c.optimize, &.{.{ .name = "session", .module = session_module }});
const run_t1_runner = b.addRunArtifact(t1_runner);
run_t1_runner.addPassthruArgs();
run_t1_runner.has_side_effects = true;
@@ -215,10 +201,9 @@ pub fn add(b: *std.Build, c: struct {
.{ .path = "src/9p_io.zig", .step = "9p-io-test", .about = "run native 9P transport and client integration tests", .filters = &.{ "Unix and TCP", "one fetch", "expired sessions", "posts itself" } },
.{ .path = "src/fs.zig", .step = "fs-unit-test", .about = "run filesystem unit tests", .filters = c.test_filters },
}) |t| {
- const m = b.createModule(.{ .root_source_file = b.path(t.path), .target = c.target, .optimize = c.optimize, .link_libc = true });
- m.link_objects.appendSlice(b.allocator, c.core_module.link_objects.items) catch @panic("OOM");
- var imports = c.core_module.import_table.iterator();
- while (imports.next()) |entry| m.addImport(entry.key_ptr.*, entry.value_ptr.*);
+ var cfg = c.core_cfg;
+ cfg.root = t.path;
+ const m = core.module(b, c.parts, cfg);
b.step(t.step, t.about).dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m, .filters = t.filters })).step);
}
@@ -241,7 +226,7 @@ pub fn add(b: *std.Build, c: struct {
}),
.filters = c.test_filters,
});
- tests.root_module.addImport("cloud9", c.cloud9);
+ tests.root_module.addImport("cloud9", c.parts.cloud9);
const run_tests = units.add(b, tests, null);
if (std.mem.eql(u8, entry.path, "src/9p.zig")) {
protocol_step.dependOn(&run_tests.step);