-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make libtest
flags more discoverable
#12494
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
clap-rs/clap#4706 would allow cargo to add flags that only exist to produce a specific error message. We've been talking about using it to help in other cases. I think using that could work
|
hmm, did you mean to link a different issue? #4706 doesn't look related. |
sigh second time in the last week I didn't update a link for being cross-repo. Fixed |
There is another issue making |
Suggesting |
Does clap-rs/clap#5075 look like it'll fit the needs of this? |
I think that's a question for the cargo team, not for me. I didn't look at the error message but in general it looks like that API requires hard coding all the names of the libtest flags 🤷 |
#11702 links out to a lot of PRs where we did things like this. Specifically #12693 is an example of an arbitrary suggestion. However, looking at this further, I wonder if I would consider this a bug in clap. Generally clap suggests to put the argument after a |
Note that this is specific to For example:
There isn't a way in clap to turn this off, so making this like #11702 would lead to providing the same suggestion two different ways. |
Inspired by rust-lang/cargo#12494. Part of this is that our "did you mean" does prefix checks so it can be overly aggressive in providing suggestions. To avoid providing needless suggestions I limited this change to `last` / `trailing_var_arg` as those convey that `--` is more likely a valid suggestion.
fix(test): Suggest `--` for libtest arguments We already do this so long as the argument doesn't look like a `cargo test` argument (e.g. `--show-output`) but `--ignored` looks like `--ignore-rust-version` do the the suggestion algorithms prefix checks. Before ``` error: unexpected argument '--ignored' found tip: a similar argument exists: '--ignore-rust-version' Usage: cargo test --ignore-rust-version [TESTNAME] [-- [ARGS]...] For more information, try '--help'. ``` After ``` error: unexpected argument '--ignored' found tip: a similar argument exists: '--ignore-rust-version' tip: to pass '--ignored' as a value, use '-- --ignored' Usage: cargo test --ignore-rust-version [TESTNAME] [-- [ARGS]...] For more information, try '--help'. ``` This was fixed in clap-rs/clap#5356 and we just need to update to take advantage of it. Fixes #12494
We already do this so long as the argument doesn't look like a `cargo test` argument (e.g. `--show-output`) but `--ignored` looks like `--ignore-rust-version` do the the suggestion algorithms prefix checks. Before ``` error: unexpected argument '--ignored' found tip: a similar argument exists: '--ignore-rust-version' Usage: cargo test --ignore-rust-version [TESTNAME] [-- [ARGS]...] For more information, try '--help'. ``` After ``` error: unexpected argument '--ignored' found tip: a similar argument exists: '--ignore-rust-version' tip: to pass '--ignored' as a value, use '-- --ignored' Usage: cargo test --ignore-rust-version [TESTNAME] [-- [ARGS]...] For more information, try '--help'. ``` Fixes rust-lang#12494
We already do this so long as the argument doesn't look like a `cargo test` argument (e.g. `--show-output`) but `--ignored` looks like `--ignore-rust-version` do the the suggestion algorithms prefix checks. Before ``` error: unexpected argument '--ignored' found tip: a similar argument exists: '--ignore-rust-version' Usage: cargo test --ignore-rust-version [TESTNAME] [-- [ARGS]...] For more information, try '--help'. ``` After ``` error: unexpected argument '--ignored' found tip: a similar argument exists: '--ignore-rust-version' tip: to pass '--ignored' as a value, use '-- --ignored' Usage: cargo test --ignore-rust-version [TESTNAME] [-- [ARGS]...] For more information, try '--help'. ``` Fixes rust-lang#12494
Problem
The
libtest
unit test runner has a lot of flags. Cargo allows passing these through withcargo test --lib --
. This is not super easy to discover -cargo test --help
does say "Runcargo test -- --help
for test binary options" at the end, but if you don't know that libtest and cargo have different flags, the error messages aren't great:Proposed Solution
Ideally, cargo would know which flags libtest supports and suggest passing those through:
Notes
Right now, it's kind of hard to parse the
--help
output of libtest programmatically, so cargo would either have to hack a parser together or hardcode the options, neither of which is particularly maintainable. Ideally--help --format json
would output a structured list that cargo can easily parse (I can open an upstream issue in rust-lang/rust if you're interested in pursuing this) and then idk embed it at build time or something like that.My motivation for opening this issue is that I want to suggest
--ignored
in libtest if 1 or more tests are ignored, but right now that will be kind of confusing for people using cargo because it's a libtest flag and not acargo test
flag.The text was updated successfully, but these errors were encountered: