Skip to content

Commit 8894d7f

Browse files
committed
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 rust-lang#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 rust-lang#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 rust-lang#134283 Fixes rust-lang#133073
1 parent ac8b0e2 commit 8894d7f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

library/test/src/cli.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn optgroups() -> getopts::Options {
6161
.optopt("", "logfile", "Write logs to the specified file (deprecated)", "PATH")
6262
.optflag(
6363
"",
64-
"nocapture",
64+
"no-capture",
6565
"don't capture stdout/stderr of each \
6666
task, allow printing directly",
6767
)
@@ -172,7 +172,7 @@ tests in the same order again. Note that --shuffle and --shuffle-seed do not
172172
affect whether the tests are run in parallel.
173173
174174
All tests have their standard output and standard error captured by default.
175-
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
175+
This can be overridden with the --no-capture flag or setting RUST_TEST_NOCAPTURE
176176
environment variable to a value other than "0". Logging is not captured by default.
177177
178178
Test Attributes:
@@ -199,7 +199,10 @@ Test Attributes:
199199
/// otherwise creates a `TestOpts` object and returns it.
200200
pub fn parse_opts(args: &[String]) -> Option<OptRes> {
201201
// Parse matches.
202-
let opts = optgroups();
202+
let mut opts = optgroups();
203+
// Flags hidden from `usage`
204+
opts.optflag("", "nocapture", "Deprecated, use `--no-capture`");
205+
203206
let binary = args.first().map(|c| &**c).unwrap_or("...");
204207
let args = args.get(1..).unwrap_or(args);
205208
let matches = match opts.parse(args) {
@@ -447,7 +450,7 @@ fn get_color_config(matches: &getopts::Matches) -> OptPartRes<ColorConfig> {
447450
}
448451

449452
fn get_nocapture(matches: &getopts::Matches) -> OptPartRes<bool> {
450-
let mut nocapture = matches.opt_present("nocapture");
453+
let mut nocapture = matches.opt_present("nocapture") || matches.opt_present("no-capture");
451454
if !nocapture {
452455
nocapture = match env::var("RUST_TEST_NOCAPTURE") {
453456
Ok(val) => &val != "0",

src/doc/rustc/src/tests/index.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ behavior.
8181

8282
> Note: When running with [`cargo test`], the libtest CLI arguments must be
8383
> passed after the `--` argument to differentiate between flags for Cargo and
84-
> those for the harness. For example: `cargo test -- --nocapture`
84+
> those for the harness. For example: `cargo test -- --no-capture`
8585
8686
### Filters
8787

@@ -225,7 +225,7 @@ The following options affect the output behavior.
225225
Displays one character per test instead of one line per test. This is an alias
226226
for [`--format=terse`](#--format-format).
227227

228-
#### `--nocapture`
228+
#### `--no-capture`
229229

230230
Does not capture the stdout and stderr of the test, and allows tests to print
231231
to the console. Usually the output is captured, and only displayed if the test
@@ -234,11 +234,13 @@ fails.
234234
This may also be specified by setting the `RUST_TEST_NOCAPTURE` environment
235235
variable to anything but `0`.
236236

237+
`--nocapture` is a deprecated alias for `--no-capture`.
238+
237239
#### `--show-output`
238240

239241
Displays the stdout and stderr of successful tests after all tests have run.
240242

241-
Contrast this with [`--nocapture`](#--nocapture) which allows tests to print
243+
Contrast this with [`--no-capture`](#--no-capture) which allows tests to print
242244
*while they are running*, which can cause interleaved output if there are
243245
multiple tests running in parallel, `--show-output` ensures the output is
244246
contiguous, but requires waiting for all tests to finish.
@@ -247,7 +249,7 @@ contiguous, but requires waiting for all tests to finish.
247249

248250
Control when colored terminal output is used. Valid options:
249251

250-
* `auto`: Colorize if stdout is a tty and [`--nocapture`](#--nocapture) is not
252+
* `auto`: Colorize if stdout is a tty and [`--no-capture`](#--no-capture) is not
251253
used. This is the default.
252254
* `always`: Always colorize the output.
253255
* `never`: Never colorize the output.

0 commit comments

Comments
 (0)