Skip to content

Commit c64c54f

Browse files
committed
Removed the need for a default 'test_counter' value
1 parent 4e7a5b1 commit c64c54f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/ex_unit/lib/ex_unit/cli_formatter.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule ExUnit.CLIFormatter do
1919
width: get_terminal_width(),
2020
slowest: opts[:slowest],
2121
slowest_modules: opts[:slowest_modules],
22-
test_counter: %{test: 0},
22+
test_counter: %{},
2323
test_timings: [],
2424
failure_counter: 0,
2525
skipped_counter: 0,
@@ -37,7 +37,7 @@ defmodule ExUnit.CLIFormatter do
3737
def handle_cast({:suite_finished, times_us}, config) do
3838
test_type_counts = collect_test_type_counts(config)
3939

40-
if test_type_counts == 0 && config.excluded_counter > 0 do
40+
if test_type_counts == 0 and config.excluded_counter > 0 do
4141
IO.puts(invalid("All tests have been excluded.", config))
4242
end
4343

@@ -335,8 +335,9 @@ defmodule ExUnit.CLIFormatter do
335335
## Printing
336336

337337
defp print_summary(config, force_failures?) do
338-
formatted_test_type_counts = format_test_type_counts(config)
339338
test_type_counts = collect_test_type_counts(config)
339+
test_counter = test_counter_or_default(config, test_type_counts)
340+
formatted_test_type_counts = format_test_type_counts(test_counter)
340341
failure_pl = pluralize(config.failure_counter, "failure", "failures")
341342

342343
message =
@@ -388,7 +389,7 @@ defmodule ExUnit.CLIFormatter do
388389
IO.puts(formatted)
389390
end
390391

391-
defp format_test_type_counts(%{test_counter: test_counter} = _config) do
392+
defp format_test_type_counts(test_counter) do
392393
test_counter
393394
|> Enum.sort()
394395
|> Enum.map(fn {test_type, count} ->
@@ -398,6 +399,14 @@ defmodule ExUnit.CLIFormatter do
398399
end)
399400
end
400401

402+
defp test_counter_or_default(_config, 0) do
403+
%{test: 0}
404+
end
405+
406+
defp test_counter_or_default(%{test_counter: test_counter} = _config, _test_type_counts) do
407+
test_counter
408+
end
409+
401410
defp collect_test_type_counts(%{test_counter: test_counter} = _config) do
402411
Enum.reduce(test_counter, 0, fn {_, count}, acc ->
403412
acc + count

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule ExUnitTest do
2929
assert capture_io(fn ->
3030
assert ExUnit.async_run() |> ExUnit.await_run() ==
3131
%{failures: 0, skipped: 0, total: 0, excluded: 0}
32-
end) =~ "\n0 failures\n"
32+
end) =~ "\n0 tests, 0 failures\n"
3333
end
3434

3535
test "supports rerunning given modules" do
@@ -137,7 +137,7 @@ defmodule ExUnitTest do
137137
assert result =~ """
138138
Showing results so far...
139139
140-
0 failures
140+
0 tests, 0 failures
141141
"""
142142
end
143143

0 commit comments

Comments
 (0)