diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -1528,6 +1528,24 @@ pub fn build(b: *std.Build) void { .link_libc = true, }), }).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). + for ([_]struct { []const u8, []const u8 }{ + .{ "fake_addon", "-DFAKE_PLAIN" }, + .{ "fake_addon_abi", "-DFAKE_ABI=0x20000" }, + .{ "fake_addon_no_export", "-DFAKE_NO_EXPORT" }, + .{ "fake_addon_core_word", "-DFAKE_WORD=\"Save\"" }, + .{ "fake_addon_no_dump", "-DFAKE_NO_DUMP" }, + }) |variant| { + const lib = b.addLibrary(.{ .name = variant[0], .linkage = .dynamic, .root_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }) }); + lib.root_module.addIncludePath(b.path("src/kinds")); + const name_flag = if (std.mem.eql(u8, variant[0], "fake_addon_abi")) "-DFAKE_NAME=\"fakeabi\"" else if (std.mem.eql(u8, variant[0], "fake_addon_core_word")) "-DFAKE_NAME=\"fakeword\"" else "-DFAKE_PLAIN"; + // The header is the whole contract: it compiles clean under every warning. + lib.root_module.addCSourceFile(.{ .file = b.path("addons/fake/fake.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror", "-Wno-override-init", variant[1], name_flag } }); + session_options.addOptionPath(variant[0], lib.getEmittedBin()); + if (std.mem.eql(u8, variant[0], "fake_addon")) fake_addon_lib = lib; + } session_module.addOptions("session_options", session_options); const behaviour_module = b.createModule(.{ .target = target, @@ -1542,6 +1560,19 @@ pub fn build(b: *std.Build) void { const behaviour_tests = b.addTest(.{ .root_module = behaviour_module, .filters = test_filters }); const behaviour_test_step = b.step("behaviour-test", "run the behavioural tests, through the 9P tree alone (test/behaviour/)"); _ = units.add(b, behaviour_tests, behaviour_test_step); + // An addon's own test, the template's: `--addon-test` over the fake + // and its script, compared with what it printed when written. + if (fake_addon_lib) |fake_lib| { + const run_addon_test = b.addRunArtifact(exe); + run_addon_test.addArg("--addon-test"); + run_addon_test.addArtifactArg(fake_lib); + run_addon_test.addFileArg(b.path("addons/fake/fake.script")); + const compare = b.addSystemCommand(&.{ "diff", "-u" }); + compare.addFileArg(b.path("addons/fake/fake.out")); + compare.addFileArg(run_addon_test.captureStdOut(.{})); + behaviour_test_step.dependOn(&compare.step); + b.step("addon-test", "pardes --addon-test over the fake addon, against addons/fake/fake.out").dependOn(&compare.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. |
