Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/mix/lib/mix/tasks/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,16 @@ defmodule Mix.Tasks.Test do
exit({:shutdown, 1})
end)

total == 0 and opts[:failed] ->
message =
"\nERROR! Unable to find failed tests while using the --failed option"

IO.puts(:stderr, IO.ANSI.format([:red, message]))

System.at_exit(fn _ ->
exit({:shutdown, 1})
end)

failures > 0 and opts[:raise] ->
raise_with_shell(shell, "\"mix test\" failed")

Expand Down
11 changes: 11 additions & 0 deletions lib/mix/test/fixtures/test_not_found/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule TestFailed.MixProject do
use Mix.Project

def project do
[
app: :test_not_found,
version: "0.0.1",
test_load_filters: [~r/.*_test_failed\.exs/]
]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defmodule OnlyFailingTest do
use ExUnit.Case

test "test number #{:random.uniform()} failed at #{DateTime.utc_now()}",
do: assert(System.get_env("PASS_FAILING_TESTS"))
end
1 change: 1 addition & 0 deletions lib/mix/test/fixtures/test_not_found/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
15 changes: 15 additions & 0 deletions lib/mix/test/mix/tasks/test_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,21 @@ defmodule Mix.Tasks.TestTest do
assert output =~ "** (RuntimeError) oops"
end)
end

test "fail with exit status 1 if failed tests cannot be found" do
in_fixture("test_not_found", fn ->
output = mix(["test", "--failed"])
assert output =~ "There are no tests to run"

# Run `mix test` once to record failures...
output = mix(["test"])
assert output =~ "1 test, 1 failure"

{output, exit_status} = mix_code(["test", "--failed"])
assert output =~ "ERROR! Unable to find failed tests while using the --failed option"
assert exit_status == 1
end)
end
end

describe "--listen-on-stdin" do
Expand Down