| ... | @@ -11,7 +11,14 @@ pub fn main() !void { | ... | @@ -11,7 +11,14 @@ pub fn main() !void { |
| 11 | var it = try std.process.argsWithAllocator(gpa); | 11 | var it = try std.process.argsWithAllocator(gpa); |
| 12 | defer it.deinit(); | 12 | defer it.deinit(); |
| 13 | _ = it.next() orelse unreachable; // skip binary name | 13 | _ = it.next() orelse unreachable; // skip binary name |
| 14 | const child_path = it.next() orelse unreachable; | 14 | const child_path, const needs_free = child_path: { |
| | 15 | const child_path = it.next() orelse unreachable; |
| | 16 | const cwd_path = it.next() orelse break :child_path .{ child_path, false }; |
| | 17 | // If there is a third argument, it is the current CWD somewhere within the cache directory. |
| | 18 | // In that case, modify the child path in order to test spawning a path with a leading `..` component. |
| | 19 | break :child_path .{ try std.fs.path.relative(gpa, cwd_path, child_path), true }; |
| | 20 | }; |
| | 21 | defer if (needs_free) gpa.free(child_path); |
| 15 | | 22 | |
| 16 | var child = std.process.Child.init(&.{ child_path, "hello arg" }, gpa); | 23 | var child = std.process.Child.init(&.{ child_path, "hello arg" }, gpa); |
| 17 | child.stdin_behavior = .Pipe; | 24 | child.stdin_behavior = .Pipe; |
| ... | @@ -39,7 +46,12 @@ pub fn main() !void { | ... | @@ -39,7 +46,12 @@ pub fn main() !void { |
| 39 | }, | 46 | }, |
| 40 | else => |term| testError("abnormal child exit: {}", .{term}), | 47 | else => |term| testError("abnormal child exit: {}", .{term}), |
| 41 | } | 48 | } |
| 42 | return if (parent_test_error) error.ParentTestError else {}; | 49 | if (parent_test_error) return error.ParentTestError; |
| | 50 | |
| | 51 | // Check that FileNotFound is consistent across platforms when trying to spawn an executable that doesn't exist |
| | 52 | const missing_child_path = try std.mem.concat(gpa, u8, &.{ child_path, "_intentionally_missing" }); |
| | 53 | defer gpa.free(missing_child_path); |
| | 54 | try std.testing.expectError(error.FileNotFound, std.process.Child.run(.{ .allocator = gpa, .argv = &.{missing_child_path} })); |
| 43 | } | 55 | } |
| 44 | | 56 | |
| 45 | var parent_test_error = false; | 57 | var parent_test_error = false; |