Skip to content

Commit

Permalink
redirect stderr for cargo
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Nov 19, 2023
1 parent 5656faa commit dac82f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-qtest"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Onur Ozkan <[email protected]>"]
license = "MIT"
Expand Down
20 changes: 11 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,29 +26,32 @@ fn get_cargo_test_output(
first_args: &[OsString],
second_args: &[OsString],
) -> Result<Vec<String>, 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.
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit dac82f8

Please sign in to comment.