#how to stop compilation if tests fail?

1 messages · Page 1 of 1 (latest)

spiral jewel
#

i'm trying to modify my zig build run setup so that if tests fail, the app won't run.
but it only tells me that tests fail after i let the app normally close

i know i can chain zig build test && zig build run but i'm wondering if i can let the build system do it for me instead of having to use two commands.

this is my test step code in build.zig

    const test_step = b.step("test", "Run unit tests");

    test_step.dependOn(&run_lib_unit_tests.step);
    test_step.dependOn(&run_exe_unit_tests.step);

    const run_cmd = b.addRunArtifact(exe);
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(test_step);
    run_step.dependOn(b.getInstallStep());
    run_step.dependOn(&run_cmd.step);
weary skiff
#

Because test should depend on install right? (Maybe transitively through the run unit test steps

spiral jewel
#

that did not do anything unfortunately.

#

here's my entire build script. minmized to only contaain the test and run code


pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const lib = b.addLibrary(.{
        .name = Constants.Root.exe_name,
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/root.zig"),
            .target = target,
            .optimize = optimize,
        }),
    });
    b.installArtifact(lib);
    const exe = b.addExecutable(.{
        .name = Constants.Root.exe_name,
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
        }),
    });
    b.installArtifact(exe);

    const lib_unit_tests = b.addTest(.{ .root_module = lib.root_module,});
    const exe_unit_tests = b.addTest(.{ .root_module = exe.root_module,});

    const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
    const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

    const test_step = b.step("test", "Run unit tests");

    test_step.dependOn(&run_lib_unit_tests.step);
    test_step.dependOn(&run_exe_unit_tests.step);

    const run_cmd = b.addRunArtifact(exe);
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(test_step);
    run_step.dependOn(&run_cmd.step);

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
}

weary skiff
spiral jewel
weary skiff
#

So run added first then test

spiral jewel
#

does nothing unfortunately