diff --git a/lib/ex_unit/lib/ex_unit/cli_formatter.ex b/lib/ex_unit/lib/ex_unit/cli_formatter.ex index cfe335a080..fda793e7ad 100644 --- a/lib/ex_unit/lib/ex_unit/cli_formatter.ex +++ b/lib/ex_unit/lib/ex_unit/cli_formatter.ex @@ -37,7 +37,7 @@ defmodule ExUnit.CLIFormatter do def handle_cast({:suite_finished, times_us}, config) do test_type_counts = collect_test_type_counts(config) - if test_type_counts > 0 && config.excluded_counter == test_type_counts do + if test_type_counts == 0 and config.excluded_counter > 0 do IO.puts(invalid("All tests have been excluded.", config)) end @@ -256,6 +256,10 @@ defmodule ExUnit.CLIFormatter do end end + defp update_test_counter(test_counter, %{state: {:excluded, _reason}}) do + test_counter + end + defp update_test_counter(test_counter, %{tags: %{test_type: test_type}}) do Map.update(test_counter, test_type, 1, &(&1 + 1)) end @@ -331,16 +335,13 @@ defmodule ExUnit.CLIFormatter do ## Printing defp print_summary(config, force_failures?) do - formatted_test_type_counts = format_test_type_counts(config) test_type_counts = collect_test_type_counts(config) + test_counter = test_counter_or_default(config, test_type_counts) + formatted_test_type_counts = format_test_type_counts(test_counter) failure_pl = pluralize(config.failure_counter, "failure", "failures") message = "#{formatted_test_type_counts}#{config.failure_counter} #{failure_pl}" - |> if_true( - config.excluded_counter > 0, - &(&1 <> ", #{config.excluded_counter} excluded") - ) |> if_true( config.invalid_counter > 0, &(&1 <> ", #{config.invalid_counter} invalid") @@ -349,6 +350,10 @@ defmodule ExUnit.CLIFormatter do config.skipped_counter > 0, &(&1 <> ", " <> skipped("#{config.skipped_counter} skipped", config)) ) + |> if_true( + config.excluded_counter > 0, + &(&1 <> " (#{config.excluded_counter} excluded)") + ) cond do config.failure_counter > 0 or force_failures? -> @@ -384,15 +389,24 @@ defmodule ExUnit.CLIFormatter do IO.puts(formatted) end - defp format_test_type_counts(%{test_counter: test_counter} = _config) do + defp format_test_type_counts(test_counter) do test_counter |> Enum.sort() |> Enum.map(fn {test_type, count} -> type_pluralized = pluralize(count, test_type, ExUnit.plural_rule(test_type |> to_string())) + "#{count} #{type_pluralized}, " end) end + defp test_counter_or_default(_config, 0) do + %{test: 0} + end + + defp test_counter_or_default(%{test_counter: test_counter} = _config, _test_type_counts) do + test_counter + end + defp collect_test_type_counts(%{test_counter: test_counter} = _config) do Enum.reduce(test_counter, 0, fn {_, count}, acc -> acc + count diff --git a/lib/ex_unit/test/ex_unit_test.exs b/lib/ex_unit/test/ex_unit_test.exs index 152a9122f7..37da768739 100644 --- a/lib/ex_unit/test/ex_unit_test.exs +++ b/lib/ex_unit/test/ex_unit_test.exs @@ -29,7 +29,7 @@ defmodule ExUnitTest do assert capture_io(fn -> assert ExUnit.async_run() |> ExUnit.await_run() == %{failures: 0, skipped: 0, total: 0, excluded: 0} - end) =~ "\n0 failures\n" + end) =~ "\n0 tests, 0 failures\n" end test "supports rerunning given modules" do @@ -137,7 +137,7 @@ defmodule ExUnitTest do assert result =~ """ Showing results so far... - 0 failures + 0 tests, 0 failures """ end @@ -331,19 +331,19 @@ defmodule ExUnitTest do {result, output} = run_with_filter([exclude: [even: true]], [ParityTest]) assert result == %{failures: 0, skipped: 0, excluded: 1, total: 4} - assert output =~ "\n4 tests, 0 failures, 1 excluded\n" + assert output =~ "\n3 tests, 0 failures (1 excluded)\n" {result, output} = run_with_filter([exclude: :even], [ParityTest]) assert result == %{failures: 0, skipped: 0, excluded: 3, total: 4} - assert output =~ "\n4 tests, 0 failures, 3 excluded\n" + assert output =~ "\n1 test, 0 failures (3 excluded)\n" {result, output} = run_with_filter([exclude: :even, include: [even: true]], [ParityTest]) assert result == %{failures: 1, skipped: 0, excluded: 2, total: 4} - assert output =~ "\n4 tests, 1 failure, 2 excluded\n" + assert output =~ "\n2 tests, 1 failure (2 excluded)\n" {result, output} = run_with_filter([exclude: :test, include: [even: true]], [ParityTest]) assert result == %{failures: 1, skipped: 0, excluded: 3, total: 4} - assert output =~ "\n4 tests, 1 failure, 3 excluded\n" + assert output =~ "\n1 test, 1 failure (3 excluded)\n" end test "log capturing" do @@ -508,8 +508,9 @@ defmodule ExUnitTest do # Empty because it is already loaded {result, output} = run_with_filter([exclude: :module], []) + assert result == %{failures: 0, skipped: 0, excluded: 2, total: 2} - assert output =~ "\n2 tests, 0 failures, 2 excluded\n" + assert output =~ "\n0 tests, 0 failures (2 excluded)\n" {result, output} = [exclude: :test, include: [module: "ExUnitTest.SecondTestModule"]] @@ -517,7 +518,7 @@ defmodule ExUnitTest do assert result == %{failures: 1, skipped: 0, excluded: 1, total: 2} assert output =~ "\n 1) test false (ExUnitTest.SecondTestModule)\n" - assert output =~ "\n2 tests, 1 failure, 1 excluded\n" + assert output =~ "\n1 test, 1 failure (1 excluded)\n" end test "raises on reserved tag :file in module" do @@ -680,7 +681,7 @@ defmodule ExUnitTest do end) refute output =~ max_failures_reached_msg() - assert output =~ "\n6 tests, 0 failures, 1 excluded, 4 invalid, 1 skipped\n" + assert output =~ "\n5 tests, 0 failures, 4 invalid, 1 skipped (1 excluded)\n" end test "parameterized tests" do @@ -787,7 +788,7 @@ defmodule ExUnitTest do end) assert output =~ max_failures_reached_msg() - assert output =~ "\n6 tests, 2 failures, 1 excluded, 1 skipped\n" + assert output =~ "\n5 tests, 2 failures, 1 skipped (1 excluded)\n" end test ":max_failures is not reached" do @@ -818,7 +819,7 @@ defmodule ExUnitTest do end) refute output =~ max_failures_reached_msg() - assert output =~ "\n8 tests, 2 failures, 2 excluded, 1 skipped\n" + assert output =~ "\n6 tests, 2 failures, 1 skipped (2 excluded)\n" end test ":max_failures has been reached" do @@ -852,7 +853,7 @@ defmodule ExUnitTest do end) assert output =~ max_failures_reached_msg() - assert output =~ "\n7 tests, 2 failures, 2 excluded, 2 skipped\n" + assert output =~ "\n5 tests, 2 failures, 2 skipped (2 excluded)\n" end # Excluded and skipped tests are detected before setup_all @@ -886,7 +887,7 @@ defmodule ExUnitTest do end) assert output =~ max_failures_reached_msg() - assert output =~ "\n4 tests, 0 failures, 1 excluded, 2 invalid, 1 skipped\n" + assert output =~ "\n3 tests, 0 failures, 2 invalid, 1 skipped (1 excluded)\n" end test ":max_failures flushes all async/sync cases" do @@ -1077,7 +1078,7 @@ defmodule ExUnitTest do end) assert output =~ "All tests have been excluded.\n" - assert output =~ "2 tests, 0 failures, 2 excluded\n" + assert output =~ "0 tests, 0 failures (2 excluded)\n" end test "tests are run in compile order (FIFO)" do diff --git a/lib/mix/test/mix/tasks/test_test.exs b/lib/mix/test/mix/tasks/test_test.exs index b51ed680db..d3d73af2c0 100644 --- a/lib/mix/test/mix/tasks/test_test.exs +++ b/lib/mix/test/mix/tasks/test_test.exs @@ -238,7 +238,7 @@ defmodule Mix.Tasks.TestTest do # Of the passing tests, 1 is tagged with `@tag :foo`. # But only the failing test with that tag should run. output = mix(["test", "--failed", "--only", "foo"]) - assert output =~ "2 tests, 1 failure, 1 excluded" + assert output =~ "1 test, 1 failure (1 excluded)" # Run again to give it a chance to record as passed System.put_env("PASS_FAILING_TESTS", "true") @@ -548,7 +548,7 @@ defmodule Mix.Tasks.TestTest do Including tags: [location: {"test/bar_tests.exs", 5}] """ - assert output =~ "4 tests, 0 failures, 3 excluded\n" + assert output =~ "1 test, 0 failures (3 excluded)\n" end) end end