| ... | @@ -142,6 +142,10 @@ pub fn main() anyerror!void { | ... | @@ -142,6 +142,10 @@ pub fn main() anyerror!void { |
| 142 | defer allocator.free(goodbye_abs_path); | 142 | defer allocator.free(goodbye_abs_path); |
| 143 | // then the PATH should not be searched and we should get InvalidExe | 143 | // then the PATH should not be searched and we should get InvalidExe |
| 144 | try testExecError(error.InvalidExe, allocator, goodbye_abs_path); | 144 | try testExecError(error.InvalidExe, allocator, goodbye_abs_path); |
| | 145 | |
| | 146 | // If we try to exec but provide a cwd that is an absolute path, the PATH |
| | 147 | // should still be searched and the goodbye.exe in something should be found. |
| | 148 | try testExecWithCwd(allocator, "goodbye", tmp_absolute_path, "hello from exe\n"); |
| 145 | } | 149 | } |
| 146 | | 150 | |
| 147 | fn testExecError(err: anyerror, allocator: std.mem.Allocator, command: []const u8) !void { | 151 | fn testExecError(err: anyerror, allocator: std.mem.Allocator, command: []const u8) !void { |
| ... | @@ -149,9 +153,14 @@ fn testExecError(err: anyerror, allocator: std.mem.Allocator, command: []const u | ... | @@ -149,9 +153,14 @@ fn testExecError(err: anyerror, allocator: std.mem.Allocator, command: []const u |
| 149 | } | 153 | } |
| 150 | | 154 | |
| 151 | fn testExec(allocator: std.mem.Allocator, command: []const u8, expected_stdout: []const u8) !void { | 155 | fn testExec(allocator: std.mem.Allocator, command: []const u8, expected_stdout: []const u8) !void { |
| | 156 | return testExecWithCwd(allocator, command, null, expected_stdout); |
| | 157 | } |
| | 158 | |
| | 159 | fn testExecWithCwd(allocator: std.mem.Allocator, command: []const u8, cwd: ?[]const u8, expected_stdout: []const u8) !void { |
| 152 | var result = try std.ChildProcess.exec(.{ | 160 | var result = try std.ChildProcess.exec(.{ |
| 153 | .allocator = allocator, | 161 | .allocator = allocator, |
| 154 | .argv = &[_][]const u8{command}, | 162 | .argv = &[_][]const u8{command}, |
| | 163 | .cwd = cwd, |
| 155 | }); | 164 | }); |
| 156 | defer allocator.free(result.stdout); | 165 | defer allocator.free(result.stdout); |
| 157 | defer allocator.free(result.stderr); | 166 | defer allocator.free(result.stderr); |