Skip to content

fix: don't hand nextest a phantom-only filterset in run - #81

Open
cargo-affected-bot wants to merge 1 commit into
mainfrom
fix/run-all-phantom-selection-exit4
Open

fix: don't hand nextest a phantom-only filterset in run#81
cargo-affected-bot wants to merge 1 commit into
mainfrom
fix/run-all-phantom-selection-exit4

Conversation

@cargo-affected-bot

Copy link
Copy Markdown
Collaborator

Deleting a test makes cargo affected run exit 4 with error: no tests to run.

Deleting a test function produces a diff hunk over exactly the lines its own stored coverage range covers, so the deleted test is selected as affected — and if the deletion is the only change, it is the whole selection. It is also gone from the current nextest list, so the generated default-filter matches nothing, and nextest's "no tests to run" exit propagates through run_tests. A stale cache row is reported to the caller as a test failure.

collect --diff has never had this problem: it passes --no-tests=warn and uses DiffPlan::live_selected_count afterwards to tell an all-phantom rerun from a runner-shim failure. run had no equivalent.

Repro

Against the two-module scratch project the functional suite uses, with the whole test_multiply block deleted and nothing else changed:

1 tests to run (1 affected + 0 config + 0 new + 0 stranded, 1 skipped of 2 reachable-known)
running 1 tests with nextest
    Starting 0 tests across 1 binary (1 test skipped via profile.default.default-filter)
     Summary [   0.000s] 0 tests run: 0 passed, 1 skipped
error: no tests to run

Exit code 4.

Change

Selection::live_selected() (new, in selection.rs) is selected() restricted to tests still in the listing. run hands nextest that subset instead of the full selection, and short-circuits with exit 0 when it is empty — there is no run to make, and asking nextest to run a phantom-only filterset can only produce the exit above. Both paths emit a note naming the count and pointing at cargo affected collect to drop the rows.

status gets the same note, in the conditional tense. Without it the dry run would predict a test that run now visibly skips, which is the invariant #71 established.

collect --diff is untouched — it keeps phantoms in its filterset deliberately, and prunes their rows afterwards.

Tests

run_with_all_phantom_selection_exits_zero (functional) collects, deletes test_multiply, and asserts exit 0 plus the two new messages. Verified failing against pre-fix src/: run with an all-phantom selection must exit 0, got Some(4), with error: no tests to run in the captured output.

Two unit tests in selection.rs pin live_selected()'s filtering and the notice's singular/plural agreement.

cargo test is green (114 unit + 42 functional); cargo clippy --all-targets is clean.

Relationship to #39 / #41

Same exit-4 failure class, different trigger, disjoint fix. #41 keeps filter-mismatched tests (positional filters, -E, #[ignore]) out of the selection by keying off filter-match.status; its own comment notes that phantoms are deliberately not in listing.excluded and stay in affected. This handles that remaining source. The two should merge cleanly enough — #41 edits the top of compute and the imports in run.rs; this edits impl Selection and the tail of run().

Deleting a test produces a hunk over exactly its own stored range, so it
lands in `affected` — and when nothing else changed, it is the whole
selection. It is also gone from `nextest list`, so the generated
default-filter matches nothing and nextest's exit 4 propagates: a stale
cache row reported as a test failure.

`run` now hands nextest `Selection::live_selected()` and short-circuits
with exit 0 when that is empty, noting the count either way. `status`
renders the same note in the conditional tense so its prediction still
matches what `run` does. `collect --diff` is untouched: it keeps
phantoms deliberately and prunes their rows afterwards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant