build: add test subcommand

zig build test can now run tests defined in main.zig and all files it
imports due to std.testing.refAllDecls.
0.10
alex 2 years ago
parent ba68c4a971
commit 4056c6dbcb

@ -17,7 +17,12 @@ pub fn build(b: *std.build.Builder) void {
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "run the executable");
run_step.dependOn(&run_cmd.step);
const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(bmode);
const test_step = b.step("test", "run tests");
test_step.dependOn(&exe_tests.step);
}

@ -176,3 +176,8 @@ fn zigStdPath(alloc: std.mem.Allocator) ![]const u8 {
defer std.json.parseFree(Env, jenv, opt);
return alloc.dupe(u8, jenv.std_dir);
}
test {
// run tests found in all @import'ed files.
std.testing.refAllDecls(@This());
}

Loading…
Cancel
Save