Skip to content

Commit fc90206

Browse files
committed
Document and ensure invalid tests have proper formatter state, closes #13373
1 parent d2276d8 commit fc90206

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

lib/ex_unit/lib/ex_unit.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ defmodule ExUnit do
7070
7171
"""
7272
@type state ::
73-
nil | {:excluded, binary} | {:failed, failed} | {:invalid, module} | {:skipped, binary}
73+
nil
74+
| {:excluded, binary}
75+
| {:failed, failed}
76+
| {:invalid, ExUnit.TestModule.t()}
77+
| {:skipped, binary}
7478

7579
@typedoc "The error state returned by `ExUnit.Test` and `ExUnit.TestModule`"
7680
@type failed :: [{Exception.kind(), reason :: term, Exception.stacktrace()}]

lib/ex_unit/lib/ex_unit/cli_formatter.ex

+9-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ defmodule ExUnit.CLIFormatter do
6565
{:noreply, update_test_timings(config, test)}
6666
end
6767

68-
def handle_cast({:test_finished, %ExUnit.Test{state: {:excluded, _}} = test}, config) do
68+
def handle_cast({:test_finished, %ExUnit.Test{state: {:excluded, reason}} = test}, config)
69+
when is_binary(reason) do
6970
if config.trace, do: IO.puts(trace_test_excluded(test))
7071

7172
test_counter = update_test_counter(config.test_counter, test)
@@ -74,7 +75,8 @@ defmodule ExUnit.CLIFormatter do
7475
{:noreply, config}
7576
end
7677

77-
def handle_cast({:test_finished, %ExUnit.Test{state: {:skipped, _}} = test}, config) do
78+
def handle_cast({:test_finished, %ExUnit.Test{state: {:skipped, reason}} = test}, config)
79+
when is_binary(reason) do
7880
if config.trace do
7981
IO.puts(skipped(trace_test_skipped(test), config))
8082
else
@@ -87,7 +89,11 @@ defmodule ExUnit.CLIFormatter do
8789
{:noreply, config}
8890
end
8991

90-
def handle_cast({:test_finished, %ExUnit.Test{state: {:invalid, _}} = test}, config) do
92+
def handle_cast(
93+
{:test_finished,
94+
%ExUnit.Test{state: {:invalid, %ExUnit.TestModule{state: {:failed, _}}}} = test},
95+
config
96+
) do
9197
if config.trace do
9298
IO.puts(invalid(trace_test_result(test), config))
9399
else

lib/ex_unit/lib/ex_unit/runner.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ defmodule ExUnit.Runner do
293293
{test_module, invalid_tests, []}
294294

295295
{:DOWN, ^module_ref, :process, ^module_pid, error} ->
296-
invalid_tests = mark_tests_invalid(tests, test_module)
297296
test_module = %{test_module | state: failed({:EXIT, module_pid}, error, [])}
297+
invalid_tests = mark_tests_invalid(tests, test_module)
298298
{test_module, invalid_tests, []}
299299
end
300300

lib/ex_unit/test/ex_unit/failures_manifest_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule ExUnit.FailuresManifestTest do
99
@skipped {:skipped, "reason"}
1010
@excluded {:excluded, "reason"}
1111
@failed {:failed, []}
12-
@invalid {:invalid, SomeMod}
12+
@invalid {:invalid, %ExUnit.TestModule{}}
1313

1414
describe "files_with_failures/1" do
1515
test "returns the set of files with failures" do

lib/ex_unit/test/ex_unit/runner_stats_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ defmodule ExUnit.RunnerStatsTest do
159159

160160
defp state_for(:passed), do: nil
161161
defp state_for(:failed), do: {:failed, []}
162-
defp state_for(:invalid), do: {:invalid, TestModule}
162+
defp state_for(:invalid), do: {:invalid, %ExUnit.TestModule{}}
163163
defp state_for(:skipped), do: {:skipped, "reason"}
164164
defp state_for(:excluded), do: {:excluded, "reason"}
165165

0 commit comments

Comments
 (0)