feat: remove --keep-going from cargo test/bench

It confuses people that both `--no-fail-fast` and `--keep-going` exist
on `cargo test` and `cargo bench` but with slightly different behavior.
The intended use cases for `--keep-going` involve build commands like
`build`/`check`/`clippy` but never `test`/`bench`.

Hence, this commit removes `--keep-going` from `test`/`bench` and
provides guidance of `--no-fail-fast` instead.

If people really want to build as many tests as possible, they can also
do it in two steps:

    cargo build --tests --keep-going
    cargo test --test --no-fail-fast
This commit is contained in:
Weihang Lo 2023-08-11 14:12:59 +01:00
parent 7da103076e
commit 5ae529b24e
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
11 changed files with 71 additions and 30 deletions

View File

@ -42,7 +42,8 @@ pub fn cli() -> Command {
"Benchmark all targets",
)
.arg_features()
.arg_jobs()
.arg_jobs_without_keep_going()
.arg(flag("keep-going", "Use `--no-fail-fast` instead").hide(true)) // See rust-lang/cargo#11702
.arg_profile("Build artifacts with the specified profile")
.arg_target_triple("Build for the target triple")
.arg_target_dir()
@ -54,6 +55,17 @@ pub fn cli() -> Command {
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let ws = args.workspace(config)?;
if args.keep_going() {
return Err(anyhow::format_err!(
"\
unexpected argument `--keep-going` found
tip: to run as many benchmarks as possible without failing fast, use `--no-fail-fast`"
)
.into());
}
let mut compile_opts = args.compile_options(
config,
CompileMode::Bench,

View File

@ -48,7 +48,8 @@ pub fn cli() -> Command {
"Test all targets (does not include doctests)",
)
.arg_features()
.arg_jobs()
.arg_jobs_without_keep_going()
.arg(flag("keep-going", "Use `--no-fail-fast` instead").hide(true)) // See rust-lang/cargo#11702
.arg_release("Build artifacts in release mode, with optimizations")
.arg_profile("Build artifacts with the specified profile")
.arg_target_triple("Build for the target triple")
@ -65,6 +66,16 @@ pub fn cli() -> Command {
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let ws = args.workspace(config)?;
if args.keep_going() {
return Err(anyhow::format_err!(
"\
unexpected argument `--keep-going` found
tip: to run as many tests as possible without failing fast, use `--no-fail-fast`"
)
.into());
}
let mut compile_opts = args.compile_options(
config,
CompileMode::Test,

View File

@ -83,6 +83,16 @@ pub trait CommandExt: Sized {
}
fn arg_jobs(self) -> Self {
self.arg_jobs_without_keep_going()._arg(
flag(
"keep-going",
"Do not abort the build as soon as there is an error (unstable)",
)
.help_heading(heading::COMPILATION_OPTIONS),
)
}
fn arg_jobs_without_keep_going(self) -> Self {
self._arg(
opt("jobs", "Number of parallel jobs, defaults to # of CPUs.")
.short('j')
@ -90,13 +100,6 @@ pub trait CommandExt: Sized {
.allow_hyphen_values(true)
.help_heading(heading::COMPILATION_OPTIONS),
)
._arg(
flag(
"keep-going",
"Do not abort the build as soon as there is an error (unstable)",
)
.help_heading(heading::COMPILATION_OPTIONS),
)
}
fn arg_targets_all(

View File

@ -186,7 +186,6 @@ includes an option to control the number of threads used:
{{#options}}
{{> options-jobs }}
{{> options-keep-going }}
{{> options-future-incompat }}
{{/options}}

View File

@ -442,11 +442,6 @@ OPTIONS
If a string default is provided, it sets the value back to defaults.
Should not be 0.
--keep-going
Build as many crates in the dependency graph as possible, rather
than aborting the build on the first one that fails to build.
Unstable, requires -Zunstable-options.
--future-incompat-report
Displays a future-incompat report for any future-incompatible
warnings produced during execution of this command

View File

@ -515,12 +515,6 @@ a string <code>default</code> is provided, it sets the value back to defaults.
Should not be 0.</dd>
<dt class="option-term" id="option-cargo-test---keep-going"><a class="option-anchor" href="#option-cargo-test---keep-going"></a><code>--keep-going</code></dt>
<dd class="option-desc">Build as many crates in the dependency graph as possible, rather than aborting
the build on the first one that fails to build. Unstable, requires
<code>-Zunstable-options</code>.</dd>
<dt class="option-term" id="option-cargo-test---future-incompat-report"><a class="option-anchor" href="#option-cargo-test---future-incompat-report"></a><code>--future-incompat-report</code></dt>
<dd class="option-desc">Displays a future-incompat report for any future-incompatible warnings
produced during execution of this command</p>

View File

@ -535,13 +535,6 @@ a string \fBdefault\fR is provided, it sets the value back to defaults.
Should not be 0.
.RE
.sp
\fB\-\-keep\-going\fR
.RS 4
Build as many crates in the dependency graph as possible, rather than aborting
the build on the first one that fails to build. Unstable, requires
\fB\-Zunstable\-options\fR\&.
.RE
.sp
\fB\-\-future\-incompat\-report\fR
.RS 4
Displays a future\-incompat report for any future\-incompatible warnings

View File

@ -1670,3 +1670,21 @@ fn json_artifact_includes_executable_for_benchmark() {
)
.run();
}
#[cargo_test]
fn cargo_bench_no_keep_going() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", "")
.build();
p.cargo("bench --keep-going")
.with_stderr(
"\
error: unexpected argument `--keep-going` found
tip: to run as many benchmarks as possible without failing fast, use `--no-fail-fast`",
)
.with_status(101)
.run();
}

View File

@ -44,7 +44,6 @@ Feature Selection:
Compilation Options:
-j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
--keep-going Do not abort the build as soon as there is an error (unstable)
--profile <PROFILE-NAME> Build artifacts with the specified profile
--target <TRIPLE> Build for the target triple
--target-dir <DIRECTORY> Directory for all generated artifacts

View File

@ -46,7 +46,6 @@ Feature Selection:
Compilation Options:
-j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
--keep-going Do not abort the build as soon as there is an error (unstable)
-r, --release Build artifacts in release mode, with optimizations
--profile <PROFILE-NAME> Build artifacts with the specified profile
--target <TRIPLE> Build for the target triple

View File

@ -4843,3 +4843,21 @@ error: 2 targets failed:
.with_status(101)
.run();
}
#[cargo_test]
fn cargo_test_no_keep_going() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", "")
.build();
p.cargo("test --keep-going")
.with_stderr(
"\
error: unexpected argument `--keep-going` found
tip: to run as many tests as possible without failing fast, use `--no-fail-fast`",
)
.with_status(101)
.run();
}