Skip to content

Commit

Permalink
testing_framework: working directory support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ishbosamiya committed Nov 14, 2021
1 parent f6f2729 commit b35024a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion testing_framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ impl Command {
}
}

pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
self.command.current_dir(dir);
self
}

pub fn stdout<T: Into<process::Stdio>>(&mut self, cfg: T) -> &mut Self {
self.command.stdout(cfg);
self
Expand Down Expand Up @@ -243,8 +248,9 @@ fn main() {
let (progress_server, progress_server_name): (ipc::IpcOneShotServer<u64>, _) =
ipc::IpcOneShotServer::new().unwrap();

let mut command = Command::new(exec_path);
let mut command = Command::new(std::fs::canonicalize(exec_path).unwrap());
command
.current_dir(std::fs::canonicalize(working_directory_path).unwrap())
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.arg("--headless")
Expand Down

0 comments on commit b35024a

Please sign in to comment.