test/link/macho: upgrade empty object test
This commit is contained in:
parent
a454ba7908
commit
82a044f4f7
|
@ -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"),
|
||||
|
|
|
@ -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 <stdio.h>
|
||||
\\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);
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
char world[] = "world";
|
||||
|
||||
char* hello() {
|
||||
return "Hello";
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
char* hello();
|
||||
extern char world[];
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
printf("%s %s", hello(), world);
|
||||
return 0;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
printf("Hello!\n");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user