Skip to content

Commit

Permalink
Merge pull request #44 from zjp-CN/main
Browse files Browse the repository at this point in the history
fixup!(v0.2.5): reinterpret `--version`/`-V` to show cargo-pretty-test version
  • Loading branch information
zjp-CN authored Oct 14, 2023
2 parents 4b034f3 + a7b802a commit 43f372f
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ use termtree::Tree;

/// Output from `cargo test`
pub struct Emit {
/// Raw output.
output: Output,
/// Raw output. None means don't run `cargo test` like for `--version`.
output: Option<Output>,
/// Don't parse the output. Forward the output instead.
no_parse: bool,
}

impl Emit {
pub fn run(self) -> ExitCode {
let Emit { output, no_parse } = self;
let Some(output) = output else {
return ExitCode::SUCCESS;
};
let raw_err = String::from_utf8_lossy(&output.stderr);
let raw_out = String::from_utf8_lossy(&output.stdout);
let stderr = strip_ansi_escapes::strip(&*raw_err);
Expand Down Expand Up @@ -76,15 +79,25 @@ pub fn cargo_test() -> Emit {
// `cargo-pretty-test` yields ["path-to-cargo-pretty-test", rest]
&passin[1..]
};
if forward.iter().any(|arg| arg == "--version" || arg == "-V") {
const VERSION: &str = env!("CARGO_PKG_VERSION");
println!("cargo-pretty-test version: {VERSION}");
return Emit {
output: None,
no_parse: true,
};
}
set_color(forward);
let no_parse = forward.iter().any(|arg| arg == "--help" || arg == "-h");
let args = forward.iter().filter(|&arg| arg != "--nocapture");
Emit {
output: Command::new("cargo")
.arg("test")
.args(args)
.output()
.expect("`cargo test` failed"),
output: Some(
Command::new("cargo")
.arg("test")
.args(args)
.output()
.expect("`cargo test` failed"),
),
no_parse,
}
}
Expand Down

0 comments on commit 43f372f

Please sign in to comment.