add standalone test for depending on the main module

This commit is contained in:
Andrew Kelley 2024-01-01 19:27:40 -07:00
parent d5c1e7f7b1
commit 2b63ba31e9
4 changed files with 43 additions and 0 deletions

View File

@ -258,6 +258,10 @@ pub const build_cases = [_]BuildCase{
.build_root = "test/standalone/ios",
.import = @import("standalone/ios/build.zig"),
},
.{
.build_root = "test/standalone/depend_on_main_mod",
.import = @import("standalone/depend_on_main_mod/build.zig"),
},
};
const std = @import("std");

View File

@ -0,0 +1,28 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it");
b.default_step = test_step;
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "depend_on_main_mod",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const foo_module = b.addModule("foo", .{
.root_source_file = .{ .path = "src/foo.zig" },
});
foo_module.addImport("root2", &exe.root_module);
exe.root_module.addImport("foo", foo_module);
const run_cmd = b.addRunArtifact(exe);
run_cmd.expectExitCode(0);
test_step.dependOn(&run_cmd.step);
}

View File

@ -0,0 +1,6 @@
const std = @import("std");
const assert = std.debug.assert;
pub fn run() void {
comptime assert(@import("root") == @import("root2"));
}

View File

@ -0,0 +1,5 @@
const std = @import("std");
pub fn main() !void {
@import("foo").run();
}