@@ -473,6 +473,7 @@ defmodule Mix.Tasks.Test do
473
473
@ impl true
474
474
def run ( args ) do
475
475
{ opts , files } = OptionParser . parse! ( args , strict: @ switches , aliases: [ b: :breakpoints ] )
476
+ opts = put_manifest_file ( opts )
476
477
477
478
if not Mix.Task . recursing? ( ) do
478
479
do_run ( opts , args , files )
@@ -591,30 +592,31 @@ defmodule Mix.Tasks.Test do
591
592
{ ex_unit_opts , allowed_files } = process_ex_unit_opts ( opts )
592
593
ExUnit . configure ( ex_unit_opts )
593
594
595
+ # Prepare and extract all files to require and run
594
596
test_paths = project [ :test_paths ] || default_test_paths ( )
595
- Enum . each ( test_paths , & require_test_helper ( shell , & 1 ) )
596
- ExUnit . configure ( merge_helper_opts ( ex_unit_opts ) )
597
-
598
- # Finally parse, require and load the files
599
597
test_files = if files != [ ] , do: parse_file_paths ( files ) , else: test_paths
600
598
test_pattern = project [ :test_pattern ] || "*_test.exs"
601
599
warn_test_pattern = project [ :warn_test_pattern ] || "*_test.ex"
602
-
603
- files_with_matched_path = Mix.Utils . extract_files ( test_files , test_pattern )
600
+ unfiltered_test_files = Mix.Utils . extract_files ( test_files , test_pattern )
604
601
605
602
matched_test_files =
606
- files_with_matched_path
603
+ unfiltered_test_files
607
604
|> filter_to_allowed_files ( allowed_files )
608
605
|> filter_by_partition ( shell , partitions )
609
606
610
- display_warn_test_pattern (
611
- test_files ,
612
- test_pattern ,
613
- files_with_matched_path ,
614
- warn_test_pattern
615
- )
616
-
617
- case CT . require_and_run ( matched_test_files , test_paths , test_elixirc_options , opts ) do
607
+ display_warn_test_pattern ( test_files , test_pattern , unfiltered_test_files , warn_test_pattern )
608
+
609
+ try do
610
+ Enum . each ( test_paths , & require_test_helper ( shell , & 1 ) )
611
+ ExUnit . configure ( merge_helper_opts ( ex_unit_opts ) )
612
+ CT . require_and_run ( matched_test_files , test_paths , test_elixirc_options , opts )
613
+ catch
614
+ kind , reason ->
615
+ # Also mark the whole suite as failed
616
+ file = Keyword . fetch! ( opts , :failures_manifest_path )
617
+ ExUnit.Filters . fail_all! ( file )
618
+ :erlang . raise ( kind , reason , __STACKTRACE__ )
619
+ else
618
620
{ :ok , % { excluded: excluded , failures: failures , total: total } } ->
619
621
Mix . shell ( shell )
620
622
cover && cover . ( )
@@ -776,23 +778,29 @@ defmodule Mix.Tasks.Test do
776
778
777
779
@ manifest_file_name ".mix_test_failures"
778
780
779
- defp manifest_opts ( opts ) do
780
- opts =
781
- Keyword . put_new (
782
- opts ,
783
- :failures_manifest_path ,
784
- Path . join ( Mix.Project . manifest_path ( ) , @ manifest_file_name )
785
- )
781
+ defp put_manifest_file ( opts ) do
782
+ Keyword . put_new_lazy (
783
+ opts ,
784
+ :failures_manifest_path ,
785
+ fn -> Path . join ( Mix.Project . manifest_path ( ) , @ manifest_file_name ) end
786
+ )
787
+ end
786
788
787
- manifest_file = Keyword . get ( opts , :failures_manifest_path )
789
+ defp manifest_opts ( opts ) do
790
+ manifest_file = Keyword . fetch! ( opts , :failures_manifest_path )
788
791
789
792
if opts [ :failed ] do
790
793
if opts [ :stale ] do
791
794
Mix . raise ( "Combining --failed and --stale is not supported." )
792
795
end
793
796
794
- { allowed_files , failed_ids } = ExUnit.Filters . failure_info ( manifest_file )
795
- { Keyword . put ( opts , :only_test_ids , failed_ids ) , allowed_files }
797
+ case ExUnit.Filters . failure_info ( manifest_file ) do
798
+ { allowed_files , failed_ids } ->
799
+ { Keyword . put ( opts , :only_test_ids , failed_ids ) , allowed_files }
800
+
801
+ :all ->
802
+ { opts , nil }
803
+ end
796
804
else
797
805
{ opts , nil }
798
806
end
0 commit comments