From 82a044f4f7997dbbb43d1aa7f8ba956328380371 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 15 Jan 2024 09:03:36 +0100 Subject: [PATCH] test/link/macho: upgrade empty object test --- test/link.zig | 4 -- test/link/macho.zig | 21 +++++++++++ test/link/macho/dylib/a.c | 7 ---- test/link/macho/dylib/build.zig | 65 --------------------------------- test/link/macho/dylib/main.c | 9 ----- test/link/macho/empty/build.zig | 31 ---------------- test/link/macho/empty/empty.c | 0 test/link/macho/empty/main.c | 6 --- 8 files changed, 21 insertions(+), 122 deletions(-) delete mode 100644 test/link/macho/dylib/a.c delete mode 100644 test/link/macho/dylib/build.zig delete mode 100644 test/link/macho/dylib/main.c delete mode 100644 test/link/macho/empty/build.zig delete mode 100644 test/link/macho/empty/empty.c delete mode 100644 test/link/macho/empty/main.c diff --git a/test/link.zig b/test/link.zig index 1085a35181..f0d6c87ec9 100644 --- a/test/link.zig +++ b/test/link.zig @@ -107,10 +107,6 @@ pub const cases = [_]Case{ .build_root = "test/link/macho/bugs/16628", .import = @import("link/macho/bugs/16628/build.zig"), }, - .{ - .build_root = "test/link/macho/empty", - .import = @import("link/macho/empty/build.zig"), - }, .{ .build_root = "test/link/macho/entry", .import = @import("link/macho/entry/build.zig"), diff --git a/test/link/macho.zig b/test/link/macho.zig index e3c481aed9..6dede6a973 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -17,6 +17,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { }); macho_step.dependOn(testDeadStrip(b, .{ .target = default_target })); + macho_step.dependOn(testEmptyObject(b, .{ .target = default_target })); macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target })); macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target })); macho_step.dependOn(testHelloC(b, .{ .target = default_target })); @@ -220,6 +221,26 @@ fn testDylib(b: *Build, opts: Options) *Step { return test_step; } +fn testEmptyObject(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "macho-empty-object", opts); + + const empty = addObject(b, opts, .{ .name = "empty", .c_source_bytes = "" }); + + const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = + \\#include + \\int main() { + \\ printf("Hello world!"); + \\} + }); + exe.addObject(empty); + + const run = addRunArtifact(exe); + run.expectStdOutEqual("Hello world!"); + test_step.dependOn(&run.step); + + return test_step; +} + fn testEntryPointDylib(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "macho-entry-point-dylib", opts); diff --git a/test/link/macho/dylib/a.c b/test/link/macho/dylib/a.c deleted file mode 100644 index 199b31e1a0..0000000000 --- a/test/link/macho/dylib/a.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char world[] = "world"; - -char* hello() { - return "Hello"; -} diff --git a/test/link/macho/dylib/build.zig b/test/link/macho/dylib/build.zig deleted file mode 100644 index abd7175eae..0000000000 --- a/test/link/macho/dylib/build.zig +++ /dev/null @@ -1,65 +0,0 @@ -const std = @import("std"); - -pub const requires_symlinks = true; - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - add(b, test_step, .Debug); - add(b, test_step, .ReleaseFast); - add(b, test_step, .ReleaseSmall); - add(b, test_step, .ReleaseSafe); -} - -fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { - const target = b.resolveTargetQuery(.{ .os_tag = .macos }); - - const dylib = b.addSharedLibrary(.{ - .name = "a", - .version = .{ .major = 1, .minor = 0, .patch = 0 }, - .optimize = optimize, - .target = target, - }); - dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); - dylib.linkLibC(); - - const check_dylib = dylib.checkObject(); - check_dylib.checkInHeaders(); - check_dylib.checkExact("cmd ID_DYLIB"); - check_dylib.checkExact("name @rpath/liba.dylib"); - check_dylib.checkExact("timestamp 2"); - check_dylib.checkExact("current version 10000"); - check_dylib.checkExact("compatibility version 10000"); - - test_step.dependOn(&check_dylib.step); - - const exe = b.addExecutable(.{ - .name = "main", - .optimize = optimize, - .target = target, - }); - exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); - exe.linkSystemLibrary("a"); - exe.addLibraryPath(dylib.getEmittedBinDirectory()); - exe.addRPath(dylib.getEmittedBinDirectory()); - exe.linkLibC(); - - const check_exe = exe.checkObject(); - check_exe.checkInHeaders(); - check_exe.checkExact("cmd LOAD_DYLIB"); - check_exe.checkExact("name @rpath/liba.dylib"); - check_exe.checkExact("timestamp 2"); - check_exe.checkExact("current version 10000"); - check_exe.checkExact("compatibility version 10000"); - - check_exe.checkInHeaders(); - check_exe.checkExact("cmd RPATH"); - check_exe.checkExactPath("path", dylib.getEmittedBinDirectory()); - test_step.dependOn(&check_exe.step); - - const run = b.addRunArtifact(exe); - run.skip_foreign_checks = true; - run.expectStdOutEqual("Hello world"); - test_step.dependOn(&run.step); -} diff --git a/test/link/macho/dylib/main.c b/test/link/macho/dylib/main.c deleted file mode 100644 index 941903f219..0000000000 --- a/test/link/macho/dylib/main.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char* hello(); -extern char world[]; - -int main(int argc, char* argv[]) { - printf("%s %s", hello(), world); - return 0; -} diff --git a/test/link/macho/empty/build.zig b/test/link/macho/empty/build.zig deleted file mode 100644 index af38930ae8..0000000000 --- a/test/link/macho/empty/build.zig +++ /dev/null @@ -1,31 +0,0 @@ -const std = @import("std"); - -pub const requires_symlinks = true; - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test it"); - b.default_step = test_step; - - add(b, test_step, .Debug); - add(b, test_step, .ReleaseFast); - add(b, test_step, .ReleaseSmall); - add(b, test_step, .ReleaseSafe); -} - -fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { - const target = b.resolveTargetQuery(.{ .os_tag = .macos }); - - const exe = b.addExecutable(.{ - .name = "test", - .optimize = optimize, - .target = target, - }); - exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); - exe.addCSourceFile(.{ .file = .{ .path = "empty.c" }, .flags = &[0][]const u8{} }); - exe.linkLibC(); - - const run_cmd = b.addRunArtifact(exe); - run_cmd.skip_foreign_checks = true; - run_cmd.expectStdOutEqual("Hello!\n"); - test_step.dependOn(&run_cmd.step); -} diff --git a/test/link/macho/empty/empty.c b/test/link/macho/empty/empty.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/link/macho/empty/main.c b/test/link/macho/empty/main.c deleted file mode 100644 index 9f1eea37b4..0000000000 --- a/test/link/macho/empty/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char* argv[]) { - printf("Hello!\n"); - return 0; -}