Trying to run test with cmdline args

test {
   const allocator = std.testing.allocator;

   const args = try std.process.argsAlloc(allocator);
   defer std.process.argsFree(allocator, args);

   std.debug.print("Arguments: {s}\n", .{args});
}

test cmd:
zig test args.zig --test-cmd-bin --test-cmd hello

receiving error message:
error: the following test command failed with exit code 3

any help will be appreciated. thank you

I believe you’re hitting this panic in test_runner.zig:

This is the relevant commit where this panic was added: make the build runner and test runner talk to each other · ziglang/zig@ede5dcf · GitHub

1 Like

Yes that’s it. I checked the commit. So I am supposed to use this --listen=- parameter somehow? Or I need to add some panic handler? I’m confused

Okay… looks like I was able to get this running by using a custom test runner which bypasses the panic. So i copied the default test_runner.zig to my src directory (renaming to test_runner_custom.zig),

changed the line:
@panic(“unrecognized command line argument”);

to:
“listen=false;”

then reran the test as:
zig test args.zig --test-cmd-bin --test-cmd “hello” --test-runner .\test_runner_custom.zig

I guess I am satisfied with this for now, just it seems like i should be able to do something simple like:
zig test args.zig --arg1 hello

2 Likes