@@ -234,27 +234,29 @@ defmodule Mix.Tasks.Test do
234234 In Elixir versions earlier than 1.19.0, this option defaulted to `*_test.exs`,
235235 but to allow better warnings for misnamed test files, it since matches any
236236 Elixir file and expects those to be filtered by `:test_load_filters` and
237- `:test_warn_filters `.
237+ `:test_ignore_filters `.
238238
239239 * `:test_load_filters` - a list of files, regular expressions or one-arity
240240 functions to restrict which files matched by the `:test_pattern` are loaded.
241- Defaults to `[~r/.*_test\\.exs$/]`
241+ Defaults to `[&String.ends_with?(&1, "_test.exs")]`. Paths are relative to
242+ the project root and separated by `/`, even on Windows.
242243
243- * `:test_warn_filters ` - a list of files, regular expressions or one-arity
244+ * `:test_ignore_filters ` - a list of files, regular expressions or one-arity
244245 functions to restrict which files matched by the `:test_pattern`, but not loaded
245246 by `:test_load_filters`, trigger a warning for a potentially misnamed test file.
246247
247248 Defaults to:
248249
249250 ```elixir
250251 [
251- ~r/.* _helper\ .exs$/ ,
252+ &String.ends_with?(&1, " _helper.exs") ,
252253 fn file -> Enum.any?(elixirc_paths(Mix.env()), &String.starts_with?(file, &1)) end
253254 ]
254255 ```
255256
256257 This ensures that any helper or test support files are not triggering a warning.
257258 Warnings can be disabled by setting this option to `false` or `nil`.
259+ Paths are relative to the project root and separated by `/`, even on Windows.
258260
259261 ## Coloring
260262
@@ -624,15 +626,15 @@ defmodule Mix.Tasks.Test do
624626 if project [ :warn_test_pattern ] do
625627 Mix . shell ( ) . info ( """
626628 warning: the `:warn_test_pattern` configuration is deprecated and will be ignored. \
627- Use `:test_load_filters` and `:test_warn_filters ` instead.
629+ Use `:test_load_filters` and `:test_ignore_filters ` instead.
628630 """ )
629631 end
630632
631633 { test_files , test_opts } =
632634 if files != [ ] , do: ExUnit.Filters . parse_paths ( files ) , else: { test_paths , [ ] }
633635
634636 # get a list of all files in the test folders, which we filter by the test_load_filters
635- potential_test_files = Mix.Utils . extract_files ( test_files , test_pattern )
637+ { potential_test_files , directly_included_test_files } = extract_files ( test_files , test_pattern )
636638
637639 { load_files , _ignored_files , warn_files } =
638640 classify_test_files ( potential_test_files , project )
@@ -641,7 +643,7 @@ defmodule Mix.Tasks.Test do
641643 # even if the test_load_filters don't match
642644 load_files =
643645 if files != [ ] ,
644- do: Enum . uniq ( load_files ++ directly_included_test_files ( files ) ) ,
646+ do: Enum . uniq ( load_files ++ directly_included_test_files ) ,
645647 else: load_files
646648
647649 matched_test_files =
@@ -701,6 +703,33 @@ defmodule Mix.Tasks.Test do
701703 end
702704 end
703705
706+ # similar to Mix.Utils.extract_files/2, but returns a list of directly included test files,
707+ # that should be not filtered by the test_load_filters, e.g.
708+ # mix test test/some_file.exs
709+ defp extract_files ( paths , pattern ) do
710+ { files , directly_included } =
711+ for path <- paths , reduce: { [ ] , [ ] } do
712+ { acc , directly_included } ->
713+ case :elixir_utils . read_file_type ( path ) do
714+ { :ok , :directory } ->
715+ { [ acc , Path . wildcard ( "#{ path } /**/#{ pattern } " ) ] , directly_included }
716+
717+ { :ok , :regular } ->
718+ { [ acc , path ] , [ path | directly_included ] }
719+
720+ _ ->
721+ { acc , directly_included }
722+ end
723+ end
724+
725+ files =
726+ files
727+ |> List . flatten ( )
728+ |> Enum . uniq ( )
729+
730+ { files , directly_included }
731+ end
732+
704733 defp raise_with_shell ( shell , message ) do
705734 Mix . shell ( shell )
706735 Mix . raise ( message )
@@ -720,19 +749,15 @@ defmodule Mix.Tasks.Test do
720749 end
721750 end
722751
723- defp directly_included_test_files ( files ) do
724- Enum . filter ( files , fn path -> :elixir_utils . read_file_type ( path ) == { :ok , :regular } end )
725- end
726-
727752 defp classify_test_files ( potential_test_files , project ) do
728- test_load_filters = project [ :test_load_filters ] || [ ~r / .* _test\ . exs$ / ]
753+ test_load_filters = project [ :test_load_filters ] || [ & String . starts_with? ( & 1 , " _test.exs" ) ]
729754 elixirc_paths = project [ :elixirc_paths ] || [ ]
730755
731756 # ignore any _helper.exs files and files that are compiled (test support files)
732- test_warn_filters =
733- Keyword . get_lazy ( project , :test_warn_filters , fn ->
757+ test_ignore_filters =
758+ Keyword . get_lazy ( project , :test_ignore_filters , fn ->
734759 [
735- ~r / .* _helper\ . exs$ / ,
760+ & String . ends_with? ( & 1 , " _helper.exs" ) ,
736761 fn file -> Enum . any? ( elixirc_paths , & String . starts_with? ( file , & 1 ) ) end
737762 ]
738763 end )
@@ -744,11 +769,11 @@ defmodule Mix.Tasks.Test do
744769 any_file_matches? ( file , test_load_filters ) ->
745770 { [ file | to_load ] , to_ignore , to_warn }
746771
747- any_file_matches? ( file , test_warn_filters ) ->
772+ any_file_matches? ( file , test_ignore_filters ) ->
748773 { to_load , [ file | to_ignore ] , to_warn }
749774
750- # don't warn if test_warn_filters is explicitly set to nil / false
751- ! ! test_warn_filters ->
775+ # don't warn if test_ignore_filters is explicitly set to nil / false
776+ ! ! test_ignore_filters ->
752777 { to_load , to_ignore , [ file | to_warn ] }
753778 end
754779 end
@@ -774,13 +799,13 @@ defmodule Mix.Tasks.Test do
774799
775800 defp warn_misnamed_test_files ( ignored ) do
776801 Mix . shell ( ) . info ( """
777- warning: the following files do not match any of the configured `:test_load_filters` / `:test_warn_filters `:
802+ warning: the following files do not match any of the configured `:test_load_filters` / `:test_ignore_filters `:
778803
779804 #{ Enum . join ( ignored , "\n " ) }
780805
781806 This might indicate a typo in a test file name (for example, using "foo_tests.exs" instead of "foo_test.exs").
782807
783- You can adjust which files trigger this warning by configuring the `:test_warn_filters ` option in your
808+ You can adjust which files trigger this warning by configuring the `:test_ignore_filters ` option in your
784809 Mix project's configuration. To disable the warning entirely, set that option to false.
785810
786811 For more information, run `mix help test`.
0 commit comments