#Test files which reference `@import("root")`

1 messages · Page 1 of 1 (latest)

hybrid garden
#

I a library in which the code in it references other parts by doing something like ```zig
const libfoo = @import("root");

pub fn doSomethingWithBar() void {
const bar = libfoo.Bar.init();
bar.doSomething();
}

However, when I try to do run my code in a test like ```
const libfoo = @import("libfoo");

test "Does something" {
  libfoo.baz.doSomethingWithBar();
} 

It takes the code in the first file as the root for the test runner as in ~/.local/share/zig/lib/compiler/test_runner.zig. How can I change that?

glossy brook
#

a library shouldnt use @import("root") for importing other parts of the library, since it'll refer to whatever the root_source_file of the artifact is, which is going to be user code. unless you mean this is for letting users define their own Bar?

hybrid garden
#

So, then how would I refer to the source of the library?

glossy brook
#

using relative paths

#

theres a proposal for what youre looking for, but it isnt implemented

hybrid garden
#

alr

worthy flower
#

I was excited to see that @import("root") is now implemented. However, as the OP says, if you run a test, then root is test_runner which doesn't work!!!

trim pebble