build: refactor test code
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
164e52cd85
commit
aaac8ebbfd
1 changed files with 16 additions and 16 deletions
22
build.zig
22
build.zig
|
|
@ -48,24 +48,24 @@ pub fn build(b: *std.Build) !void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
|
|
||||||
if (target.getCpuArch() != .wasm32) {
|
if (target.getCpuArch() != .wasm32) {
|
||||||
const tests_step = b.step("test", "Run tests");
|
// Creates a step for unit testing. This only builds the test executable
|
||||||
tests_step.dependOn(&testStep(b, optimize, target).step);
|
// but does not run it.
|
||||||
}
|
const unit_tests = b.addTest(.{
|
||||||
}
|
|
||||||
|
|
||||||
fn testStep(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.RunStep {
|
|
||||||
const main_tests = b.addTest(.{
|
|
||||||
.name = "mach-tests",
|
|
||||||
.root_source_file = .{ .path = "src/main.zig" },
|
.root_source_file = .{ .path = "src/main.zig" },
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
var iter = module(b, optimize, target).dependencies.iterator();
|
var iter = module(b, optimize, target).dependencies.iterator();
|
||||||
while (iter.next()) |e| {
|
while (iter.next()) |e| {
|
||||||
main_tests.addModule(e.key_ptr.*, e.value_ptr.*);
|
unit_tests.addModule(e.key_ptr.*, e.value_ptr.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exposes a `test` step to the `zig build --help` menu, providing a way for the user to
|
||||||
|
// request running the unit tests.
|
||||||
|
const run_unit_tests = b.addRunArtifact(unit_tests);
|
||||||
|
const test_step = b.step("test", "Run unit tests");
|
||||||
|
test_step.dependOn(&run_unit_tests.step);
|
||||||
}
|
}
|
||||||
b.installArtifact(main_tests);
|
|
||||||
return b.addRunArtifact(main_tests);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const App = struct {
|
pub const App = struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue