Commit 72769f6cec

Jakub Konka <kubkon@jakubkonka.com>
2022-11-06 15:21:28
link-tests: add test case for parsing weak imports
1 parent 351031b
Changed files (3)
test
link
macho
test/link/macho/bugs/13056/build.zig
@@ -0,0 +1,29 @@
+const std = @import("std");
+const Builder = std.build.Builder;
+
+pub fn build(b: *Builder) void {
+    const mode = b.standardReleaseOptions();
+
+    const target: std.zig.CrossTarget = .{ .os_tag = .macos };
+    const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable;
+    const sdk = std.zig.system.darwin.getDarwinSDK(b.allocator, target_info.target) orelse
+        @panic("macOS SDK is required to run the test");
+
+    const test_step = b.step("test", "Test the program");
+
+    const exe = b.addExecutable("test", null);
+    b.default_step.dependOn(&exe.step);
+    exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable);
+    exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable);
+    exe.addCSourceFile("test.cpp", &.{
+        "-nostdlib++",
+        "-nostdinc++",
+    });
+    exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable);
+    exe.setBuildMode(mode);
+
+    const run_cmd = exe.run();
+    run_cmd.expectStdErrEqual("x: 5\n");
+
+    test_step.dependOn(&run_cmd.step);
+}
test/link/macho/bugs/13056/test.cpp
@@ -0,0 +1,10 @@
+// test.cpp
+#include <new>
+#include <cstdio>
+
+int main() {
+    int *x = new int;
+    *x = 5;
+    fprintf(stderr, "x: %d\n", *x);
+    delete x;
+}
test/link.zig
@@ -79,6 +79,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
 }
 
 fn addMachOCases(cases: *tests.StandaloneContext) void {
+    cases.addBuildFile("test/link/macho/bugs/13056/build.zig", .{
+        .build_modes = true,
+        .requires_macos_sdk = true,
+    });
+
     cases.addBuildFile("test/link/macho/bugs/13457/build.zig", .{
         .build_modes = true,
     });