#test exe @import("root") | root struct of file 'test_runner' has no member named ...

1 messages · Page 1 of 1 (latest)

pure shoal
#

Hi all,

in my build.zig i got this:

const test_exe = b.addTestExe("test", "src/main.zig");```
`main.zig` imports other files for testing:
```zig
comptime {
    _ = @import("tests.zig");
}
pub var server: Server = undefined;```
`tests.zig` contains this:
```zig
test {
    std.testing.refAllDecls(@import("evented.zig"));
    // ...
}```
Running `zig build test` i get this error:

src/evented.zig:134:41: error: root struct of file 'test_runner' has no member named 'server'
connection: *@TypeOf(@import("root").server),
~~~~~~~~~^```
i think it's clear why this happens, but is there a way to have main.zig remain the file @import("root") refers to?

$ zig version
0.11.0-dev.1384+fe6dcdba1```
south jasper
#

for now it works like that 😬 it's annoying, but test_runner.zig is the root

pure shoal
#

are there plans to change this?

south jasper
#

i found this issue

pure shoal
#

thx, subscribed it

#

in that case i'll probably just use a root.zig which usingnamespaces main.zig as an intermediary solution

#

i can't seem to add the "Answered" tag to this post
anyone who it works for, feel free to do so
closing

weary moss
undone kite
pure shoal
#

yeah i've figured it out since