This commit is contained in:
2026-02-11 18:27:44 +00:00
parent d6e65fe565
commit 0a563abefa

View File

@@ -44,9 +44,10 @@ pub fn build(b: *std.Build) !void {
const cc = b.option([]const u8, "cc", "C compiler") orelse "zig";
const no_exec = b.option(bool, "no-exec", "Compile test binary without running it") orelse false;
const valgrind = b.option(bool, "valgrind", "Run tests under valgrind") orelse false;
const test_step = b.step("test", "Run unit tests");
addTestStep(b, test_step, target, optimize, cc, no_exec);
addTestStep(b, test_step, target, optimize, cc, no_exec, valgrind);
const fmt_step = b.step("fmt", "clang-format");
const clang_format = b.addSystemCommand(&.{ "clang-format", "-i" });
@@ -102,7 +103,7 @@ pub fn build(b: *std.Build) !void {
all_step.dependOn(&fmt_check.step);
for (compilers) |compiler| {
addTestStep(b, all_step, target, optimize, compiler, false);
addTestStep(b, all_step, target, optimize, compiler, false, valgrind);
}
b.default_step = all_step;
@@ -115,6 +116,7 @@ fn addTestStep(
optimize: std.builtin.OptimizeMode,
cc: []const u8,
no_exec: bool,
valgrind: bool,
) void {
const test_mod = b.createModule(.{
.root_source_file = b.path("test_all.zig"),
@@ -144,6 +146,17 @@ fn addTestStep(
}
const test_exe = b.addTest(.{ .root_module = test_mod });
if (valgrind) {
test_exe.setExecCmd(&.{
"valgrind",
"--error-exitcode=2",
"--leak-check=full",
"--show-leak-kinds=all",
"--errors-for-leak-kinds=all",
"--track-fds=yes",
null,
});
}
if (no_exec) {
const install = b.addInstallArtifact(test_exe, .{});
step.dependOn(&install.step);