@@ -421,8 +421,10 @@ defmodule Mix.Tasks.Test do
421
421
{ :error , { :already_loaded , :ex_unit } } -> :ok
422
422
end
423
423
424
- # Then configure ExUnit again so that command line options
425
- # override test_helper.exs
424
+ # The test helper may change the Mix.shell(), so let's make sure to revert it later
425
+ shell = Mix . shell ( )
426
+
427
+ # Configure ExUnit now and then again so the task options override test_helper.exs
426
428
{ ex_unit_opts , allowed_files } = process_ex_unit_opts ( opts )
427
429
ExUnit . configure ( ex_unit_opts )
428
430
@@ -442,20 +444,21 @@ defmodule Mix.Tasks.Test do
442
444
443
445
display_warn_test_pattern ( test_files , test_pattern , matched_test_files , warn_test_pattern )
444
446
445
- case CT . require_and_run ( matched_test_files , test_paths , opts ) do
447
+ results = CT . require_and_run ( matched_test_files , test_paths , opts )
448
+ Mix . shell ( shell )
449
+
450
+ case results do
446
451
{ :ok , % { excluded: excluded , failures: failures , total: total } } ->
447
452
cover && cover . ( )
448
453
449
- option_only_present? = Keyword . has_key? ( opts , :only )
450
-
451
454
cond do
452
455
failures > 0 and opts [ :raise ] ->
453
456
Mix . raise ( "\" mix test\" failed" )
454
457
455
458
failures > 0 ->
456
459
System . at_exit ( fn _ -> exit ( { :shutdown , 1 } ) end )
457
460
458
- excluded == total and option_only_present? ->
461
+ excluded == total and Keyword . has_key? ( opts , :only ) ->
459
462
message = "The --only option was given to \" mix test\" but no test was executed"
460
463
raise_or_error_at_exit ( message , opts )
461
464
@@ -541,9 +544,15 @@ defmodule Mix.Tasks.Test do
541
544
end
542
545
543
546
defp merge_helper_opts ( opts ) do
547
+ # The only options that are additive from app env are the excludes
544
548
merge_opts ( opts , :exclude )
545
549
end
546
550
551
+ defp merge_opts ( opts , key ) do
552
+ value = List . wrap ( Application . get_env ( :ex_unit , key , [ ] ) )
553
+ Keyword . update ( opts , key , value , & Enum . uniq ( & 1 ++ value ) )
554
+ end
555
+
547
556
defp default_opts ( opts ) do
548
557
# Set autorun to false because Mix
549
558
# automatically runs the test suite for us.
@@ -643,11 +652,6 @@ defmodule Mix.Tasks.Test do
643
652
end
644
653
end
645
654
646
- defp merge_opts ( opts , key ) do
647
- value = List . wrap ( Application . get_env ( :ex_unit , key , [ ] ) )
648
- Keyword . update ( opts , key , value , & Enum . uniq ( & 1 ++ value ) )
649
- end
650
-
651
655
defp require_test_helper ( dir ) do
652
656
file = Path . join ( dir , "test_helper.exs" )
653
657
0 commit comments