Commit 2b63ba31e9

Andrew Kelley <andrew@ziglang.org>
2024-01-02 03:27:40
add standalone test for depending on the main module
1 parent d5c1e7f
Changed files (4)
test
standalone
depend_on_main_mod
test/standalone/depend_on_main_mod/src/foo.zig
@@ -0,0 +1,6 @@
+const std = @import("std");
+const assert = std.debug.assert;
+
+pub fn run() void {
+    comptime assert(@import("root") == @import("root2"));
+}
test/standalone/depend_on_main_mod/src/main.zig
@@ -0,0 +1,5 @@
+const std = @import("std");
+
+pub fn main() !void {
+    @import("foo").run();
+}
test/standalone/depend_on_main_mod/build.zig
@@ -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);
+}
test/standalone.zig
@@ -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");