Stream: compiler development

Topic: ✔ Running tests for zig builtins


view this post on Zulip Matthew Heath (Nov 29 2024 at 17:58):

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

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 18:56):

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

view this post on Zulip Matthew Heath (Nov 29 2024 at 19:10):

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)

view this post on Zulip Matthew Heath (Nov 29 2024 at 19:13):

Oh is it setting DEBUG_TESTING_ALLOC to true in utils?

view this post on Zulip Matthew Heath (Nov 29 2024 at 19:16):

no... that's just providing console output

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 19:23):

Hmm, those 3 symbols shouldn't be used anywhere in the zig tests

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 19:24):

They may not have a testing version created

view this post on Zulip Matthew Heath (Nov 29 2024 at 19:26):

The relevant value seems to be builtin.is_test where builtin = @import("builtin");

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 19:27):

zig build test should work for you

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 19:27):

Or I guess zig test if you tell it to link libc

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 19:27):

I think everything is wired correctly for adding testing allocators and such, but they depend on libc

view this post on Zulip Matthew Heath (Nov 29 2024 at 19:36):

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

view this post on Zulip Matthew Heath (Nov 29 2024 at 19:37):

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

view this post on Zulip Luke Boswell (Nov 29 2024 at 20:07):

I think you're on the wrong version of zig. We're still on 0.11.0

view this post on Zulip Luke Boswell (Nov 29 2024 at 20:15):

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'

view this post on Zulip Matthew Heath (Nov 29 2024 at 21:56):

More specifically, I was in the wrong terminal. Thanks

view this post on Zulip Notification Bot (Nov 29 2024 at 21:56):

Matthew Heath has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC