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

[cargo-nextest] Run tests when no subcommand is provided #800

Open
jalil-salame opened this issue Jan 30, 2023 · 7 comments
Open

[cargo-nextest] Run tests when no subcommand is provided #800

jalil-salame opened this issue Jan 30, 2023 · 7 comments
Labels
deferred Work deferred or blocked

Comments

@jalil-salame
Copy link

Problem

cargo nextest fails as no subcommand is provided.

Version

cargo-nextest-nextest 0.9.49

Use case

When combined with cargo watch nextest is overly verbose:

$ cargo watch -x nextest
Fails as no subcomand is provided
$ cargo watch -s 'cargo nextest run'
...

Solution

Default to cargo nextest run when no arguments are provided.

@sunshowers
Copy link
Member

Thanks for the report! Unfortunately that isn't really possible to do at the moment, since it's ambiguous whether a particular argument is a subcommand or the name of a test case.

For example, does:

cargo nextest list

mean "run all tests with list in the name", or does it mean "run the list subcommand"? This is even more problematic in an automated context, where you can't inspect the command directly.

This is a mistake I made while initially defining the CLI -- what I should have done is always require you to specify -- before the name of a test filter. For example:

cargo nextest run -- test-name

If we'd done that, we could have specified run as a default subcommand, making this equivalent:

cargo nextest -- test-name

However, this unfortunately isn't fixable without a breaking change.

See also: #459.

@sunshowers
Copy link
Member

sunshowers commented Jan 30, 2023

Hmm, thinking about this more: one thing we could do is that if no positional arguments are specified before --, treat cargo nextest as cargo nextest run. That avoids ambiguity.

edit: only applies to positional arguments

@sunshowers
Copy link
Member

sunshowers commented Jan 30, 2023

Yeah, so we can support all of:

cargo nextest
cargo nextest -- test-filter
cargo nextest run
cargo nextest run -- test-filter
cargo nextest run test-filter
cargo nextest list
cargo nextest list test-filter
cargo nextest list -- test-filter

but not:

cargo nextest test-filter

@jalil-salame
Copy link
Author

Hmm, thinking about this more: one thing we could do is that if no arguments are specified before --, treat cargo nextest as cargo nextest run. That avoids ambiguity.

This solves my use case (no arguments), although I do think that, a separate issue, should address the 1.0 release interface, to polish the edges.

@sunshowers
Copy link
Member

(Note that we can continue to support options and flags like --no-fail-fast. It's specifically positional arguments that we won't be able to support.)

@sunshowers
Copy link
Member

This is really tricky to do correctly with clap currently. I think I'm going to defer this. As a compromise, I've added cargo nextest r as an alias to cargo nextest run.

Meanwhile you can add an alias to your $HOME/.cargo/config.toml.

@sunshowers sunshowers closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2023
@sunshowers
Copy link
Member

Going to reopen this, since I think it's desirable eventually once clap has better support for it (clap-rs/clap#975).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deferred Work deferred or blocked
Projects
None yet
Development

No branches or pull requests

2 participants