Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cargo nextest support #144

Merged
merged 2 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ SUBCOMMANDS:
Output the environment set by cargo-llvm-cov to build Rust projects
clean
Remove artifacts that cargo-llvm-cov has generated in the past
nextest
Run tests with cargo nextest
help
Print this message or the help of the given subcommand(s)
```
Expand Down
13 changes: 13 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ pub(crate) enum Subcommand {
)]
Clean(CleanOptions),

/// Run tests with cargo nextest
#[clap(
bin_name = "cargo llvm-cov nextest",
max_term_width(MAX_TERM_WIDTH),
setting(AppSettings::DeriveDisplayOrder),
trailing_var_arg = true,
allow_hyphen_values = true
)]
Nextest {
#[clap(multiple_values = true)]
passthrough_options: Vec<String>,
},

// internal (unstable)
#[clap(
bin_name = "cargo llvm-cov demangle",
Expand Down
51 changes: 51 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ fn try_main() -> Result<()> {
writer.set("CARGO_LLVM_COV_TARGET_DIR", cx.ws.metadata.target_directory.as_str());
}

Some(Subcommand::Nextest { passthrough_options }) => {
let cx = &context_from_args(
&mut Args::try_parse_from(
[
// fake argv[0] to help clap parse
"nextest".to_string(),
]
.iter()
// real pass-through args
.chain(passthrough_options.iter()),
)?,
false,
)?;

clean::clean_partial(cx)?;
create_dirs(cx)?;
match (args.no_run, cx.cov.no_report) {
(false, false) => {
run_nextest(cx, &args)?;
generate_report(cx)?;
}
(false, true) => {
run_nextest(cx, &args)?;
}
(true, false) => {
generate_report(cx)?;
}
(true, true) => unreachable!(),
}
}

None => {
let cx = &context_from_args(&mut args, false)?;
let tmp = term::warn(); // The following warnings should not be promoted to an error.
Expand Down Expand Up @@ -274,6 +305,26 @@ fn run_test(cx: &Context, args: &Args) -> Result<()> {
Ok(())
}

fn run_nextest(cx: &Context, args: &Args) -> Result<()> {
let mut cargo = cx.cargo();

set_env(cx, &mut cargo);

cargo.arg("nextest").arg("run");

if cx.doctests {
return Err(anyhow::anyhow!("doctest is not supported for nextest"));
}

cargo::test_args(cx, args, &mut cargo);

if term::verbose() {
status!("Running", "{}", cargo);
}
cargo.stdout_to_stderr().run()?;
Ok(())
}

fn run_run(cx: &Context, args: &RunOptions) -> Result<()> {
let mut cargo = cx.cargo();

Expand Down
2 changes: 2 additions & 0 deletions tests/long-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,7 @@ SUBCOMMANDS:
Output the environment set by cargo-llvm-cov to build Rust projects
clean
Remove artifacts that cargo-llvm-cov has generated in the past
nextest
Run tests with cargo nextest
help
Print this message or the help of the given subcommand(s)
1 change: 1 addition & 0 deletions tests/short-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ SUBCOMMANDS:
run Run a binary or example and generate coverage report
show-env Output the environment set by cargo-llvm-cov to build Rust projects
clean Remove artifacts that cargo-llvm-cov has generated in the past
nextest Run tests with cargo nextest
help Print this message or the help of the given subcommand(s)