Skip to content

Commit ae48325

Browse files
committed
Run all available tests if there are no pending --failed tests
Closes #10781
1 parent c8a52fd commit ae48325

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/mix/lib/mix/tasks/test.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ defmodule Mix.Tasks.Test do
116116
* `--export-coverage` - the name of the file to export coverage results to.
117117
Only has an effect when used with `--cover`
118118
119-
* `--failed` - runs only tests that failed the last time they ran
119+
* `--failed` - runs only tests that failed the last time they ran.
120+
If there are no pending --failed tests, `mix test` will run all available tests
120121
121122
* `--force` - forces compilation regardless of modification times
122123
@@ -688,7 +689,13 @@ defmodule Mix.Tasks.Test do
688689
end
689690

690691
{allowed_files, failed_ids} = ExUnit.Filters.failure_info(manifest_file)
691-
{Keyword.put(opts, :only_test_ids, failed_ids), allowed_files}
692+
693+
if MapSet.size(failed_ids) == 0 do
694+
Mix.shell().info("No pending --failed tests, re-running all available tests...")
695+
{opts, nil}
696+
else
697+
{Keyword.put(opts, :only_test_ids, failed_ids), allowed_files}
698+
end
692699
else
693700
{opts, nil}
694701
end

lib/mix/test/mix/tasks/test_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ defmodule Mix.Tasks.TestTest do
215215
assert mix(["test", "--failed"]) =~ "2 tests, 0 failures"
216216

217217
# Nothing should get run if we try it again since everything is passing.
218-
assert mix(["test", "--failed"]) =~ "There are no tests to run"
218+
output = mix(["test", "--failed"])
219+
assert output =~ "No pending --failed tests, re-running all available tests..."
220+
assert output =~ "4 tests, 0 failures"
219221

220222
# `--failed` and `--stale` cannot be combined
221223
output = mix(["test", "--failed", "--stale"])

0 commit comments

Comments
 (0)