From 4acf3baecda9c5080bcfdc1ebb4560fbb2a4567e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 20 Jun 2025 13:18:05 -0700 Subject: [PATCH 1/2] libtest: expose --fail-fast --- library/test/src/cli.rs | 4 +++- src/doc/rustc/src/tests/index.md | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 8840714a66238..d19141b8c2c73 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -57,6 +57,7 @@ fn optgroups() -> getopts::Options { .optflag("", "test", "Run tests and not benchmarks") .optflag("", "bench", "Run benchmarks instead of tests") .optflag("", "list", "List all tests and benchmarks") + .optflag("", "fail-fast", "Don't start new tests after the first failure") .optflag("h", "help", "Display this message") .optopt("", "logfile", "Write logs to the specified file (deprecated)", "PATH") .optflag( @@ -270,6 +271,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { let exact = matches.opt_present("exact"); let list = matches.opt_present("list"); let skip = matches.opt_strs("skip"); + let fail_fast = matches.opt_present("fail-fast"); let bench_benchmarks = matches.opt_present("bench"); let run_tests = !bench_benchmarks || matches.opt_present("test"); @@ -307,7 +309,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { skip, time_options, options, - fail_fast: false, + fail_fast, }; Ok(test_opts) diff --git a/src/doc/rustc/src/tests/index.md b/src/doc/rustc/src/tests/index.md index 12de69a4c9eec..7033184e52aa9 100644 --- a/src/doc/rustc/src/tests/index.md +++ b/src/doc/rustc/src/tests/index.md @@ -158,6 +158,16 @@ unstable-options` flag. See [tracking issue The following options affect how tests are executed. +#### `--fail-fast` + +Stops tests after the first failure. + +If running tests in parallel (which is the default), then tests that have already been started on +other threads will be allowed to run to completion before the process exits. + +Note that when running tests in parallel, the test execution order is non-deterministic: +if multiple tests would fail, the first failure encountered will be reported. + #### `--test-threads` _NUM_THREADS_ Sets the number of threads to use for running tests in parallel. By default, From 547c72901ad145b40d7271e3ddef2b4ac0c53619 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 20 Jun 2025 13:27:53 -0700 Subject: [PATCH 2/2] Make fail-fast unstable --- library/test/src/cli.rs | 2 +- src/doc/rustc/src/tests/index.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index d19141b8c2c73..ea91ebc4e9875 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -262,6 +262,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { // Unstable flags let force_run_in_process = unstable_optflag!(matches, allow_unstable, "force-run-in-process"); let exclude_should_panic = unstable_optflag!(matches, allow_unstable, "exclude-should-panic"); + let fail_fast = unstable_optflag!(matches, allow_unstable, "fail-fast"); let time_options = get_time_options(&matches, allow_unstable)?; let shuffle = get_shuffle(&matches, allow_unstable)?; let shuffle_seed = get_shuffle_seed(&matches, allow_unstable)?; @@ -271,7 +272,6 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { let exact = matches.opt_present("exact"); let list = matches.opt_present("list"); let skip = matches.opt_strs("skip"); - let fail_fast = matches.opt_present("fail-fast"); let bench_benchmarks = matches.opt_present("bench"); let run_tests = !bench_benchmarks || matches.opt_present("test"); diff --git a/src/doc/rustc/src/tests/index.md b/src/doc/rustc/src/tests/index.md index 7033184e52aa9..ab96fbcd3178e 100644 --- a/src/doc/rustc/src/tests/index.md +++ b/src/doc/rustc/src/tests/index.md @@ -168,6 +168,8 @@ other threads will be allowed to run to completion before the process exits. Note that when running tests in parallel, the test execution order is non-deterministic: if multiple tests would fail, the first failure encountered will be reported. +⚠️ 🚧 This requires the `-Z unstable-options` flag. + #### `--test-threads` _NUM_THREADS_ Sets the number of threads to use for running tests in parallel. By default,