How do I know which files, or which tests, `zig build test` covers?

I have a default build.zig file from zig init.

My main.zig file has a couple local imports, like const foo = @import("./foo.zig") and foo.zig contains another relative import.

In my main.zig I have:

test {
    std.testing.refAllDeclsRecursive(@This());
}

I thought this would run every test in main.zig, and every test in every file I transitively import from main.zig.

But the output from zig build test --summary all is:

Build Summary: 5/5 steps succeeded; 7/7 tests passed
test success
├─ run test 1 passed 2ms MaxRSS:2M
│  └─ zig test Debug native cached 55ms MaxRSS:58M
└─ run test 6 passed 3ms MaxRSS:4M
   └─ zig test Debug native cached 55ms MaxRSS:58M

This doesn’t look right to me at first glance. I have exactly one other test in main.zig, so maybe that’s the 1 passed test, and then 6 passed is the collection of all the transitive imports’ tests? I could temporarily inject failures into the other tests I think it is supposed to run, or I could add new tests in the other files to see if the count goes up, but neither of those seem like the right solution to understand what exactly is being run in tests.

It could also be that I am misunderstanding std.testing.refAllDeclsRecursive, but if so I would still want to confirm that by seeing what tests are actually run in this setup.

Is there another option I can pass to zig build test to print out which files it is testing, or the fully qualified names of the tests it runs? I am not seeing any relevant flags in zig build test --help.

I’m running 0.14.0-dev.2097+d30e28754.

IMHO the test runner is one of the current pain-points in Zig. I hope it gets fixed/improved one day but you can also use your own test-runner.

@karlseguin shared one which you can use for reference

2 Likes

related: