I have a the following directory structure:
project
|-> src
|-> main.zig
|-> stack.zig
|-> unicit
|-> prolly.zig
Inside of prolly.zig
, I have
const stack = @import("../stack.zig");
I found that when running zig build run
, I need to add the following to both lib and exec in build.zig
:
lib.addIncludePath(b.path("src"));
...some exec stuff
exe.addIncludePath(b.path("src"));
So then zig build run
works.
But now, when I run zig test ./src/unicit/prolly.zig
, it doesn’t work. It is confused about where stack.zig
is again.
This is also still the case when I run zig test ./src/unicit/prolly.zig -I src
I also tried:
const prolly_tests = b.addTest(.{
.root_source_file = b.path("src/unicit/prolly.zig"),
.target = target,
.optimize = optimize,
});
prolly_tests.addIncludePath(b.path("src")); // Add include path for tests
const run_prolly_tests = b.addRunArtifact(prolly_tests);
It’s a no go.
➜ database git:(main) ✗ zig build test
test
└─ run test
└─ zig test Debug native 1 errors
src/unicit/prolly.zig:2:23: error: import of file outside module path: '../stack.zig'
const Stack = @import("../stack.zig");
^~~~~~~~~~~~~~
referenced by:
reverseKeyPath: src/unicit/prolly.zig:205:25
test.Can find the reverse key path: src/unicit/prolly.zig:338:28
remaining reference traces hidden; use '-freference-trace' to see all reference traces
error: the following command failed with 1 compilation errors:
/Users/iamwil/.zvm/0.13.0/zig test -ODebug -I /Users/iamwil/projects/code/fruitful_town/database/src -Mroot=/Users/iamwil/projects/code/fruitful_town/database/src/unicit/prolly.zig --cache-dir /Users/iamwil/projects/code/fruitful_town/database/.zig-cache --global-cache-dir /Users/iamwil/.cache/zig --name test --listen=-
Build Summary: 4/7 steps succeeded; 1 failed (disable with --summary none)
test transitive failure
└─ run test transitive failure
└─ zig test Debug native 1 errors
error: the following build command failed with exit code 1:
/Users/iamwil/projects/code/fruitful_town/database/.zig-cache/o/c8414a20a07487128b802b1c006e99c6/build /Users/iamwil/.zvm/0.13.0/zig /Users/iamwil/projects/code/fruitful_town/database /Users/iamwil/projects/code/fruitful_town/database/.zig-cache /Users/iamwil/.cache/zig --seed 0xb8c2159e -Z538cd959a42d4f27 test
What should I do so that I can use zig test
? Or should I use zig build test
? I’m not sure what the difference is, other than there’s a test runner with the former.