Skip to content

Commit 777e16a

Browse files
committed
[cargo-nextest] change no-tests behavior
Per #1646.
1 parent 4d8f74e commit 777e16a

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

cargo-nextest/src/dispatch.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,7 @@ pub struct TestRunnerOpts {
848848
#[arg(long, conflicts_with = "no-run", overrides_with = "fail-fast")]
849849
no_fail_fast: bool,
850850

851-
/// Behavior if there are no tests to run.
852-
///
853-
/// The default is currently `warn`, but it will change to `fail` in the future.
851+
/// Behavior if there are no tests to run [default: fail]
854852
#[arg(
855853
long,
856854
value_enum,
@@ -862,13 +860,12 @@ pub struct TestRunnerOpts {
862860
no_tests: Option<NoTestsBehavior>,
863861
}
864862

865-
#[derive(Clone, Copy, Debug, Default, ValueEnum)]
863+
#[derive(Clone, Copy, Debug, ValueEnum)]
866864
enum NoTestsBehavior {
867865
/// Silently exit with code 0.
868866
Pass,
869867

870868
/// Produce a warning and exit with code 0.
871-
#[default]
872869
Warn,
873870

874871
/// Produce an error message and exit with code 4.
@@ -1798,27 +1795,15 @@ impl App {
17981795

17991796
match run_stats.summarize_final() {
18001797
FinalRunStats::Success => Ok(0),
1801-
FinalRunStats::NoTestsRun => {
1802-
match runner_opts.no_tests {
1803-
Some(NoTestsBehavior::Pass) => Ok(0),
1804-
Some(NoTestsBehavior::Warn) => {
1805-
warn!("no tests to run");
1806-
Ok(0)
1807-
}
1808-
Some(NoTestsBehavior::Fail) => {
1809-
Err(ExpectedError::NoTestsRun { is_default: false })
1810-
}
1811-
None => {
1812-
// This currently does not exit with a non-zero code, but will in the
1813-
// future: https://github.com/nextest-rs/nextest/issues/1639
1814-
warn!(
1815-
"no tests to run -- this will become an error in the future\n\
1816-
(hint: use `--no-tests` to customize)"
1817-
);
1818-
Ok(0)
1819-
}
1798+
FinalRunStats::NoTestsRun => match runner_opts.no_tests {
1799+
Some(NoTestsBehavior::Pass) => Ok(0),
1800+
Some(NoTestsBehavior::Warn) => {
1801+
warn!("no tests to run");
1802+
Ok(0)
18201803
}
1821-
}
1804+
Some(NoTestsBehavior::Fail) => Err(ExpectedError::NoTestsRun { is_default: false }),
1805+
None => Err(ExpectedError::NoTestsRun { is_default: true }),
1806+
},
18221807
FinalRunStats::Cancelled(RunStatsFailureKind::SetupScript)
18231808
| FinalRunStats::Failed(RunStatsFailureKind::SetupScript) => {
18241809
Err(ExpectedError::setup_script_failed())

integration-tests/tests/integration/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,22 @@ fn test_run_no_tests() {
302302
"-E",
303303
"none()",
304304
])
305+
.unchecked(true)
305306
.output();
306307

308+
assert_eq!(
309+
output.exit_status.code(),
310+
Some(NextestExitCode::NO_TESTS_RUN),
311+
"correct exit code for command\n{output}"
312+
);
313+
307314
let stderr = output.stderr_as_str();
308315
assert!(
309316
stderr.contains("Starting 0 tests across 0 binaries (8 binaries skipped)"),
310317
"stderr contains 'Starting' message: {output}"
311318
);
312319
assert!(
313-
stderr.contains("warning: no tests to run -- this will become an error in the future"),
320+
stderr.contains("error: no tests to run\n(hint: use `--no-tests` to customize)"),
314321
"stderr contains no tests message: {output}"
315322
);
316323

0 commit comments

Comments
 (0)