Skip to content

Commit a20fe50

Browse files
test: add test step in build.zig
- add all unit tests in test bundle script - add test step
1 parent 5fe9c76 commit a20fe50

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

build.zig

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ pub fn build(b: *STD.Build) !void {
1616

1717
// cli
1818
{
19-
const CPPLINGS_CLI = b.addExecutable(.{ .name = "cpplings_cli", .root_module = b.createModule(.{
20-
.target = TARGET,
21-
.optimize = OPTIMIZE,
22-
.root_source_file = b.path("src/main.zig"),
23-
}) });
19+
const CPPLINGS_CLI = b.addExecutable(.{
20+
.name = "cpplings_cli",
21+
.root_module = b.createModule(.{
22+
.target = TARGET,
23+
.optimize = OPTIMIZE,
24+
.root_source_file = b.path("src/main.zig"),
25+
}),
26+
});
2427

2528
b.installArtifact(CPPLINGS_CLI);
2629
const CPPLINGS_CLI_ARTIFIACT = b.addRunArtifact(CPPLINGS_CLI);
@@ -36,6 +39,23 @@ pub fn build(b: *STD.Build) !void {
3639
}
3740
}
3841

42+
// tests
43+
{
44+
const CPPLINGS_CLI_TESTS = b.addTest(.{
45+
.name = "cpplings_tests",
46+
.root_module = b.createModule(.{
47+
.target = TARGET,
48+
.optimize = OPTIMIZE,
49+
.root_source_file = b.path("src/test.zig"),
50+
}),
51+
});
52+
53+
const CPPLINGS_CLI_TESTS_ARTIFACT = b.addRunArtifact(CPPLINGS_CLI_TESTS);
54+
55+
const CPPLINGS_CLI_TESTS_STEP = b.step("tests", "Run cpplings tests");
56+
CPPLINGS_CLI_TESTS_STEP.dependOn(&CPPLINGS_CLI_TESTS_ARTIFACT.step);
57+
}
58+
3959
// exercises
4060
{
4161
const COMPILER_FLAGS = [_][]const u8{ "-std=c++23", "-Wall", "-Werror", "-Wextra" };

src/test.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const STD = @import("std");
22

3-
const CLI = @import("cli.zig");
4-
const PATCH = @import("patch.zig");
5-
const UTIL = @import("util.zig");
6-
73
test "run all tests" {
84
STD.testing.refAllDecls(@This());
5+
6+
comptime {
7+
_ = @import("cli.zig");
8+
_ = @import("patch.zig");
9+
_ = @import("util.zig");
10+
}
911
}

0 commit comments

Comments
 (0)