Skip to content

Commit 8216f0e

Browse files
committed
Tests
1 parent 284fa5d commit 8216f0e

File tree

5 files changed

+63
-25
lines changed

5 files changed

+63
-25
lines changed

lib/mix/lib/mix/tasks/deps.loadpaths.ex

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ defmodule Mix.Tasks.Deps.Loadpaths do
139139
defp partition([dep | deps], not_ok, compile) do
140140
cond do
141141
Mix.Dep.compilable?(dep) or (Mix.Dep.ok?(dep) and local?(dep)) ->
142-
if from_umbrella?(dep) do
143-
partition(deps, not_ok, compile)
144-
else
145-
partition(deps, not_ok, [dep | compile])
146-
end
142+
partition(deps, not_ok, [dep | compile])
147143

148144
Mix.Dep.ok?(dep) ->
149145
partition(deps, not_ok, compile)
@@ -163,11 +159,6 @@ defmodule Mix.Tasks.Deps.Loadpaths do
163159
|> Mix.Dep.filter_by_name(Mix.Dep.load_and_cache())
164160
end
165161

166-
# Those are compiled by umbrella.
167-
defp from_umbrella?(dep) do
168-
dep.opts[:from_umbrella]
169-
end
170-
171162
# Every local dependency (i.e. that are not fetchable)
172163
# are automatically recompiled if they are ok.
173164
defp local?(dep) do

lib/mix/test/fixtures/umbrella_dep/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule UmbrellaDep.MixProject do
44
def project do
55
[
66
app: :umbrella_dep,
7+
version: "0.1.0",
78
deps: deps()
89
]
910
end

lib/mix/test/mix/tasks/deps_test.exs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ defmodule Mix.Tasks.DepsTest do
6161
end
6262
end
6363

64-
defmodule RawRepoDep do
64+
defmodule RawRepoDepApp do
6565
def project do
6666
[
6767
app: :raw_sample,
@@ -219,6 +219,38 @@ defmodule Mix.Tasks.DepsTest do
219219
end)
220220
end
221221

222+
test "compiles deps using os partitions" do
223+
System.put_env("MIX_OS_DEPS_COMPILE_PARTITION_COUNT", "2")
224+
225+
in_fixture("deps_status", fn ->
226+
File.write!("mix.exs", """
227+
defmodule ParDepsApp do
228+
use Mix.Project
229+
230+
def project do
231+
[
232+
app: :par_sample,
233+
version: "0.1.0",
234+
deps: [
235+
{:raw_repo, "0.1.0", path: "custom/raw_repo"},
236+
{:git_repo, "0.1.0", path: #{inspect(fixture_path("git_repo"))}}
237+
]
238+
]
239+
end
240+
end
241+
""")
242+
243+
Mix.Project.in_project(:par_sample, ".", fn _ ->
244+
output = ExUnit.CaptureIO.capture_io(fn -> Mix.Tasks.Deps.Compile.run([]) end)
245+
assert output =~ ~r/\d> Generated git_repo app/
246+
assert output =~ ~r/\d> Generated raw_repo app/
247+
assert_received {:mix_shell, :info, ["mix deps.compile running across 2 OS processes"]}
248+
end)
249+
end)
250+
after
251+
System.delete_env("MIX_OS_DEPS_COMPILE_PARTITION_COUNT")
252+
end
253+
222254
test "doesn't compile any umbrella apps if --skip-umbrella-children is given" do
223255
in_fixture("umbrella_dep/deps/umbrella", fn ->
224256
Mix.Project.in_project(:umbrella, ".", fn _ ->
@@ -414,7 +446,7 @@ defmodule Mix.Tasks.DepsTest do
414446

415447
test "sets deps env to prod by default" do
416448
in_fixture("deps_status", fn ->
417-
Mix.Project.push(RawRepoDep)
449+
Mix.Project.push(RawRepoDepApp)
418450

419451
Mix.Tasks.Deps.Update.run(["--all"])
420452
assert_received {:mix_shell, :info, [":raw_repo env is prod"]}
@@ -751,7 +783,7 @@ defmodule Mix.Tasks.DepsTest do
751783

752784
test "checks if compile env changed" do
753785
in_fixture("deps_status", fn ->
754-
Mix.Project.push(RawRepoDep)
786+
Mix.Project.push(RawRepoDepApp)
755787
Mix.Tasks.Deps.Loadpaths.run([])
756788
assert_receive {:mix_shell, :info, ["Generated raw_repo app"]}
757789
assert Application.spec(:raw_repo, :vsn)
@@ -766,7 +798,7 @@ defmodule Mix.Tasks.DepsTest do
766798
Application.unload(:raw_repo)
767799
Mix.ProjectStack.pop()
768800
Mix.Task.clear()
769-
Mix.Project.push(RawRepoDep)
801+
Mix.Project.push(RawRepoDepApp)
770802
purge([RawRepo])
771803
Mix.Tasks.Loadconfig.load_compile("config/config.exs")
772804

lib/mix/test/mix/umbrella_test.exs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,27 @@ defmodule Mix.UmbrellaTest do
276276
test "compile for umbrella as dependency" do
277277
in_fixture("umbrella_dep", fn ->
278278
Mix.Project.in_project(:umbrella_dep, ".", fn _ ->
279-
Mix.Task.run("deps.compile")
279+
Mix.Task.run("compile")
280+
assert Bar.bar() == "hello world"
281+
end)
282+
end)
283+
end
284+
285+
test "compile for umbrella as dependency with os partitions" do
286+
System.put_env("MIX_OS_DEPS_COMPILE_PARTITION_COUNT", "2")
287+
288+
in_fixture("umbrella_dep", fn ->
289+
Mix.Project.in_project(:umbrella_dep, ".", fn _ ->
290+
output = ExUnit.CaptureIO.capture_io(fn -> Mix.Task.run("compile") end)
291+
assert output =~ ~r/\d> :foo env is prod/
292+
assert output =~ ~r/\d> :bar env is prod/
293+
294+
assert_received {:mix_shell, :info, ["mix deps.compile running across 2 OS processes"]}
280295
assert Bar.bar() == "hello world"
281296
end)
282297
end)
298+
after
299+
System.delete_env("MIX_OS_DEPS_COMPILE_PARTITION_COUNT")
283300
end
284301

285302
defmodule CycleDeps do
@@ -351,7 +368,7 @@ defmodule Mix.UmbrellaTest do
351368
def project do
352369
[app: :bar,
353370
version: "0.1.0",
354-
aliases: ["compile.all": fn _ -> Mix.shell().info "no compile bar" end]]
371+
aliases: ["compile.elixir": fn _ -> Mix.shell().info "no compile bar" end]]
355372
end
356373
end
357374
""")

lib/mix/test/test_helper.exs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ mix = Path.expand("../tmp/.mix", __DIR__)
1010
File.mkdir_p!(mix)
1111
System.put_env("MIX_HOME", mix)
1212

13-
System.delete_env("XDG_DATA_HOME")
14-
System.delete_env("XDG_CONFIG_HOME")
15-
1613
# Load protocols to make sure they are not unloaded during tests
1714
[Collectable, Enumerable, Inspect, String.Chars, List.Chars]
1815
|> Enum.each(& &1.__protocol__(:module))
@@ -53,12 +50,12 @@ ExUnit.start(
5350
)
5451

5552
# Clear environment variables that may affect tests
56-
System.delete_env("http_proxy")
57-
System.delete_env("https_proxy")
58-
System.delete_env("HTTP_PROXY")
59-
System.delete_env("HTTPS_PROXY")
60-
System.delete_env("MIX_ENV")
61-
System.delete_env("MIX_TARGET")
53+
Enum.each(
54+
~w(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY) ++
55+
~w(MIX_ENV MIX_OS_DEPS_COMPILE_PARTITION_COUNT MIX_TARGET) ++
56+
~w(XDG_DATA_HOME XDG_CONFIG_HOME),
57+
&System.delete_env/1
58+
)
6259

6360
defmodule MixTest.Case do
6461
use ExUnit.CaseTemplate

0 commit comments

Comments
 (0)