Skip to content

Commit

Permalink
Prevent dual compilation of test_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 6, 2024
1 parent edfbe92 commit a7c29eb
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions tests/process.rs
Expand Up @@ -81,25 +81,28 @@ fn test_cmd() {
}
}

fn build_test_binary() {
std::process::Command::new("rustc")
.arg("test_bin/main.rs")
.arg("-o")
.arg("target/test_binary")
.stdout(std::process::Stdio::null())
.spawn()
.unwrap()
.wait()
.unwrap();
fn build_test_binary(file_name: &str) {
if !std::path::file_exists(file_name) {
std::process::Command::new("rustc")
.arg("test_bin/main.rs")
.arg("-o")
.arg(file_name)
.stdout(std::process::Stdio::null())
.spawn()
.unwrap()
.wait()
.unwrap();
}
}

#[test]
fn test_environ() {
if !sysinfo::IS_SUPPORTED_SYSTEM || cfg!(feature = "apple-sandbox") {
return;
}
build_test_binary();
let mut p = std::process::Command::new("./target/test_binary")
let file_name = "target/test_binary";
build_test_binary(file_name);
let mut p = std::process::Command::new(&format!("./{file_name}"))
.env("FOO", "BAR")
.env("OTHER", "VALUE")
.spawn()
Expand Down Expand Up @@ -810,8 +813,9 @@ fn test_parent_change() {
return;
}

build_test_binary();
let mut p = std::process::Command::new("./target/test_binary")
let file_name = "target/test_binary2";
build_test_binary(file_name);
let mut p = std::process::Command::new(&format!("./{file_name}"))
.arg("1")
.spawn()
.unwrap();
Expand Down

0 comments on commit a7c29eb

Please sign in to comment.