Commit a717ac0340

Sashko <2179872-misanthrop@users.noreply.gitlab.com>
2024-03-12 09:46:21
Add a standalone test to cover the duplicate module bug
1 parent 604a332
Changed files (5)
test
standalone
test/standalone/dep_duplicate_module/build.zig
@@ -0,0 +1,32 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+    const target = b.standardTargetOptions(.{});
+    const optimize = b.standardOptimizeOption(.{});
+
+    const mod = b.addModule("mod", .{
+        .root_source_file = .{ .path = "mod.zig" },
+        .target = target,
+        .optimize = optimize,
+    });
+
+    const lib = b.addStaticLibrary(.{
+        .name = "lib",
+        .root_source_file = .{ .path = "lib.zig" },
+        .target = target,
+        .optimize = optimize,
+    });
+    lib.root_module.addImport("mod", mod);
+
+    const exe = b.addExecutable(.{
+        .name = "app",
+        .root_source_file = .{ .path = "main.zig" },
+        .target = target,
+        .optimize = optimize,
+    });
+
+    exe.root_module.addImport("mod", mod);
+    exe.root_module.linkLibrary(lib);
+
+    b.installArtifact(exe);
+}
test/standalone/dep_duplicate_module/lib.zig
@@ -0,0 +1,6 @@
+const std = @import("std");
+const mod = @import("mod");
+
+export fn work(x: u32) u32 {
+    return mod.double(x);
+}
test/standalone/dep_duplicate_module/main.zig
@@ -0,0 +1,8 @@
+const std = @import("std");
+const mod = @import("mod");
+
+extern fn work(x: u32) u32;
+
+pub fn main() !void {
+    _ = work(mod.half(25));
+}
test/standalone/dep_duplicate_module/mod.zig
@@ -0,0 +1,7 @@
+pub fn double(v: u32) u32 {
+    return v * 2;
+}
+
+pub fn half(v: u32) u32 {
+    return v / 2;
+}
test/standalone/build.zig.zon
@@ -86,6 +86,9 @@
         .dirname = .{
             .path = "dirname",
         },
+        .dep_duplicate_module = .{
+            .path = "dep_duplicate_module",
+        },
         .empty_env = .{
             .path = "empty_env",
         },