Skip to content

Commit

Permalink
[cargo-nextest] add help text for --skip and --exact
Browse files Browse the repository at this point in the history
Provide a hint to use a filter expression instead.

Closes #29.
  • Loading branch information
sunshowers committed Jul 9, 2022
1 parent ba0899f commit 035bef7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cargo-nextest/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ impl TestBuildFilter {
let mut ignore_filters = Vec::new();
let mut read_trailing_filters = false;

let mut skip_exact = Vec::new();
let mut unsupported_args = Vec::new();

patterns.extend(
Expand All @@ -473,6 +474,9 @@ impl TestBuildFilter {
} else if s == "--" {
read_trailing_filters = true;
false
} else if s == "--skip" || s == "--exact" {
skip_exact.push(s.clone());
false
} else {
unsupported_args.push(s.clone());
true
Expand All @@ -499,6 +503,13 @@ impl TestBuildFilter {
}
}

if !skip_exact.is_empty() {
return Err(ExpectedError::test_binary_args_parse_error(
"unsupported\n(hint: use a filter expression instead: <https://nexte.st/book/filter-expressions>)",
skip_exact,
));
}

if !unsupported_args.is_empty() {
return Err(ExpectedError::test_binary_args_parse_error(
"unsupported",
Expand Down
11 changes: 11 additions & 0 deletions site/src/book/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ cargo nextest run <test-name1> <test-name2>...

This is different from `cargo test`, where you have to specify a `--`, for example: `cargo test -- <test-name1> <test-name2>...`.

### `--skip` and `--exact`

Nextest does not support `--skip` and `--exact` directly; instead, it supports more powerful [filter expressions](filter-expressions.md) which supersede these options.

Here are some examples:

| Cargo test command | Nextest command |
|:-----------------------------------------------:|:-------------------------------------------------------:|
| `cargo test -- --skip skip1 --skip skip2 test3` | `cargo nextest run -E 'test(test3) - test(/skip[12]/)'` |
| `cargo test -- --exact test1 test2` | `cargo nextest run -E 'test(=test1) + test(=test2)'` |

### Filtering by build platform

While cross-compiling code, some tests (e.g. proc-macro tests) may need to be run on the host platform. To filter tests based on the build platform they're for, nextest accepts the `--platform-filter` option with values `target`, `host` or `any` (default).
Expand Down
1 change: 0 additions & 1 deletion site/src/book/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ For more information about running tests, see [Running tests](running.md).
To work around this, consider combining those tests into one so that nextest runs them as a
unit, or excluding those tests from nextest.
* There's [no way](https://github.com/nextest-rs/nextest/issues/28) to mark a particular test binary as excluded from nextest.
* The `--skip` and `--exact` test filter options are currently [not supported](https://github.com/nextest-rs/nextest/issues/29) by nextest.
* Doctests are currently [not supported](https://github.com/nextest-rs/nextest/issues/16) because of limitations in stable Rust. Locally and in CI, after `cargo nextest run`, use `cargo test --doc` to run all doctests.

0 comments on commit 035bef7

Please sign in to comment.