diff --git a/Cargo.lock b/Cargo.lock index 209eb67..e47091a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cargo-qtest" -version = "0.1.1" +version = "0.1.2" dependencies = [ "inquire", "regex", diff --git a/Cargo.toml b/Cargo.toml index f4d8ce0..51736b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-qtest" -version = "0.1.1" +version = "0.1.2" edition = "2021" authors = ["Onur Ozkan "] license = "MIT" diff --git a/src/main.rs b/src/main.rs index 5805aa7..8830ba9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::env; use std::ffi::OsString; use std::process::exit; use std::process::Command; +use std::process::Stdio; /// Returns the cargo binary path from the `CARGO` environment /// variable; this enables us to execute cargo from the correct @@ -25,29 +26,32 @@ fn get_cargo_test_output( first_args: &[OsString], second_args: &[OsString], ) -> Result, String> { - let mut cargo = Command::new(cargo_bin()); + println!("Collecting test files from the project..\n"); + let mut cargo = Command::new(cargo_bin()); let cargo = cargo .arg("test") .args(first_args) + .arg("--quiet") .arg("--") .args(second_args) .args(["--list", "--color", "never", "--format", "terse"]); + cargo.stderr(Stdio::inherit()); + cargo.envs(std::env::vars_os()); let output = cargo .output() .map_err(|e| format!("Reading test metadata failed. {}", e))?; - if output.status.success() { - String::from_utf8(output.stdout) - .map(|data| data.lines().map(String::from).collect()) - .map_err(|e| format!("Reading stdout failed. {}", e)) - } else { - eprintln!("Cargo failed with: {:?}", output.status); + if !output.status.success() { exit(1); } + + String::from_utf8(output.stdout) + .map(|data| data.lines().map(String::from).collect()) + .map_err(|e| format!("Reading stdout failed. {}", e)) } /// Filters out the test paths with regex from a vector of strings. @@ -170,8 +174,6 @@ fn main() { (&args[..], &[][..]) }; - println!("Collecting test files from the project..\n"); - let lines = match get_cargo_test_output(first_args, second_args) { Ok(t) => t, Err(err) => {