You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On a personal project I'm working on, I recently ran into an issue in which either importing MicroZig directly or using something that relies on it inside of a test block causes a compilation error. When running using a test step (e.g. zig build test), the error is no module named 'microzig' available within module root. When running using zig test, the error is no module named 'microzig' available within module test. The fix for this was adding a line to build.zig that imports the MicroZig module within the test step:
const test_run_step = b.step("test", "Run unit tests");
const driver_tests = b.addTest(.{
.name = "driver_tests",
.root_source_file = b.path("source/drivers.zig"),
.target = b.graph.host,
});
driver_tests.root_module.addImport("microzig", firmware.modules.microzig); // adding this line fixed the issue
const driver_test_run = b.addRunArtifact(driver_tests);
test_run_step.dependOn(&driver_test_run.step);
Since this is slightly unintuitive, it'd be nice to have direct support for this from within the MicroZig framework.
The text was updated successfully, but these errors were encountered:
bryanmcelvy
changed the title
Add support for importing MicroZig as a module in unit tests
Add support for using MicroZig within test blocks
Aug 5, 2024
On a personal project I'm working on, I recently ran into an issue in which either importing MicroZig directly or using something that relies on it inside of a
test
block causes a compilation error. When running using a test step (e.g.zig build test
), the error isno module named 'microzig' available within module root
. When running usingzig test
, the error isno module named 'microzig' available within module test
. The fix for this was adding a line tobuild.zig
that imports the MicroZig module within the test step:Since this is slightly unintuitive, it'd be nice to have direct support for this from within the MicroZig framework.
The text was updated successfully, but these errors were encountered: