zml/test_runner: add optional filtering of test functions via command‑line argument, allowing selective execution of tests (e.g., bazel run //zml:test -- sdpa)

This commit is contained in:
Tarry Singh 2023-01-20 13:50:36 +00:00
parent b961856e5f
commit f39b16e13d

View File

@ -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) {