Skip to content

Commit 9d93fab

Browse files
authored
Rollup merge of #142807 - sourcefrog:failfast, r=dtolnay
libtest: expose --fail-fast as an unstable command-line option This exposes the `fail_fast` option added in #105153 on the test harness command line, so that workflows that only want to know if any test fails can find out without waiting for everything to run. For example, cargo-mutants just needs to know if any tests fails. It only works with `-Zunstable-options`. Tracking issue: #142859
2 parents 3f1552a + 547c729 commit 9d93fab

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

library/test/src/cli.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn optgroups() -> getopts::Options {
5757
.optflag("", "test", "Run tests and not benchmarks")
5858
.optflag("", "bench", "Run benchmarks instead of tests")
5959
.optflag("", "list", "List all tests and benchmarks")
60+
.optflag("", "fail-fast", "Don't start new tests after the first failure")
6061
.optflag("h", "help", "Display this message")
6162
.optopt("", "logfile", "Write logs to the specified file (deprecated)", "PATH")
6263
.optflag(
@@ -260,6 +261,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {
260261
// Unstable flags
261262
let force_run_in_process = unstable_optflag!(matches, allow_unstable, "force-run-in-process");
262263
let exclude_should_panic = unstable_optflag!(matches, allow_unstable, "exclude-should-panic");
264+
let fail_fast = unstable_optflag!(matches, allow_unstable, "fail-fast");
263265
let time_options = get_time_options(&matches, allow_unstable)?;
264266
let shuffle = get_shuffle(&matches, allow_unstable)?;
265267
let shuffle_seed = get_shuffle_seed(&matches, allow_unstable)?;
@@ -306,7 +308,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {
306308
skip,
307309
time_options,
308310
options,
309-
fail_fast: false,
311+
fail_fast,
310312
};
311313

312314
Ok(test_opts)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ unstable-options` flag. See [tracking issue
158158

159159
The following options affect how tests are executed.
160160

161+
#### `--fail-fast`
162+
163+
Stops tests after the first failure.
164+
165+
If running tests in parallel (which is the default), then tests that have already been started on
166+
other threads will be allowed to run to completion before the process exits.
167+
168+
Note that when running tests in parallel, the test execution order is non-deterministic:
169+
if multiple tests would fail, the first failure encountered will be reported.
170+
171+
⚠️ 🚧 This requires the `-Z unstable-options` flag.
172+
161173
#### `--test-threads` _NUM_THREADS_
162174

163175
Sets the number of threads to use for running tests in parallel. By default,

0 commit comments

Comments
 (0)