#When using `test`, no package named 'zig-network' available in package 'root'

1 messages · Page 1 of 1 (latest)

orchid oar
#

Hi all! I'm fairly new to Zig, and have encountered this issue when trying to run tests. When running the application normally I have no issues.

Relevant file structure:

src/
  network/
    relevant_file.zig
  main.zig
  test.zig
lib/
  zig-network/
build.zig

I started with tests written in relevant_file.zig, and eventually moved to a universal test file referenced in build.zig. Relevant code snippet from build.zig:

    exe.addPackagePath("zig_network", "lib/zig-network/network.zig");
    ...
    ...
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    const exe_tests = b.addTest("src/main.zig");
    exe_tests.setTarget(target);
    exe_tests.setBuildMode(mode);

    const all_tests = b.addTest("src/test.zig");
    all_tests.setTarget(target);
    all_tests.setBuildMode(mode);

    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&exe_tests.step);
    test_step.dependOn(&all_tests.step);

At this point, when running zig build test I receive the following output:

All 1 tests passed.
src\network\relevant_file.zig:2:29: error: no package named 'zig_network' available within package 'root'
pub const network = @import("zig_network");
...
...

The "All 1 tests passed" being those tests defined by exe_tests.

This may be related to #1037826817731592214 message, but the error is consistent and I didn't see a solution in that thread.

Any help would be appreciated!

Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

#

When using test, no package named 'zig-network' available in package 'root'

visual lava
#

tests are configured as their own executable separate from exe, which means it needs any packages added to it as well exe_tests.addPackagePath("zig_network", "lib/zig-network/network.zig");

frank fractal
#

you can write a loop like inline for (.{ exe, exe_tests }) |goal| { to avoid repeating too much

#

then goal.addPackagePath etc

orchid oar
orchid oar