Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using MicroZig within test blocks #230

Open
bryanmcelvy opened this issue Aug 5, 2024 · 0 comments
Open

Add support for using MicroZig within test blocks #230

bryanmcelvy opened this issue Aug 5, 2024 · 0 comments

Comments

@bryanmcelvy
Copy link

bryanmcelvy commented 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 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.

@bryanmcelvy 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant