link-tests: add test case for parsing weak imports

This commit is contained in:
Jakub Konka 2022-11-06 15:21:28 +01:00
parent 351031b6c7
commit 72769f6cec
3 changed files with 44 additions and 0 deletions

View File

@ -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,
});

View File

@ -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);
}

View File

@ -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;
}