#confusion about steps and unit tests in build.zig

1 messages · Page 1 of 1 (latest)

bright aspen
#

in my build.zig i set up a test step and then make running my libraries unit tests. something like

const test_step = b.step("test", "Run unit tests");
const lib_unit_tests = b.addTest(.{
    .root_source_file = .{ .path = "src/mylib.zig" },
    .target = target,
    .optimize = optimize,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
test_step.dependOn(&run_lib_unit_tests.step);
// and then add the executable's tests in a similar way.

this is all fine and good, but i have no clue how to run test_step from the zig build cli. and if that isn't possible (it doesn't seem so?)... is there any point to setting things up like this?

twin valley
#

zig build test should run the "test" step you just defined.

bright aspen
#

oh hm

#

yeah that seems to do things (i was trying zig test)

#

is it the case that zig build <toplevelstep name> should run any top level build step?

#

(sorry, i'm very new with zig)

#

it seems so, neat

twin valley
#

I believe that's the idea. When you do a b.step("some_step_name", "some_description") you basically define a zig build some_step_name to be executed from the cli.

bright aspen
#

yeah great

#

for some reason i thought those would be under zig run or something other than zig build