From 01752ce3cab456a8ee3818f568b18c3e28a952b7 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 3 Oct 2025 21:05:46 +0900 Subject: [PATCH 1/2] Fix inaccurate hint for disabling :test_ignore_filters --- lib/mix/lib/mix/tasks/test.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/lib/mix/tasks/test.ex b/lib/mix/lib/mix/tasks/test.ex index 7e6f87a67e..b20bdba007 100644 --- a/lib/mix/lib/mix/tasks/test.ex +++ b/lib/mix/lib/mix/tasks/test.ex @@ -851,7 +851,7 @@ defmodule Mix.Tasks.Test do This might indicate a typo in a test file name (for example, using "foo_tests.exs" instead of "foo_test.exs"). You can adjust which files trigger this warning by configuring the `:test_ignore_filters` option in your - Mix project's configuration. To disable the warning entirely, set that option to false. + Mix project's configuration. To disable the warning entirely, set that option to [fn _ -> true end]. For more information, run `mix help test`. """) From 3dffa15ad9ae324eba3b07cec0479356bc4feee5 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 3 Oct 2025 21:20:48 +0900 Subject: [PATCH 2/2] Better error message on invalid :test_ignore_filters --- lib/mix/lib/mix/tasks/test.ex | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/mix/lib/mix/tasks/test.ex b/lib/mix/lib/mix/tasks/test.ex index b20bdba007..804b57efd7 100644 --- a/lib/mix/lib/mix/tasks/test.ex +++ b/lib/mix/lib/mix/tasks/test.ex @@ -660,7 +660,7 @@ defmodule Mix.Tasks.Test do {potential_test_files, directly_included_test_files} = extract_files(test_files, test_pattern) {load_files, _ignored_files, warn_files} = - classify_test_files(potential_test_files, project) + classify_test_files(shell, potential_test_files, project) # ensure that files given as direct argument to mix test are loaded, # even if the test_load_filters don't match @@ -797,16 +797,10 @@ defmodule Mix.Tasks.Test do end end - defp classify_test_files(potential_test_files, project) do + defp classify_test_files(shell, potential_test_files, project) do test_load_filters = project[:test_load_filters] || [&String.ends_with?(&1, "_test.exs")] - elixirc_paths = project[:elixirc_paths] || [] - # ignore any _helper.exs files and files that are compiled (test support files) - test_ignore_filters = - [ - &String.ends_with?(&1, "_helper.exs"), - fn file -> Enum.any?(elixirc_paths, &String.starts_with?(file, &1)) end - ] ++ Keyword.get(project, :test_ignore_filters, []) + test_ignore_filters = get_test_ignore_filters(shell, project) {to_load, to_ignore, to_warn} = for file <- potential_test_files, reduce: {[], [], []} do @@ -827,6 +821,25 @@ defmodule Mix.Tasks.Test do {Enum.reverse(to_load), Enum.reverse(to_ignore), Enum.reverse(to_warn)} end + defp get_test_ignore_filters(shell, project) do + elixirc_paths = project[:elixirc_paths] || [] + + case Keyword.get(project, :test_ignore_filters, []) do + list when is_list(list) -> + # ignore any _helper.exs files and files that are compiled (test support files) + [ + &String.ends_with?(&1, "_helper.exs"), + fn file -> Enum.any?(elixirc_paths, &String.starts_with?(file, &1)) end + ] ++ list + + other -> + raise_with_shell( + shell, + "Invalid configuration for :test_ignore_filters, expected a list, got: #{inspect(other)}" + ) + end + end + defp any_file_matches?(file, filters) do Enum.any?(filters, fn filter -> case filter do