Skip to content

Commit 5e12cfd

Browse files
committed
test-cases: avoid using realpath since it is not portable
For example FreeBSD does not support this syscall.
1 parent 8a1b69f commit 5e12cfd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/test.zig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,19 +1800,21 @@ pub const TestContext = struct {
18001800
exec_node.activate();
18011801
defer exec_node.end();
18021802

1803-
// We use relative to cwd here because we pass a new cwd to the
1804-
// child process.
1805-
const exe_path = try std.fmt.allocPrint(arena, "." ++ std.fs.path.sep_str ++ "{s}", .{bin_name});
1803+
// We go out of our way here to use the unique temporary directory name in
1804+
// the exe_path so that it makes its way into the cache hash, avoiding
1805+
// cache collisions from multiple threads doing `zig run` at the same time
1806+
// on the same test_case.c input filename.
1807+
const ss = std.fs.path.sep_str;
1808+
const exe_path = try std.fmt.allocPrint(
1809+
arena,
1810+
".." ++ ss ++ "{s}" ++ ss ++ "{s}",
1811+
.{ &tmp.sub_path, bin_name },
1812+
);
18061813
if (case.object_format != null and case.object_format.? == .c) {
18071814
if (host.getExternalExecutor(target_info, .{ .link_libc = true }) != .native) {
18081815
// We wouldn't be able to run the compiled C code.
18091816
return; // Pass test.
18101817
}
1811-
// Use an absolute path here so that the unique directory name
1812-
// for this Case makes it into the cache hash, avoiding cache
1813-
// collisions from multiple threads doing `zig run` at the same
1814-
// time on the same test_case.c input filename.
1815-
const abs_exe_path = try tmp.dir.realpathAlloc(arena, bin_name);
18161818
try argv.appendSlice(&[_][]const u8{
18171819
std.testing.zig_exe_path,
18181820
"run",
@@ -1823,7 +1825,7 @@ pub const TestContext = struct {
18231825
"-Wno-incompatible-library-redeclaration", // https://github.com/ziglang/zig/issues/875
18241826
"--",
18251827
"-lc",
1826-
abs_exe_path,
1828+
exe_path,
18271829
});
18281830
} else switch (host.getExternalExecutor(target_info, .{ .link_libc = case.link_libc })) {
18291831
.native => try argv.append(exe_path),

0 commit comments

Comments
 (0)