Skip to content

Commit b35024a

Browse files
committed
testing_framework: working directory support
std::process::Command::current_dir() works differently on Windows and Unix. On Unix, the current directory is set before spawning the child process which can lead to incorrect file path for child process but on Windows it works as expected, sets the current working directory after spawning the child process. A simple workaround for this is to use absolute paths. See rust-lang/rust#37868 for more details.
1 parent f6f2729 commit b35024a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

testing_framework/src/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ impl Command {
116116
}
117117
}
118118

119+
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
120+
self.command.current_dir(dir);
121+
self
122+
}
123+
119124
pub fn stdout<T: Into<process::Stdio>>(&mut self, cfg: T) -> &mut Self {
120125
self.command.stdout(cfg);
121126
self
@@ -243,8 +248,9 @@ fn main() {
243248
let (progress_server, progress_server_name): (ipc::IpcOneShotServer<u64>, _) =
244249
ipc::IpcOneShotServer::new().unwrap();
245250

246-
let mut command = Command::new(exec_path);
251+
let mut command = Command::new(std::fs::canonicalize(exec_path).unwrap());
247252
command
253+
.current_dir(std::fs::canonicalize(working_directory_path).unwrap())
248254
.stdout(std::process::Stdio::null())
249255
.stderr(std::process::Stdio::null())
250256
.arg("--headless")

0 commit comments

Comments
 (0)