Skip to content

Commit 4e7a5b1

Browse files
committed
Refactored based on feedback
1 parent 76bff37 commit 4e7a5b1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/ex_unit/lib/ex_unit/cli_formatter.ex

Lines changed: 10 additions & 11 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: %{},
22+
test_counter: %{test: 0},
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 == test_type_counts do
40+
if test_type_counts == 0 && config.excluded_counter > 0 do
4141
IO.puts(invalid("All tests have been excluded.", config))
4242
end
4343

@@ -256,6 +256,10 @@ defmodule ExUnit.CLIFormatter do
256256
end
257257
end
258258

259+
defp update_test_counter(test_counter, %{state: {:excluded, _reason}}) do
260+
test_counter
261+
end
262+
259263
defp update_test_counter(test_counter, %{tags: %{test_type: test_type}}) do
260264
Map.update(test_counter, test_type, 1, &(&1 + 1))
261265
end
@@ -384,21 +388,16 @@ defmodule ExUnit.CLIFormatter do
384388
IO.puts(formatted)
385389
end
386390

387-
defp format_test_type_counts(config) do
388-
config.test_counter
391+
defp format_test_type_counts(%{test_counter: test_counter} = _config) do
392+
test_counter
389393
|> Enum.sort()
390394
|> Enum.map(fn {test_type, count} ->
391-
executed_count = calculate_executed_test_count(test_type, count, config.excluded_counter)
392-
plural_rule = ExUnit.plural_rule(test_type |> to_string())
393-
type_pluralized = pluralize(executed_count, test_type, plural_rule)
395+
type_pluralized = pluralize(count, test_type, ExUnit.plural_rule(test_type |> to_string()))
394396

395-
"#{executed_count} #{type_pluralized}, "
397+
"#{count} #{type_pluralized}, "
396398
end)
397399
end
398400

399-
defp calculate_executed_test_count(:test, count, excluded_counter), do: count - excluded_counter
400-
defp calculate_executed_test_count(_test_type, count, _excluded_counter), do: count
401-
402401
defp collect_test_type_counts(%{test_counter: test_counter} = _config) do
403402
Enum.reduce(test_counter, 0, fn {_, count}, acc ->
404403
acc + count

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ defmodule ExUnitTest do
508508

509509
# Empty because it is already loaded
510510
{result, output} = run_with_filter([exclude: :module], [])
511+
511512
assert result == %{failures: 0, skipped: 0, excluded: 2, total: 2}
512513
assert output =~ "\n0 tests, 0 failures, 2 excluded\n"
513514

0 commit comments

Comments
 (0)