From 6e56a8df20395749b21b3857952dae1c227aacf1 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 20 Jun 2022 17:29:00 +0200 Subject: [PATCH] link-tests: CheckFileStep to do grep test on the binary --- test/link.zig | 8 ++++---- test/link/dylib/build.zig | 7 +++++++ test/tests.zig | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/test/link.zig b/test/link.zig index 3c1b268d86..9026da65ea 100644 --- a/test/link.zig +++ b/test/link.zig @@ -7,10 +7,6 @@ pub fn addCases(cases: *tests.StandaloneContext) void { .build_modes = false, // we only guarantee zerofill for undefined in Debug }); - cases.addBuildFile("test/link/dylib/build.zig", .{ - .build_modes = true, - }); - cases.addBuildFile("test/link/common_symbols/build.zig", .{ .build_modes = true, }); @@ -32,6 +28,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { }); if (builtin.os.tag == .macos) { + cases.addBuildFile("test/link/dylib/build.zig", .{ + .build_modes = true, + }); + cases.addBuildFile("test/link/frameworks/build.zig", .{ .build_modes = true, .requires_macos_sdk = true, diff --git a/test/link/dylib/build.zig b/test/link/dylib/build.zig index a9dee4aafb..c14bf0b7d5 100644 --- a/test/link/dylib/build.zig +++ b/test/link/dylib/build.zig @@ -24,6 +24,13 @@ pub fn build(b: *Builder) void { run.cwd = b.pathFromRoot("."); run.expectStdOutEqual("Hello world"); + const exp_dylib = std.macho.createLoadDylibCommand(b.allocator, "@rpath/liba.dylib", 2, 0x10000, 0x10000) catch unreachable; + var buf = std.ArrayList(u8).init(b.allocator); + defer buf.deinit(); + exp_dylib.write(buf.writer()) catch unreachable; + const check_file = std.build.CheckFileStep.create(b, exe.getOutputSource(), &[_][]const u8{buf.items}); + test_step.dependOn(b.getInstallStep()); test_step.dependOn(&run.step); + test_step.dependOn(&check_file.step); } diff --git a/test/tests.zig b/test/tests.zig index 8bc415d28b..d1f319673c 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -995,7 +995,8 @@ pub const StandaloneContext = struct { } if (features.cross_targets and !self.target.isNative()) { - const target_arg = fmt.allocPrint(b.allocator, "-Dtarget={s}", .{self.target.zigTriple(b.allocator) catch unreachable}) catch unreachable; + const target_triple = self.target.zigTriple(b.allocator) catch unreachable; + const target_arg = fmt.allocPrint(b.allocator, "-Dtarget={s}", .{target_triple}) catch unreachable; zig_args.append(target_arg) catch unreachable; }