I'm trying Zig for the first time, and I don't really understand how to conveniently organize tests with the build system. Right now, all my tests are in the same files as the function implementations, after which I collect all the files into one test block like this (tests.zig):
test {
_ = @import("main.zig");
_ = @import("day1.zig");
_ = @import("day2.zig");
_ = @import("tools.zig");
}
And in build.zig I run them using
const exe_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_exe_tests = b.addRunArtifact(exe_tests);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(&run_exe_tests.step);
But this looks very cursed. If in any of the files tested in tests.zig I do an import by module name instead of by file name, the tests won't start. Example: