commit 8f00bc9d231c0c686b2ffa3bd0b14181afa7a171 (tree)
parent dfdb807543a03eec27341deec6a5f3b88f87fac3
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Sat, 25 Jun 2022 10:57:56 +0200
link-tests: put macho search strategy tests into one test case
Diffstat:
8 files changed, 69 insertions(+), 110 deletions(-)
diff --git a/test/link.zig b/test/link.zig
@@ -61,11 +61,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
.build_modes = true,
});
- cases.addBuildFile("test/link/macho/search_paths_first/build.zig", .{
- .build_modes = true,
- });
-
- cases.addBuildFile("test/link/macho/search_dylibs_first/build.zig", .{
+ cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{
.build_modes = true,
});
}
diff --git a/test/link/macho/search_dylibs_first/build.zig b/test/link/macho/search_dylibs_first/build.zig
@@ -1,48 +0,0 @@
-const std = @import("std");
-const Builder = std.build.Builder;
-
-pub fn build(b: *Builder) void {
- const mode = b.standardReleaseOptions();
-
- const test_step = b.step("test", "Test");
- test_step.dependOn(b.getInstallStep());
-
- const static = b.addStaticLibrary("a", null);
- static.setBuildMode(mode);
- static.addCSourceFile("a.c", &.{});
- static.linkLibC();
- static.override_dest_dir = std.build.InstallDir{
- .custom = "static",
- };
- static.install();
-
- const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
- dylib.setBuildMode(mode);
- dylib.addCSourceFile("a.c", &.{});
- dylib.linkLibC();
- dylib.override_dest_dir = std.build.InstallDir{
- .custom = "dynamic",
- };
- dylib.install();
-
- const exe = b.addExecutable("main", null);
- exe.setBuildMode(mode);
- exe.addCSourceFile("main.c", &.{});
- exe.linkSystemLibraryName("a");
- exe.linkLibC();
- exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
- exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
- exe.addRPath(b.pathFromRoot("zig-out/dynamic"));
- exe.search_strategy = .dylibs_first;
-
- const check = exe.checkObject(.macho);
- check.checkStart("cmd LOAD_DYLIB");
- check.checkNext("name @rpath/liba.dylib");
-
- test_step.dependOn(&check.step);
-
- const run = exe.run();
- run.cwd = b.pathFromRoot(".");
- run.expectStdOutEqual("Hello world");
- test_step.dependOn(&run.step);
-}
diff --git a/test/link/macho/search_paths_first/a.c b/test/link/macho/search_paths_first/a.c
@@ -1,7 +0,0 @@
-#include <stdio.h>
-
-char world[] = "world";
-
-char* hello() {
- return "Hello";
-}
diff --git a/test/link/macho/search_paths_first/build.zig b/test/link/macho/search_paths_first/build.zig
@@ -1,41 +0,0 @@
-const std = @import("std");
-const Builder = std.build.Builder;
-
-pub fn build(b: *Builder) void {
- const mode = b.standardReleaseOptions();
-
- const test_step = b.step("test", "Test");
- test_step.dependOn(b.getInstallStep());
-
- const static = b.addStaticLibrary("a", null);
- static.setBuildMode(mode);
- static.addCSourceFile("a.c", &.{});
- static.linkLibC();
- static.override_dest_dir = std.build.InstallDir{
- .custom = "static",
- };
- static.install();
-
- const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
- dylib.setBuildMode(mode);
- dylib.addCSourceFile("a.c", &.{});
- dylib.linkLibC();
- dylib.override_dest_dir = std.build.InstallDir{
- .custom = "dynamic",
- };
- dylib.install();
-
- const exe = b.addExecutable("main", null);
- exe.setBuildMode(mode);
- exe.addCSourceFile("main.c", &.{});
- exe.linkSystemLibraryName("a");
- exe.linkLibC();
- exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
- exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
- exe.search_strategy = .paths_first;
-
- const run = exe.run();
- run.cwd = b.pathFromRoot(".");
- run.expectStdOutEqual("Hello world");
- test_step.dependOn(&run.step);
-}
diff --git a/test/link/macho/search_paths_first/main.c b/test/link/macho/search_paths_first/main.c
@@ -1,9 +0,0 @@
-#include <stdio.h>
-
-char* hello();
-extern char world[];
-
-int main() {
- printf("%s %s", hello(), world);
- return 0;
-}
diff --git a/test/link/macho/search_dylibs_first/a.c b/test/link/macho/search_strategy/a.c
diff --git a/test/link/macho/search_strategy/build.zig b/test/link/macho/search_strategy/build.zig
@@ -0,0 +1,68 @@
+const std = @import("std");
+const Builder = std.build.Builder;
+const LibExeObjectStep = std.build.LibExeObjStep;
+
+pub fn build(b: *Builder) void {
+ const mode = b.standardReleaseOptions();
+
+ const test_step = b.step("test", "Test");
+ test_step.dependOn(b.getInstallStep());
+
+ {
+ // -search_dylibs_first
+ const exe = createScenario(b, mode);
+ exe.search_strategy = .dylibs_first;
+
+ const check = exe.checkObject(.macho);
+ check.checkStart("cmd LOAD_DYLIB");
+ check.checkNext("name @rpath/liba.dylib");
+
+ test_step.dependOn(&check.step);
+
+ const run = exe.run();
+ run.cwd = b.pathFromRoot(".");
+ run.expectStdOutEqual("Hello world");
+ test_step.dependOn(&run.step);
+ }
+
+ {
+ // -search_paths_first
+ const exe = createScenario(b, mode);
+ exe.search_strategy = .paths_first;
+
+ const run = exe.run();
+ run.cwd = b.pathFromRoot(".");
+ run.expectStdOutEqual("Hello world");
+ test_step.dependOn(&run.step);
+ }
+}
+
+fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
+ const static = b.addStaticLibrary("a", null);
+ static.setBuildMode(mode);
+ static.addCSourceFile("a.c", &.{});
+ static.linkLibC();
+ static.override_dest_dir = std.build.InstallDir{
+ .custom = "static",
+ };
+ static.install();
+
+ const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
+ dylib.setBuildMode(mode);
+ dylib.addCSourceFile("a.c", &.{});
+ dylib.linkLibC();
+ dylib.override_dest_dir = std.build.InstallDir{
+ .custom = "dynamic",
+ };
+ dylib.install();
+
+ const exe = b.addExecutable("main", null);
+ exe.setBuildMode(mode);
+ exe.addCSourceFile("main.c", &.{});
+ exe.linkSystemLibraryName("a");
+ exe.linkLibC();
+ exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
+ exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
+ exe.addRPath(b.pathFromRoot("zig-out/dynamic"));
+ return exe;
+}
diff --git a/test/link/macho/search_dylibs_first/main.c b/test/link/macho/search_strategy/main.c