aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-11-06 15:21:28 +0100
committerJakub Konka <kubkon@jakubkonka.com>2022-11-06 15:21:28 +0100
commit72769f6cec3093be0b82c52a50e4caff2eefa551 (patch)
tree34b5afc36395643b647e2c627804e81f6beceacf
parent351031b6c7b01f45a4ee366eb1c0b28bce89145c (diff)
downloadzig-72769f6cec3093be0b82c52a50e4caff2eefa551.tar.gz
zig-72769f6cec3093be0b82c52a50e4caff2eefa551.zip
link-tests: add test case for parsing weak imports
-rw-r--r--test/link.zig5
-rw-r--r--test/link/macho/bugs/13056/build.zig29
-rw-r--r--test/link/macho/bugs/13056/test.cpp10
3 files changed, 44 insertions, 0 deletions
diff --git a/test/link.zig b/test/link.zig
index 9ad695ba26..47e51859bc 100644
--- a/test/link.zig
+++ b/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,
});
diff --git a/test/link/macho/bugs/13056/build.zig b/test/link/macho/bugs/13056/build.zig
new file mode 100644
index 0000000000..751a7c4db6
--- /dev/null
+++ b/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);
+}
diff --git a/test/link/macho/bugs/13056/test.cpp b/test/link/macho/bugs/13056/test.cpp
new file mode 100644
index 0000000000..d042cb0a2a
--- /dev/null
+++ b/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;
+}