@@ -121,9 +121,9 @@ defmodule Mix.Tasks.Test do
121121
122122 * `--cover` - runs coverage tool. See "Coverage" section below
123123
124- * `--dry-run` - prints which tests would be run based on current options,
124+ * `--dry-run` *(since v1.19.0)* - prints which tests would be run based on current options,
125125 but does not actually run any tests. This combines with all other options
126- like `--stale`, `--only`, `--exclude`, etc .
126+ like `--stale`, `--only`, `--exclude`, and so on .
127127
128128 * `--exclude` - excludes tests that match the filter. This option may be given
129129 several times to apply different filters, such as `--exclude ci --exclude slow`
@@ -628,7 +628,6 @@ defmodule Mix.Tasks.Test do
628628
629629 warnings_as_errors? = Keyword . get ( opts , :warnings_as_errors , false )
630630 exit_status = Keyword . fetch! ( ex_unit_opts , :exit_status )
631- dry_run? = Keyword . get ( opts , :dry_run , false )
632631
633632 # Prepare and extract all files to require and run
634633 test_paths = project [ :test_paths ] || default_test_paths ( )
@@ -665,115 +664,69 @@ defmodule Mix.Tasks.Test do
665664
666665 warn_files != [ ] && warn_misnamed_test_files ( warn_files )
667666
668- if dry_run? do
669- do_dry_run ( matched_test_files )
667+ try do
668+ Enum . each ( test_paths , & require_test_helper ( shell , & 1 ) )
669+ # test_opts always wins because those are given via args
670+ ExUnit . configure ( ex_unit_opts |> merge_helper_opts ( ) |> Keyword . merge ( test_opts ) )
671+ CT . require_and_run ( matched_test_files , test_paths , test_elixirc_options , opts )
672+ catch
673+ kind , reason ->
674+ # Also mark the whole suite as failed
675+ file = Keyword . fetch! ( opts , :failures_manifest_path )
676+ ExUnit.Filters . fail_all! ( file )
677+ :erlang . raise ( kind , reason , __STACKTRACE__ )
670678 else
671- do_wet_run (
672- shell ,
673- cover ,
674- test_paths ,
675- files ,
676- matched_test_files ,
677- test_opts ,
678- test_elixirc_options ,
679- ex_unit_opts ,
680- warnings_as_errors? ,
681- exit_status ,
682- opts
683- )
684- end
685- end
679+ { :ok , % { excluded: excluded , failures: failures , warnings?: warnings? , total: total } } ->
680+ Mix . shell ( shell )
681+ cover && cover . ( )
686682
687- defp do_dry_run ( matched_test_files ) do
688- if matched_test_files == [ ] do
689- Mix . shell ( ) . info ( """
690- -- DRY RUN --
691- No tests would run
692- """ )
693- else
694- Mix . shell ( ) . info ( """
695- -- DRY RUN --
696- The following test files would be run:
683+ cond do
684+ warnings_as_errors? and warnings? and failures == 0 ->
685+ message =
686+ "\n ERROR! Test suite aborted after successful execution due to warnings while using the --warnings-as-errors option"
697687
698- #{ Enum . join ( matched_test_files , "\n " ) }
699- """ )
700- end
701- end
688+ IO . puts ( :stderr , IO.ANSI . format ( [ :red , message ] ) )
702689
703- defp do_wet_run (
704- shell ,
705- cover ,
706- test_paths ,
707- files ,
708- matched_test_files ,
709- test_opts ,
710- test_elixirc_options ,
711- ex_unit_opts ,
712- warnings_as_errors? ,
713- exit_status ,
714- opts
715- ) do
716- Enum . each ( test_paths , & require_test_helper ( shell , & 1 ) )
717- # test_opts always wins because those are given via args
718- ExUnit . configure ( ex_unit_opts |> merge_helper_opts ( ) |> Keyword . merge ( test_opts ) )
719- CT . require_and_run ( matched_test_files , test_paths , test_elixirc_options , opts )
720- catch
721- kind , reason ->
722- # Also mark the whole suite as failed
723- file = Keyword . fetch! ( opts , :failures_manifest_path )
724- ExUnit.Filters . fail_all! ( file )
725- :erlang . raise ( kind , reason , __STACKTRACE__ )
726- else
727- { :ok , % { excluded: excluded , failures: failures , warnings?: warnings? , total: total } } ->
728- Mix . shell ( shell )
729- cover && cover . ( )
690+ System . at_exit ( fn _ ->
691+ exit ( { :shutdown , 1 } )
692+ end )
730693
731- cond do
732- warnings_as_errors? and warnings? and failures == 0 ->
733- message =
734- "\n ERROR! Test suite aborted after successful execution due to warnings while using the --warnings-as-errors option"
735-
736- IO . puts ( :stderr , IO.ANSI . format ( [ :red , message ] ) )
737-
738- System . at_exit ( fn _ ->
739- exit ( { :shutdown , 1 } )
740- end )
694+ failures > 0 and opts [ :raise ] ->
695+ raise_with_shell ( shell , "\" mix test\" failed" )
741696
742- failures > 0 and opts [ :raise ] ->
743- raise_with_shell ( shell , "\" mix test\" failed" )
697+ warnings_as_errors? and warnings? and failures > 0 ->
698+ System . at_exit ( fn _ ->
699+ exit ( { :shutdown , exit_status + 1 } )
700+ end )
744701
745- warnings_as_errors? and warnings? and failures > 0 ->
746- System . at_exit ( fn _ ->
747- exit ( { :shutdown , exit_status + 1 } )
748- end )
702+ failures > 0 ->
703+ System . at_exit ( fn _ ->
704+ exit ( { :shutdown , exit_status } )
705+ end )
749706
750- failures > 0 ->
751- System . at_exit ( fn _ ->
752- exit ( { :shutdown , exit_status } )
753- end )
707+ excluded == total and Keyword . has_key? ( opts , :only ) ->
708+ message = "The --only option was given to \" mix test\" but no test was executed"
709+ raise_or_error_at_exit ( shell , message , opts )
754710
755- excluded == total and Keyword . has_key? ( opts , :only ) ->
756- message = "The --only option was given to \" mix test \" but no test was executed"
757- raise_or_error_at_exit ( shell , message , opts )
711+ true ->
712+ :ok
713+ end
758714
759- true ->
760- :ok
761- end
715+ :noop ->
716+ cond do
717+ opts [ :stale ] ->
718+ Mix . shell ( ) . info ( "No stale tests" )
762719
763- :noop ->
764- cond do
765- opts [ :stale ] ->
766- Mix . shell ( ) . info ( "No stale tests" )
720+ opts [ :failed ] || files == [ ] ->
721+ Mix . shell ( ) . info ( "There are no tests to run" )
767722
768- opts [ :failed ] || files == [ ] ->
769- Mix . shell ( ) . info ( "There are no tests to run" )
723+ true ->
724+ message = "Paths given to \" mix test\" did not match any directory/file: "
725+ raise_or_error_at_exit ( shell , message <> Enum . join ( files , ", " ) , opts )
726+ end
770727
771- true ->
772- message = "Paths given to \" mix test\" did not match any directory/file: "
773- raise_or_error_at_exit ( shell , message <> Enum . join ( files , ", " ) , opts )
774- end
775-
776- :ok
728+ :ok
729+ end
777730 end
778731
779732 # similar to Mix.Utils.extract_files/2, but returns a list of directly included test files,
0 commit comments