authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-29 00:33:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-29 00:33:08-07:00
log1590ed9d6aea95e5a21e3455e8edba4cdb374f2c
tree509e9a697be358d82553937943fdf71841e7c0a2
parent7e1e771f0260b5fd0a5cd2f7e3d669979d8f141b

stage2 tests: pass cwd to child process to fix exe path

Previous commit broke the tests for non-Windows because we were intending to change the cwd when running the child process. However, for Windows we don't support passing a directory handle for cwd when spawning child processes yet. However on Linux we do. This commit reverts the previous one but then fixes things for all systems by passing both cwd_dir and cwd to the child process.

1 files changed, 17 insertions(+), 8 deletions(-)

src/test.zig+17-8
......@@ -561,10 +561,10 @@ pub const TestContext = struct {
561561
562562 var cache_dir = try tmp.dir.makeOpenPath("zig-cache", .{});
563563 defer cache_dir.close();
564 const tmp_path = try std.fs.path.join(arena, &[_][]const u8{ ".", "zig-cache", "tmp", &tmp.sub_path });
564 const tmp_dir_path = try std.fs.path.join(arena, &[_][]const u8{ ".", "zig-cache", "tmp", &tmp.sub_path });
565565 const zig_cache_directory: Compilation.Directory = .{
566566 .handle = cache_dir,
567 .path = try std.fs.path.join(arena, &[_][]const u8{ tmp_path, "zig-cache" }),
567 .path = try std.fs.path.join(arena, &[_][]const u8{ tmp_dir_path, "zig-cache" }),
568568 };
569569
570570 const tmp_src_path = switch (case.extension) {
......@@ -573,7 +573,7 @@ pub const TestContext = struct {
573573 };
574574
575575 var root_pkg: Package = .{
576 .root_src_directory = .{ .path = tmp_path, .handle = tmp.dir },
576 .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir },
577577 .root_src_path = tmp_src_path,
578578 };
579579
......@@ -585,7 +585,7 @@ pub const TestContext = struct {
585585 });
586586
587587 const emit_directory: Compilation.Directory = .{
588 .path = tmp_path,
588 .path = tmp_dir_path,
589589 .handle = tmp.dir,
590590 };
591591 const emit_bin: Compilation.EmitLoc = .{
......@@ -771,7 +771,9 @@ pub const TestContext = struct {
771771 exec_node.activate();
772772 defer exec_node.end();
773773
774 const exe_path = try emit_directory.join(arena, &[_][]const u8{bin_name});
774 // We use relative to cwd here because we pass a new cwd to the
775 // child process.
776 const exe_path = try std.fmt.allocPrint(arena, "." ++ std.fs.path.sep_str ++ "{s}", .{bin_name});
775777 if (case.object_format != null and case.object_format.? == .c) {
776778 try argv.appendSlice(&[_][]const u8{
777779 std.testing.zig_exe_path, "run", exe_path, "-lc",
......@@ -824,11 +826,18 @@ pub const TestContext = struct {
824826
825827 try comp.makeBinFileExecutable();
826828
827 break :x try std.ChildProcess.exec(.{
829 break :x std.ChildProcess.exec(.{
828830 .allocator = allocator,
829831 .argv = argv.items,
830832 .cwd_dir = tmp.dir,
831 });
833 .cwd = tmp_dir_path,
834 }) catch |err| {
835 std.debug.print("\nThe following command failed with {s}:\n", .{
836 @errorName(err),
837 });
838 dumpArgs(argv.items);
839 return error.ZigTestFailed;
840 };
832841 };
833842 var test_node = update_node.start("test", 0);
834843 test_node.activate();
......@@ -976,4 +985,4 @@ fn dumpArgs(argv: []const []const u8) void {
976985 std.debug.print("{s} ", .{arg});
977986 }
978987 std.debug.print("\n", .{});
979}
\ No newline at end of file
988}