Skip to content

Commit 133fc0c

Browse files
author
José Valim
committed
Only call compile_path when we effectively need it mix test, closes #4783
1 parent 3b5bb5c commit 133fc0c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/mix/lib/mix/compilers/test.ex

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ defmodule Mix.Compilers.Test do
2121
It expects all of the test patterns, the test files that were matched for the
2222
test patterns, the test paths, and the opts from the test task.
2323
"""
24-
def require_and_run(test_patterns, matched_test_files, test_paths, compile_path, opts) do
24+
def require_and_run(test_patterns, matched_test_files, test_paths, opts) do
2525
stale = opts[:stale]
2626

2727
{test_files_to_run, stale_manifest_pid, parallel_require_callbacks} =
2828
if stale do
29-
set_up_stale(matched_test_files, test_paths, compile_path, opts)
29+
set_up_stale(matched_test_files, test_paths, opts)
3030
else
3131
{matched_test_files, nil, []}
3232
end
@@ -58,7 +58,7 @@ defmodule Mix.Compilers.Test do
5858
end
5959
end
6060

61-
defp set_up_stale(matched_test_files, test_paths, compile_path, opts) do
61+
defp set_up_stale(matched_test_files, test_paths, opts) do
6262
manifest = manifest()
6363
modified = Mix.Utils.last_modified(manifest)
6464
all_sources = read_manifest()
@@ -95,20 +95,17 @@ defmodule Mix.Compilers.Test do
9595

9696
test_files_to_run =
9797
sources
98-
|> tests_with_changed_references(compile_path)
98+
|> tests_with_changed_references()
9999
|> MapSet.union(stale)
100100
|> MapSet.to_list()
101101

102102
if test_files_to_run == [] do
103103
write_manifest(sources)
104-
105104
{[], nil, nil}
106105
else
107106
{:ok, pid} = Agent.start_link(fn -> sources end)
108-
109107
cwd = File.cwd!()
110108
parallel_require_callbacks = [each_module: &each_module(pid, cwd, &1, &2, &3)]
111-
112109
{test_files_to_run, pid, parallel_require_callbacks}
113110
end
114111
end
@@ -191,13 +188,13 @@ defmodule Mix.Compilers.Test do
191188

192189
## Test changed dependency resolution
193190

194-
defp tests_with_changed_references(test_sources, compile_path) do
191+
defp tests_with_changed_references(test_sources) do
195192
test_manifest = manifest()
196193
[elixir_manifest] = Mix.Tasks.Compile.Elixir.manifests()
197194

198195
if Mix.Utils.stale?([elixir_manifest], [test_manifest]) do
199196
elixir_manifest_entries =
200-
CE.read_manifest(elixir_manifest, compile_path)
197+
CE.read_manifest(elixir_manifest, Mix.Project.compile_path())
201198
|> Enum.group_by(&elem(&1, 0))
202199

203200
stale_modules =

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,12 @@ defmodule Mix.Tasks.Test do
184184
end
185185

186186
project = Mix.Project.config
187-
compile_path = Mix.Project.compile_path(project)
187+
188188

189189
# Start cover after we load deps but before we start the app.
190190
cover =
191191
if opts[:cover] do
192+
compile_path = Mix.Project.compile_path(project)
192193
cover = Keyword.merge(@cover, project[:test_coverage] || [])
193194
cover[:tool].start(compile_path, cover)
194195
end
@@ -227,7 +228,7 @@ defmodule Mix.Tasks.Test do
227228

228229
display_warn_test_pattern(matched_warn_test_files, test_pattern)
229230

230-
case CT.require_and_run(files, matched_test_files, test_paths, compile_path, opts) do
231+
case CT.require_and_run(files, matched_test_files, test_paths, opts) do
231232
{:ok, %{failures: failures}} ->
232233
cover && cover.()
233234

0 commit comments

Comments
 (0)