I am trying to add tests to a Zig file towards this PR. But zig test <filepath>
doesn't work because there is no platform supplying roc_alloc
. What is the simplest way to run such tests
Hmm...we provide testing versions of the allocator in the utils.zig file which should be loaded. That is how list tests work despite depending on roc_alloc
Whatever I am doing wring also applies to list.zig
matthew@mjh:~/repos/rocSHA$ zig test crates/compiler/builtins/bitcode/src/list.zig
error: ld.lld: undefined symbol: getppid
note: referenced by utils.zig:36 (/home/matthew/repos/rocSHA/crates/compiler/builtins/bitcode/src/utils.zig:36)
note: /home/matthew/.cache/zig/o/ce4054c98a5b4dc8af6dbdc9be616a31/test.o:(roc_getppid)
error: ld.lld: undefined symbol: mmap
note: referenced by utils.zig:47 (/home/matthew/repos/rocSHA/crates/compiler/builtins/bitcode/src/utils.zig:47)
note: /home/matthew/.cache/zig/o/ce4054c98a5b4dc8af6dbdc9be616a31/test.o:(roc_mmap)
error: ld.lld: undefined symbol: shm_open
note: referenced by utils.zig:44 (/home/matthew/repos/rocSHA/crates/compiler/builtins/bitcode/src/utils.zig:44)
note: /home/matthew/.cache/zig/o/ce4054c98a5b4dc8af6dbdc9be616a31/test.o:(roc_shm_open)
Oh is it setting DEBUG_TESTING_ALLOC
to true in utils?
no... that's just providing console output
Hmm, those 3 symbols shouldn't be used anywhere in the zig tests
They may not have a testing version created
The relevant value seems to be builtin.is_test
where builtin = @import("builtin");
zig build test
should work for you
Or I guess zig test
if you tell it to link libc
I think everything is wired correctly for adding testing allocators and such, but they depend on libc
zig build test
fails because it can't find a build.zig
file.
I think maybe I am just running these commands from the wrong folder
hmm--this is at least something else
matthew@mjh:~/repos/rocSHA/crates/compiler/builtins/bitcode$ zig build test crates/compiler/builtins/bitcode/src/list.zig
/home/matthew/repos/rocSHA/crates/compiler/builtins/bitcode/build.zig:19:38: error: no field named 'path' in union 'Build.LazyPath'
const main_tests = b.addTest(.{ .root_source_file = main_path, .link_libc = true });
~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/snap/zig/11625/lib/std/Build.zig:2171:22: note: union declared here
pub const LazyPath = union(enum) {
^~~~~
referenced by:
runBuild__anon_8831: /snap/zig/11625/lib/std/Build.zig:2116:27
main: /snap/zig/11625/lib/compiler/build_runner.zig:301:29
remaining reference traces hidden; use '-freference-trace' to see all reference traces
I think you're on the wrong version of zig. We're still on 0.11.0
They changed the way paths were done in later versions, so this is what makes me think that, 38: error: no field named 'path' in union 'Build.LazyPath'
More specifically, I was in the wrong terminal. Thanks
Matthew Heath has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC