@@ -43,9 +43,9 @@ defmodule ExUnit.CLIFormatter do
4343 end
4444
4545 def handle_cast ( { :suite_finished , times_us } , config ) do
46- test_type_counts = collect_test_type_counts ( config )
46+ test_counter = collect_test_counter ( config )
4747
48- if test_type_counts == 0 and config . excluded_counter > 0 do
48+ if test_counter == 0 and config . excluded_counter > 0 do
4949 IO . puts ( invalid ( "All tests have been excluded." , config ) )
5050 end
5151
@@ -83,10 +83,7 @@ defmodule ExUnit.CLIFormatter do
8383 def handle_cast ( { :test_finished , % ExUnit.Test { state: { :excluded , reason } } = test } , config )
8484 when is_binary ( reason ) do
8585 if config . trace , do: IO . puts ( trace_test_excluded ( test ) )
86-
87- test_counter = update_test_counter ( config . test_counter , test )
88- config = % { config | test_counter: test_counter , excluded_counter: config . excluded_counter + 1 }
89-
86+ config = % { config | excluded_counter: config . excluded_counter + 1 }
9087 { :noreply , config }
9188 end
9289
@@ -98,10 +95,7 @@ defmodule ExUnit.CLIFormatter do
9895 IO . write ( skipped ( "*" , config ) )
9996 end
10097
101- test_counter = update_test_counter ( config . test_counter , test )
102- config = % { config | test_counter: test_counter , skipped_counter: config . skipped_counter + 1 }
103-
104- { :noreply , config }
98+ { :noreply , % { config | skipped_counter: config . skipped_counter + 1 } }
10599 end
106100
107101 def handle_cast (
@@ -115,10 +109,7 @@ defmodule ExUnit.CLIFormatter do
115109 IO . write ( invalid ( "?" , config ) )
116110 end
117111
118- test_counter = update_test_counter ( config . test_counter , test )
119- config = % { config | test_counter: test_counter , invalid_counter: config . invalid_counter + 1 }
120-
121- { :noreply , config }
112+ { :noreply , % { config | invalid_counter: config . invalid_counter + 1 } }
122113 end
123114
124115 def handle_cast ( { :test_finished , % ExUnit.Test { state: { :failed , failures } } = test } , config ) do
@@ -287,10 +278,6 @@ defmodule ExUnit.CLIFormatter do
287278 end
288279 end
289280
290- defp update_test_counter ( test_counter , % { state: { :excluded , _reason } } ) do
291- test_counter
292- end
293-
294281 defp update_test_counter ( test_counter , % { tags: % { test_type: test_type } } ) do
295282 Map . update ( test_counter , test_type , 1 , & ( & 1 + 1 ) )
296283 end
@@ -366,26 +353,22 @@ defmodule ExUnit.CLIFormatter do
366353 ## Printing
367354
368355 defp print_summary ( config , force_failures? ) do
369- test_type_counts = collect_test_type_counts ( config )
370- test_counter = test_counter_or_default ( config , test_type_counts )
371-
372- passed_total =
373- test_type_counts - config . failure_counter - config . skipped_counter - config . invalid_counter
356+ test_counter = collect_test_counter ( config )
357+ passed_counter = test_counter - config . failure_counter
374358
375- # Passed line: "Passed : 447/455 (53/54 doctests, 393/403 tests)" or
376- # "Passed : 455 (70 tests, 14 properties)" when all pass
377- all_passed? = passed_total == test_type_counts
359+ # Passed line: "Result : 447/455 passed (53/54 doctests, 393/403 tests)" or
360+ # "Result : 455 passed (70 tests, 14 properties)" when all pass
361+ all_passed? = config . failure_counter == 0
378362
379363 passed_breakdown =
380- format_passed_breakdown ( test_counter , config . failure_type_counter , all_passed? )
364+ format_passed_breakdown ( config . test_counter , config . failure_type_counter , all_passed? )
381365
382366 passed_line =
383- if all_passed? do
384- "Passed: #{ passed_total } "
385- else
386- "Passed: #{ passed_total } /#{ test_type_counts } "
387- end
388- |> if_true ( passed_breakdown != "" , & ( & 1 <> " (#{ passed_breakdown } )" ) )
367+ cond do
368+ test_counter == 0 -> "Result: 0 tests"
369+ all_passed? -> "Result: #{ passed_counter } passed"
370+ true -> "Result: #{ passed_counter } /#{ test_counter } passed"
371+ end <> passed_breakdown
389372
390373 # Failed line: "Failed: 8 tests, 1 property"
391374 failed_line =
@@ -408,7 +391,7 @@ defmodule ExUnit.CLIFormatter do
408391 )
409392 |> if_true (
410393 config . excluded_counter > 0 ,
411- & ( & 1 <> " ( #{ config . excluded_counter } excluded) " )
394+ & ( & 1 <> ", #{ config . excluded_counter } excluded" )
412395 )
413396
414397 cond do
@@ -418,7 +401,7 @@ defmodule ExUnit.CLIFormatter do
418401 config . invalid_counter > 0 ->
419402 IO . puts ( invalid ( message , config ) )
420403
421- test_type_counts > 0 && config . excluded_counter == test_type_counts ->
404+ test_counter > 0 && config . excluded_counter == test_counter ->
422405 IO . puts ( invalid ( message , config ) )
423406
424407 true ->
@@ -455,41 +438,35 @@ defmodule ExUnit.CLIFormatter do
455438 end
456439
457440 defp format_passed_breakdown ( test_counter , failure_type_counter , all_passed? ) do
458- # If there are no different test types, we just print "Passed: N/N"
459- # without the type.
441+ # If there are no different test types, we just print "Result: N/N passed" without the type.
460442 if map_size ( test_counter ) in 0 .. 1 do
461443 ""
462444 else
463- test_counter
464- |> Map . keys ( )
465- |> Enum . sort ( )
466- |> Enum . map_join ( ", " , fn type ->
467- total = Map . fetch! ( test_counter , type )
468-
469- if all_passed? do
470- "#{ total } #{ pluralize_type ( total , type ) } "
471- else
472- failed = Map . get ( failure_type_counter , type , 0 )
473- passed = total - failed
474- "#{ passed } /#{ total } #{ pluralize_type ( total , type ) } "
475- end
476- end )
445+ entries =
446+ test_counter
447+ |> Map . keys ( )
448+ |> Enum . sort ( )
449+ |> Enum . map_join ( ", " , fn type ->
450+ total = Map . fetch! ( test_counter , type )
451+
452+ if all_passed? do
453+ "#{ total } #{ pluralize_type ( total , type ) } "
454+ else
455+ failed = Map . get ( failure_type_counter , type , 0 )
456+ passed = total - failed
457+ "#{ passed } /#{ total } #{ pluralize_type ( total , type ) } "
458+ end
459+ end )
460+
461+ " (" <> entries <> ")"
477462 end
478463 end
479464
480465 defp pluralize_type ( count , type ) do
481466 pluralize ( count , type , ExUnit . plural_rule ( to_string ( type ) ) )
482467 end
483468
484- defp test_counter_or_default ( _config , 0 ) do
485- % { test: 0 }
486- end
487-
488- defp test_counter_or_default ( % { test_counter: test_counter } = _config , _test_type_counts ) do
489- test_counter
490- end
491-
492- defp collect_test_type_counts ( % { test_counter: test_counter } = _config ) do
469+ defp collect_test_counter ( % { test_counter: test_counter } = _config ) do
493470 Enum . reduce ( test_counter , 0 , fn { _ , count } , acc ->
494471 acc + count
495472 end )
0 commit comments