diff --git a/cargo-nextest/src/dispatch.rs b/cargo-nextest/src/dispatch.rs index dd12dd0954e..8ad476c46b3 100644 --- a/cargo-nextest/src/dispatch.rs +++ b/cargo-nextest/src/dispatch.rs @@ -848,9 +848,7 @@ pub struct TestRunnerOpts { #[arg(long, conflicts_with = "no-run", overrides_with = "fail-fast")] no_fail_fast: bool, - /// Behavior if there are no tests to run. - /// - /// The default is currently `warn`, but it will change to `fail` in the future. + /// Behavior if there are no tests to run [default: fail] #[arg( long, value_enum, @@ -862,13 +860,12 @@ pub struct TestRunnerOpts { no_tests: Option, } -#[derive(Clone, Copy, Debug, Default, ValueEnum)] +#[derive(Clone, Copy, Debug, ValueEnum)] enum NoTestsBehavior { /// Silently exit with code 0. Pass, /// Produce a warning and exit with code 0. - #[default] Warn, /// Produce an error message and exit with code 4. @@ -1798,27 +1795,15 @@ impl App { match run_stats.summarize_final() { FinalRunStats::Success => Ok(0), - FinalRunStats::NoTestsRun => { - match runner_opts.no_tests { - Some(NoTestsBehavior::Pass) => Ok(0), - Some(NoTestsBehavior::Warn) => { - warn!("no tests to run"); - Ok(0) - } - Some(NoTestsBehavior::Fail) => { - Err(ExpectedError::NoTestsRun { is_default: false }) - } - None => { - // This currently does not exit with a non-zero code, but will in the - // future: https://github.com/nextest-rs/nextest/issues/1639 - warn!( - "no tests to run -- this will become an error in the future\n\ - (hint: use `--no-tests` to customize)" - ); - Ok(0) - } + FinalRunStats::NoTestsRun => match runner_opts.no_tests { + Some(NoTestsBehavior::Pass) => Ok(0), + Some(NoTestsBehavior::Warn) => { + warn!("no tests to run"); + Ok(0) } - } + Some(NoTestsBehavior::Fail) => Err(ExpectedError::NoTestsRun { is_default: false }), + None => Err(ExpectedError::NoTestsRun { is_default: true }), + }, FinalRunStats::Cancelled(RunStatsFailureKind::SetupScript) | FinalRunStats::Failed(RunStatsFailureKind::SetupScript) => { Err(ExpectedError::setup_script_failed()) diff --git a/integration-tests/tests/integration/main.rs b/integration-tests/tests/integration/main.rs index a59a56c39b0..7e43b74409e 100644 --- a/integration-tests/tests/integration/main.rs +++ b/integration-tests/tests/integration/main.rs @@ -302,15 +302,22 @@ fn test_run_no_tests() { "-E", "none()", ]) + .unchecked(true) .output(); + assert_eq!( + output.exit_status.code(), + Some(NextestExitCode::NO_TESTS_RUN), + "correct exit code for command\n{output}" + ); + let stderr = output.stderr_as_str(); assert!( stderr.contains("Starting 0 tests across 0 binaries (8 binaries skipped)"), "stderr contains 'Starting' message: {output}" ); assert!( - stderr.contains("warning: no tests to run -- this will become an error in the future"), + stderr.contains("error: no tests to run\n(hint: use `--no-tests` to customize)"), "stderr contains no tests message: {output}" );