fix(test): Expose '--no-capture', deprecating '--nocapture'

This improves consistency with commonly expected CLI conventions,
avoiding a common stutter people make when running tests (trying what
they expect and then having to check the docs to then user whats
accepted).

An alternative could have been to take a value, like `--capture <value>` (e.g. `pytest` does this).
Overall, we're shifting focus for features to custom test harnesses (see #134283).
Most of `pytest`s modes will likely be irrelevant in that situation.
As for the rest, its too early to tell which, if any, may be relevant,
so we're sticking with this small, quality of life improvement.

By deprecating `--nocapture`, we intend that custom test harnesses do
not need to support it for reasons outside of their own compatibility
requirements, much like the deprecation in #134283

I'm punting for now on the naming of `RUST_TEST_NOCAPTURE`.
I feel like T-testing-devex should do a wider look at environment
variables role in lib`test` before evaluating whether to
- Deprecate it in favor of the user passing CLI flags or the test runner
  providing its own config
- Deprecate in favor of `RUST_TEST_NO_CAPTURE`
- Deprecate in favor of `RUST_TEST_CAPTURE`

Other CLI flags were evaluated for casing consistency:
- `--logfile` has the same problem but was deprecated in #134283

Fixes #133073
This commit is contained in:
Ed Page 2025-01-27 14:04:49 -06:00
parent 11f7290c9f
commit aa8670f6f8
2 changed files with 13 additions and 8 deletions

View file

@ -81,7 +81,7 @@ behavior.
> Note: When running with [`cargo test`], the libtest CLI arguments must be
> passed after the `--` argument to differentiate between flags for Cargo and
> those for the harness. For example: `cargo test -- --nocapture`
> those for the harness. For example: `cargo test -- --no-capture`
### Filters
@ -225,7 +225,7 @@ The following options affect the output behavior.
Displays one character per test instead of one line per test. This is an alias
for [`--format=terse`](#--format-format).
#### `--nocapture`
#### `--no-capture`
Does not capture the stdout and stderr of the test, and allows tests to print
to the console. Usually the output is captured, and only displayed if the test
@ -234,11 +234,13 @@ fails.
This may also be specified by setting the `RUST_TEST_NOCAPTURE` environment
variable to anything but `0`.
`--nocapture` is a deprecated alias for `--no-capture`.
#### `--show-output`
Displays the stdout and stderr of successful tests after all tests have run.
Contrast this with [`--nocapture`](#--nocapture) which allows tests to print
Contrast this with [`--no-capture`](#--no-capture) which allows tests to print
*while they are running*, which can cause interleaved output if there are
multiple tests running in parallel, `--show-output` ensures the output is
contiguous, but requires waiting for all tests to finish.
@ -247,7 +249,7 @@ contiguous, but requires waiting for all tests to finish.
Control when colored terminal output is used. Valid options:
* `auto`: Colorize if stdout is a tty and [`--nocapture`](#--nocapture) is not
* `auto`: Colorize if stdout is a tty and [`--no-capture`](#--no-capture) is not
used. This is the default.
* `always`: Always colorize the output.
* `never`: Never colorize the output.