Skip to content

Commit d703e78

Browse files
sabiwarajosevalim
authored andcommitted
Fix inaccurate hint for disabling :test_ignore_filters (#14808)
1 parent 44fd817 commit d703e78

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lib/mix/lib/mix/tasks/test.ex

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ defmodule Mix.Tasks.Test do
649649
{potential_test_files, directly_included_test_files} = extract_files(test_files, test_pattern)
650650

651651
{load_files, _ignored_files, warn_files} =
652-
classify_test_files(potential_test_files, project)
652+
classify_test_files(shell, potential_test_files, project)
653653

654654
# ensure that files given as direct argument to mix test are loaded,
655655
# even if the test_load_filters don't match
@@ -786,16 +786,10 @@ defmodule Mix.Tasks.Test do
786786
end
787787
end
788788

789-
defp classify_test_files(potential_test_files, project) do
789+
defp classify_test_files(shell, potential_test_files, project) do
790790
test_load_filters = project[:test_load_filters] || [&String.ends_with?(&1, "_test.exs")]
791-
elixirc_paths = project[:elixirc_paths] || []
792791

793-
# ignore any _helper.exs files and files that are compiled (test support files)
794-
test_ignore_filters =
795-
[
796-
&String.ends_with?(&1, "_helper.exs"),
797-
fn file -> Enum.any?(elixirc_paths, &String.starts_with?(file, &1)) end
798-
] ++ Keyword.get(project, :test_ignore_filters, [])
792+
test_ignore_filters = get_test_ignore_filters(shell, project)
799793

800794
{to_load, to_ignore, to_warn} =
801795
for file <- potential_test_files, reduce: {[], [], []} do
@@ -816,6 +810,25 @@ defmodule Mix.Tasks.Test do
816810
{Enum.reverse(to_load), Enum.reverse(to_ignore), Enum.reverse(to_warn)}
817811
end
818812

813+
defp get_test_ignore_filters(shell, project) do
814+
elixirc_paths = project[:elixirc_paths] || []
815+
816+
case Keyword.get(project, :test_ignore_filters, []) do
817+
list when is_list(list) ->
818+
# ignore any _helper.exs files and files that are compiled (test support files)
819+
[
820+
&String.ends_with?(&1, "_helper.exs"),
821+
fn file -> Enum.any?(elixirc_paths, &String.starts_with?(file, &1)) end
822+
] ++ list
823+
824+
other ->
825+
raise_with_shell(
826+
shell,
827+
"Invalid configuration for :test_ignore_filters, expected a list, got: #{inspect(other)}"
828+
)
829+
end
830+
end
831+
819832
defp any_file_matches?(file, filters) do
820833
Enum.any?(filters, fn filter ->
821834
case filter do
@@ -840,7 +853,7 @@ defmodule Mix.Tasks.Test do
840853
This might indicate a typo in a test file name (for example, using "foo_tests.exs" instead of "foo_test.exs").
841854
842855
You can adjust which files trigger this warning by configuring the `:test_ignore_filters` option in your
843-
Mix project's configuration. To disable the warning entirely, set that option to false.
856+
Mix project's configuration. To disable the warning entirely, set that option to [fn _ -> true end].
844857
845858
For more information, run `mix help test`.
846859
""")

0 commit comments

Comments
 (0)