I'm not sure if it's always this situation that fails, but I have a very minimal test case:
main.zig:
pub const i: i32 = 0;
test/crashing_test.zig:
const std = @import("std");
const main = @import("../main.zig");
test "" {
_ = main.i;
}
Running zig test test/crashing_test.zig gives this:
Assertion failed: (mem_len != SIZE_MAX), function buf_append_mem, file /Users/dbandstra/zig/src/buffer.hpp, line 108.
Abort trap: 6
If main.zig is also in the test folder, it works. This is breaking my zig-pcx and oxid projects (they both die with this assertion error).
I think this might be the culprit. When @import uses a relative path add_source() gets confused and assumes resolved_root_src_dir is a parent (common string prefix) to noextname. In this case the pointer math/size is wrong.
Was going to try and patch but don't have the high level view of what namespace_name should be in cases of { std/builtin, absolute, relative and sub } and what happens if Tld.name ends up duplicated?
https://github.com/ziglang/zig/blob/764205ac13cc340ff6dcce74667c32dafe24e510/src/analyze.cpp#L4507-L4512
After the above commit:
[nix-shell:~/dev/zig/build]$ ./zig test foo/a.zig
/home/andy/dev/zig/build/foo/a.zig:1:11: error: import of file outside package path: '../b.zig'
const b = @import("../b.zig");
^
[nix-shell:~/dev/zig/build]$ ./zig test foo/a.zig --main-pkg-path ../
Test 1/1 oaeu...OK
All tests passed.
So the idea here is that you'll have to map your packages in as packages, or you'll have to choose an explicit root directory for the main package. It's no longer supported to @import a file from the file system that does not belong to a package.