From f39b16e13da52878213ca93491118f2ea98a981d Mon Sep 17 00:00:00 2001 From: Tarry Singh Date: Fri, 20 Jan 2023 13:50:36 +0000 Subject: [PATCH] =?UTF-8?q?zml/test=5Frunner:=20add=20optional=20filtering?= =?UTF-8?q?=20of=20test=20functions=20via=20command=E2=80=91line=20argumen?= =?UTF-8?q?t,=20allowing=20selective=20execution=20of=20tests=20(e.g.,=20`?= =?UTF-8?q?bazel=20run=20//zml:test=20--=20sdpa`)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zml/test_runner.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/zml/test_runner.zig b/zml/test_runner.zig index 0ff5ad6..7c0fe69 100644 --- a/zml/test_runner.zig +++ b/zml/test_runner.zig @@ -25,7 +25,7 @@ pub fn main() anyerror!void { } pub fn asyncMain() void { - const test_fn_list = builtin.test_functions; + const test_fn_list: []const std.builtin.TestFn = builtin.test_functions; var ok_count: usize = 0; var skip_count: usize = 0; var fail_count: usize = 0; @@ -35,9 +35,24 @@ pub fn asyncMain() void { }); const have_tty = std.io.getStdErr().isTty(); + var args = std.process.args(); + // Skip executable path + _ = args.next().?; + + const identifier_query = if (args.next()) |arg| blk: { + std.debug.print("Only tests with identifiers that includes `{s}` will be run\n", .{arg}); + break :blk arg; + } else blk: { + break :blk ""; + }; + var leaks: usize = 0; for (test_fn_list, 0..) |test_fn, i| { + if (std.mem.indexOf(u8, test_fn.name, identifier_query) == null) { + continue; + } + testing.allocator_instance = .{}; defer { if (testing.allocator_instance.deinit() == .leak) {