Skip to content

Commit 5fcf1c1

Browse files
committed
Added root projects to run all tests and all examples
1 parent 40d5277 commit 5fcf1c1

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

2024/02/red_nosed_reports/build.zig

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,47 @@ pub fn build(b: *std.Build) void {
1010
});
1111

1212
// -------------------------- Main executable --------------------------- \\
13-
const exe = b.addExecutable(.{
13+
const red_nosed_reports_exe = b.addExecutable(.{
1414
.name = "red_nosed_reports",
1515
.root_source_file = b.path("src/main.zig"),
1616
.target = target,
1717
.optimize = optimize,
1818
});
1919

2020
const yazap = b.dependency("yazap", .{});
21-
exe.root_module.addImport("yazap", yazap.module("yazap"));
22-
exe.root_module.addImport("red_nosed_reports", red_nosed_reports);
23-
b.installArtifact(exe);
21+
red_nosed_reports_exe.root_module.addImport("yazap", yazap.module("yazap"));
22+
red_nosed_reports_exe.root_module.addImport("red_nosed_reports", red_nosed_reports);
23+
b.installArtifact(red_nosed_reports_exe);
2424

25-
const run_cmd = b.addRunArtifact(exe);
25+
const run_cmd = b.addRunArtifact(red_nosed_reports_exe);
2626
run_cmd.step.dependOn(b.getInstallStep());
2727
if (b.args) |args| {
2828
run_cmd.addArgs(args);
2929
}
3030

31-
const run_step = b.step("run", "Run the app");
31+
const run_step = b.step("run", "Run the red_nosed_reports (day 02) app");
3232
run_step.dependOn(&run_cmd.step);
3333

3434
// --------------------------- Example tests ---------------------------- \\
35-
const example_tests = b.addTest(.{
35+
const red_nosed_reports_tests = b.addTest(.{
36+
.name = "red_nosed_reports_tests",
3637
.root_source_file = b.path("tests/example_tests.zig"),
3738
.target = target,
3839
.optimize = optimize,
3940
});
4041

41-
example_tests.root_module.addImport("red_nosed_reports", red_nosed_reports);
42-
example_tests.root_module.addAnonymousImport("example_input", .{
42+
red_nosed_reports_tests.root_module.addImport("red_nosed_reports", red_nosed_reports);
43+
red_nosed_reports_tests.root_module.addAnonymousImport("example_input", .{
4344
.root_source_file = b.path("input/example_input.txt"),
4445
});
46+
b.installArtifact(red_nosed_reports_tests);
4547

46-
const run_example_tests = b.addRunArtifact(example_tests);
47-
const test_step = b.step("test", "Run example tests");
48-
test_step.dependOn(&run_example_tests.step);
48+
const test_step = b.step("test", "Run red_nosed_reports (day 02) tests");
49+
test_step.dependOn(&b.addRunArtifact(red_nosed_reports_tests).step);
4950

5051
// ------------------------- Puzzle benchmarks -------------------------- \\
51-
const puzzle_benchmarks = b.addExecutable(.{
52-
.name = "red_nosed_reports_benchmark",
52+
const red_nosed_reports_benchmarks = b.addExecutable(.{
53+
.name = "red_nosed_reports_benchmarks",
5354
.root_source_file = b.path("benchmarks/puzzle_benchmarks.zig"),
5455
.target = target,
5556
.optimize = optimize,
@@ -59,13 +60,13 @@ pub fn build(b: *std.Build) void {
5960
.target = target,
6061
.optimize = optimize,
6162
});
62-
puzzle_benchmarks.root_module.addImport("zbench", zbench.module("zbench"));
63-
puzzle_benchmarks.root_module.addImport("red_nosed_reports", red_nosed_reports);
64-
puzzle_benchmarks.root_module.addAnonymousImport("puzzle_input", .{
63+
red_nosed_reports_benchmarks.root_module.addImport("zbench", zbench.module("zbench"));
64+
red_nosed_reports_benchmarks.root_module.addImport("red_nosed_reports", red_nosed_reports);
65+
red_nosed_reports_benchmarks.root_module.addAnonymousImport("puzzle_input", .{
6566
.root_source_file = b.path("input/puzzle_input.txt"),
6667
});
68+
b.installArtifact(red_nosed_reports_benchmarks);
6769

68-
const run_puzzle_benchmarks = b.addRunArtifact(puzzle_benchmarks);
69-
const benchmark_step = b.step("benchmark", "Run puzzle benchmarks");
70-
benchmark_step.dependOn(&run_puzzle_benchmarks.step);
70+
const benchmark_step = b.step("benchmark", "Run red_nosed_reports (day 02) benchmarks");
71+
benchmark_step.dependOn(&b.addRunArtifact(red_nosed_reports_benchmarks).step);
7172
}

0 commit comments

Comments
 (0)