Skip to content

Commit

Permalink
Document and ensure invalid tests have proper formatter state, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 27, 2024
1 parent d2276d8 commit fc90206
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/ex_unit/lib/ex_unit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ defmodule ExUnit do
"""
@type state ::
nil | {:excluded, binary} | {:failed, failed} | {:invalid, module} | {:skipped, binary}
nil
| {:excluded, binary}
| {:failed, failed}
| {:invalid, ExUnit.TestModule.t()}
| {:skipped, binary}

@typedoc "The error state returned by `ExUnit.Test` and `ExUnit.TestModule`"
@type failed :: [{Exception.kind(), reason :: term, Exception.stacktrace()}]
Expand Down
12 changes: 9 additions & 3 deletions lib/ex_unit/lib/ex_unit/cli_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule ExUnit.CLIFormatter do
{:noreply, update_test_timings(config, test)}
end

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

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

def handle_cast({:test_finished, %ExUnit.Test{state: {:skipped, _}} = test}, config) do
def handle_cast({:test_finished, %ExUnit.Test{state: {:skipped, reason}} = test}, config)
when is_binary(reason) do
if config.trace do
IO.puts(skipped(trace_test_skipped(test), config))
else
Expand All @@ -87,7 +89,11 @@ defmodule ExUnit.CLIFormatter do
{:noreply, config}
end

def handle_cast({:test_finished, %ExUnit.Test{state: {:invalid, _}} = test}, config) do
def handle_cast(
{:test_finished,
%ExUnit.Test{state: {:invalid, %ExUnit.TestModule{state: {:failed, _}}}} = test},
config
) do
if config.trace do
IO.puts(invalid(trace_test_result(test), config))
else
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_unit/lib/ex_unit/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ defmodule ExUnit.Runner do
{test_module, invalid_tests, []}

{:DOWN, ^module_ref, :process, ^module_pid, error} ->
invalid_tests = mark_tests_invalid(tests, test_module)
test_module = %{test_module | state: failed({:EXIT, module_pid}, error, [])}
invalid_tests = mark_tests_invalid(tests, test_module)
{test_module, invalid_tests, []}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ex_unit/test/ex_unit/failures_manifest_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ExUnit.FailuresManifestTest do
@skipped {:skipped, "reason"}
@excluded {:excluded, "reason"}
@failed {:failed, []}
@invalid {:invalid, SomeMod}
@invalid {:invalid, %ExUnit.TestModule{}}

describe "files_with_failures/1" do
test "returns the set of files with failures" do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_unit/test/ex_unit/runner_stats_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ defmodule ExUnit.RunnerStatsTest do

defp state_for(:passed), do: nil
defp state_for(:failed), do: {:failed, []}
defp state_for(:invalid), do: {:invalid, TestModule}
defp state_for(:invalid), do: {:invalid, %ExUnit.TestModule{}}
defp state_for(:skipped), do: {:skipped, "reason"}
defp state_for(:excluded), do: {:excluded, "reason"}

Expand Down

0 comments on commit fc90206

Please sign in to comment.