diff --git a/lib/mix/test/mix/umbrella_test.exs b/lib/mix/test/mix/umbrella_test.exs index 26aaecff99a..f88eedbe8b1 100644 --- a/lib/mix/test/mix/umbrella_test.exs +++ b/lib/mix/test/mix/umbrella_test.exs @@ -1,4 +1,4 @@ -Code.require_file "../test_helper.exs", __DIR__ +Code.require_file("../test_helper.exs", __DIR__) defmodule Mix.UmbrellaTest do use MixTest.Case @@ -7,11 +7,17 @@ defmodule Mix.UmbrellaTest do test "apps_paths" do in_fixture "umbrella_dep/deps/umbrella", fn -> - assert Mix.Project.apps_paths == nil + assert Mix.Project.apps_paths() == nil + Mix.Project.in_project(:umbrella, ".", fn _ -> - assert Mix.Project.apps_paths == - %{bar: "apps/bar", foo: "apps/foo"} - assert_received {:mix_shell, :error, ["warning: path \"apps/dont_error_on_missing_mixfile\"" <> _]} + assert Mix.Project.apps_paths() == %{bar: "apps/bar", foo: "apps/foo"} + + assert_received { + :mix_shell, + :error, + ["warning: path \"apps/dont_error_on_missing_mixfile\"" <> _] + } + refute_received {:mix_shell, :error, ["warning: path \"apps/dont_error_on_files\"" <> _]} end) end @@ -20,10 +26,9 @@ defmodule Mix.UmbrellaTest do test "apps_paths with selection" do in_fixture "umbrella_dep/deps/umbrella", fn -> Mix.Project.in_project(:umbrella, ".", [apps: [:foo, :bar]], fn _ -> - File.mkdir_p! "apps/errors" - File.write! "apps/errors/mix.exs", "raise :oops" - assert Mix.Project.apps_paths == - %{bar: "apps/bar", foo: "apps/foo"} + File.mkdir_p!("apps/errors") + File.write!("apps/errors/mix.exs", "raise :oops") + assert Mix.Project.apps_paths() == %{bar: "apps/bar", foo: "apps/foo"} end) end end @@ -31,14 +36,14 @@ defmodule Mix.UmbrellaTest do test "compiles umbrella" do in_fixture "umbrella_dep/deps/umbrella", fn -> Mix.Project.in_project(:umbrella, ".", fn _ -> - Mix.Task.run "deps" + Mix.Task.run("deps") assert_received {:mix_shell, :info, ["* bar (apps/bar) (mix)"]} assert_received {:mix_shell, :info, ["* foo (apps/foo) (mix)"]} # Ensure we can compile and run checks - Mix.Task.run "deps.compile" - Mix.Task.run "deps.loadpaths" - Mix.Task.run "compile", ["--verbose"] + Mix.Task.run("deps.compile") + Mix.Task.run("deps.loadpaths") + Mix.Task.run("compile", ["--verbose"]) assert_received {:mix_shell, :info, ["==> bar"]} assert_received {:mix_shell, :info, ["Generated bar app"]} @@ -51,8 +56,8 @@ defmodule Mix.UmbrellaTest do assert_received {:mix_shell, :info, [":foo env is dev"]} assert_received {:mix_shell, :info, [":bar env is dev"]} - Mix.Task.clear - Mix.Task.run "app.start", ["--no-compile"] + Mix.Task.clear() + Mix.Task.run("app.start", ["--no-compile"]) end) end end @@ -60,13 +65,13 @@ defmodule Mix.UmbrellaTest do test "compiles umbrella with protocol consolidation" do in_fixture "umbrella_dep/deps/umbrella", fn -> Mix.Project.in_project(:umbrella, ".", fn _ -> - Mix.Task.run "compile", ["--verbose"] + Mix.Task.run("compile", ["--verbose"]) assert_received {:mix_shell, :info, ["Generated bar app"]} assert_received {:mix_shell, :info, ["Generated foo app"]} - assert File.regular? "_build/dev/consolidated/Elixir.Enumerable.beam" - purge [Enumerable] + assert File.regular?("_build/dev/consolidated/Elixir.Enumerable.beam") + purge([Enumerable]) - assert Mix.Tasks.App.Start.run [] + assert Mix.Tasks.App.Start.run([]) assert Protocol.consolidated?(Enumerable) end) end @@ -78,16 +83,16 @@ defmodule Mix.UmbrellaTest do defmodule Elixir.Mix.Tasks.Umbrella.Recur do use Mix.Task @recursive true - def run(_), do: Mix.Task.run "compile", ["--verbose"] + def run(_), do: Mix.Task.run("compile", ["--verbose"]) end - Mix.Task.run "umbrella.recur" + Mix.Task.run("umbrella.recur") assert_received {:mix_shell, :info, ["Generated bar app"]} assert_received {:mix_shell, :info, ["Generated foo app"]} - assert File.regular? "_build/dev/consolidated/Elixir.Enumerable.beam" - purge [Enumerable] + assert File.regular?("_build/dev/consolidated/Elixir.Enumerable.beam") + purge([Enumerable]) - assert Mix.Tasks.App.Start.run [] + assert Mix.Tasks.App.Start.run([]) assert Protocol.consolidated?(Enumerable) end) end @@ -95,13 +100,12 @@ defmodule Mix.UmbrellaTest do defmodule UmbrellaDeps do def project do - [apps_path: "apps", - deps: [{:some_dep, path: "deps/some_dep"}]] + [apps_path: "apps", deps: [{:some_dep, path: "deps/some_dep"}]] end end test "loads umbrella dependencies" do - Mix.Project.push UmbrellaDeps + Mix.Project.push(UmbrellaDeps) in_fixture "umbrella_dep/deps/umbrella", fn -> File.mkdir_p!("deps/some_dep/ebin") @@ -109,17 +113,17 @@ defmodule Mix.UmbrellaTest do File.mkdir_p!("_build/dev/lib/foo/ebin") File.mkdir_p!("_build/dev/lib/bar/ebin") - Mix.Task.run "loadpaths", ["--no-deps-check", "--no-elixir-version-check"] - assert to_charlist(Path.expand("_build/dev/lib/some_dep/ebin")) in :code.get_path - assert to_charlist(Path.expand("_build/dev/lib/foo/ebin")) in :code.get_path - assert to_charlist(Path.expand("_build/dev/lib/bar/ebin")) in :code.get_path + Mix.Task.run("loadpaths", ["--no-deps-check", "--no-elixir-version-check"]) + assert to_charlist(Path.expand("_build/dev/lib/some_dep/ebin")) in :code.get_path() + assert to_charlist(Path.expand("_build/dev/lib/foo/ebin")) in :code.get_path() + assert to_charlist(Path.expand("_build/dev/lib/bar/ebin")) in :code.get_path() end end test "loads umbrella child dependencies in all environments" do in_fixture "umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/bar/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -129,25 +133,25 @@ defmodule Mix.UmbrellaTest do deps: [{:git_repo, git: MixTest.Case.fixture_path("git_repo"), only: :other}]] end end - """ + """) # Does not fetch when filtered - Mix.Tasks.Deps.Get.run ["--only", "dev"] + Mix.Tasks.Deps.Get.run(["--only", "dev"]) refute_received {:mix_shell, :info, ["* Getting git_repo" <> _]} # But works across all environments - Mix.Tasks.Deps.Get.run [] + Mix.Tasks.Deps.Get.run([]) assert_received {:mix_shell, :info, ["* Getting git_repo" <> _]} # Does not show by default - Mix.Tasks.Deps.run [] + Mix.Tasks.Deps.run([]) refute_received {:mix_shell, :info, ["* git_repo" <> _]} # But shows on proper environment Mix.env(:other) - Mix.Tasks.Deps.run [] + Mix.Tasks.Deps.run([]) assert_received {:mix_shell, :info, ["* git_repo " <> _]} - end + end) end after Mix.env(:test) @@ -155,8 +159,8 @@ defmodule Mix.UmbrellaTest do test "loads umbrella child optional dependencies" do in_fixture "umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/bar/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -166,18 +170,18 @@ defmodule Mix.UmbrellaTest do deps: [{:git_repo, git: MixTest.Case.fixture_path("git_repo"), optional: true}]] end end - """ + """) - Mix.Tasks.Deps.run [] + Mix.Tasks.Deps.run([]) assert_received {:mix_shell, :info, ["* git_repo " <> _]} - end + end) end end test "loads umbrella sibling dependencies with :in_umbrella" do in_fixture "umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/bar/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -187,19 +191,19 @@ defmodule Mix.UmbrellaTest do deps: [{:foo, in_umbrella: true}]] end end - """ + """) # Running from umbrella should not cause conflicts - Mix.Tasks.Deps.Get.run [] - Mix.Tasks.Run.run [] - end + Mix.Tasks.Deps.Get.run([]) + Mix.Tasks.Run.run([]) + end) end end test "finds umbrella sibling dependencies conflicts with :in_umbrella" do in_fixture "umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/bar/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -209,15 +213,20 @@ defmodule Mix.UmbrellaTest do deps: [{:foo, in_umbrella: true, env: :unknown}]] end end - """ + """) assert_raise Mix.Error, fn -> - Mix.Tasks.Deps.Get.run [] + Mix.Tasks.Deps.Get.run([]) end assert_received {:mix_shell, :error, ["Dependencies have diverged:"]} - assert_received {:mix_shell, :error, [" the dependency foo in mix.exs is overriding a child dependency" <> _]} - end + + assert_received { + :mix_shell, + :error, + [" the dependency foo in mix.exs is overriding a child dependency" <> _] + } + end) end end @@ -226,7 +235,7 @@ defmodule Mix.UmbrellaTest do test "list deps for umbrella as dependency" do in_fixture("umbrella_dep", fn -> Mix.Project.in_project(:umbrella_dep, ".", fn _ -> - Mix.Task.run "deps" + Mix.Task.run("deps") assert_received {:mix_shell, :info, ["* umbrella (deps/umbrella) (mix)"]} assert_received {:mix_shell, :info, ["* foo (apps/foo) (mix)"]} end) @@ -236,24 +245,26 @@ defmodule Mix.UmbrellaTest do test "compile for umbrella as dependency" do in_fixture "umbrella_dep", fn -> Mix.Project.in_project(:umbrella_dep, ".", fn _ -> - Mix.Task.run "deps.compile" - assert Bar.bar == "hello world" + Mix.Task.run("deps.compile") + assert Bar.bar() == "hello world" end) end end defmodule CycleDeps do def project do - [app: :umbrella_dep, - deps: [ - {:bar, path: "deps/umbrella/apps/bar"}, - {:umbrella, path: "deps/umbrella"} - ]] + [ + app: :umbrella_dep, + deps: [ + {:bar, path: "deps/umbrella/apps/bar"}, + {:umbrella, path: "deps/umbrella"} + ] + ] end end test "handles dependencies with cycles" do - Mix.Project.push CycleDeps + Mix.Project.push(CycleDeps) in_fixture "umbrella_dep", fn -> assert Enum.map(Mix.Dep.loaded([]), & &1.app) == [:foo, :bar, :umbrella] @@ -262,8 +273,8 @@ defmodule Mix.UmbrellaTest do test "handles dependencies with cycles and overridden deps" do in_fixture "umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/foo/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/foo/mix.exs", """ defmodule Foo.MixProject do use Mix.Project @@ -276,9 +287,9 @@ defmodule Mix.UmbrellaTest do deps: [{:bar, in_umbrella: true}]] end end - """ + """) - File.write! "apps/bar/mix.exs", """ + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -292,17 +303,17 @@ defmodule Mix.UmbrellaTest do {:b, path: "deps/b"}]] end end - """ + """) assert Enum.map(Mix.Dep.loaded([]), & &1.app) == [:a, :b, :bar, :foo] - end + end) end end test "uses dependency aliases" do in_fixture "umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/bar/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -312,19 +323,19 @@ defmodule Mix.UmbrellaTest do aliases: ["compile.all": fn _ -> Mix.shell.info "no compile bar" end]] end end - """ + """) - Mix.Task.run "compile", ["--verbose"] + Mix.Task.run("compile", ["--verbose"]) assert_receive {:mix_shell, :info, ["no compile bar"]} refute_receive {:mix_shell, :info, ["Compiled lib/bar.ex"]} - end + end) end end test "recompiles after path dependency changes" do in_fixture("umbrella_dep/deps/umbrella/apps", fn -> Mix.Project.in_project(:bar, "bar", fn _ -> - Mix.Task.run "compile", ["--verbose"] + Mix.Task.run("compile", ["--verbose"]) assert_received {:mix_shell, :info, ["Generated foo app"]} assert_received {:mix_shell, :info, ["Generated bar app"]} assert File.regular?("_build/dev/lib/foo/ebin/Elixir.Foo.beam") @@ -334,10 +345,16 @@ defmodule Mix.UmbrellaTest do assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:noop, []} # Noop when there is no runtime dependency - ensure_touched("_build/dev/lib/foo/ebin/Elixir.Foo.beam", - File.stat!("_build/dev/lib/bar/.compile.elixir").mtime) - ensure_touched("_build/dev/lib/foo/.compile.elixir", - File.stat!("_build/dev/lib/bar/.compile.elixir").mtime) + ensure_touched( + "_build/dev/lib/foo/ebin/Elixir.Foo.beam", + File.stat!("_build/dev/lib/bar/.compile.elixir").mtime + ) + + ensure_touched( + "_build/dev/lib/foo/.compile.elixir", + File.stat!("_build/dev/lib/bar/.compile.elixir").mtime + ) + assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:noop, []} # Add runtime dependency @@ -346,14 +363,21 @@ defmodule Mix.UmbrellaTest do def bar, do: Foo.foo end """) + assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:ok, []} assert_receive {:mix_shell, :info, ["Compiled lib/bar.ex"]} # Noop for runtime dependencies - ensure_touched("_build/dev/lib/foo/ebin/Elixir.Foo.beam", - File.stat!("_build/dev/lib/bar/.compile.elixir").mtime) - ensure_touched("_build/dev/lib/foo/.compile.elixir", - File.stat!("_build/dev/lib/bar/.compile.elixir").mtime) + ensure_touched( + "_build/dev/lib/foo/ebin/Elixir.Foo.beam", + File.stat!("_build/dev/lib/bar/.compile.elixir").mtime + ) + + ensure_touched( + "_build/dev/lib/foo/.compile.elixir", + File.stat!("_build/dev/lib/bar/.compile.elixir").mtime + ) + assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:noop, []} # Add compile time dependency @@ -362,10 +386,16 @@ defmodule Mix.UmbrellaTest do assert_receive {:mix_shell, :info, ["Compiled lib/bar.ex"]} # Recompiles for compile time dependencies - ensure_touched("_build/dev/lib/foo/ebin/Elixir.Foo.beam", - File.stat!("_build/dev/lib/bar/.compile.elixir").mtime) - ensure_touched("_build/dev/lib/foo/.compile.elixir", - File.stat!("_build/dev/lib/bar/.compile.elixir").mtime) + ensure_touched( + "_build/dev/lib/foo/ebin/Elixir.Foo.beam", + File.stat!("_build/dev/lib/bar/.compile.elixir").mtime + ) + + ensure_touched( + "_build/dev/lib/foo/.compile.elixir", + File.stat!("_build/dev/lib/bar/.compile.elixir").mtime + ) + assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:ok, []} assert_receive {:mix_shell, :info, ["Compiled lib/bar.ex"]} end) @@ -384,21 +414,26 @@ defmodule Mix.UmbrellaTest do def foo(list), do: list end """) + Mix.Task.run("compile") assert File.regular?("_build/dev/lib/bar/consolidated/Elixir.Foo.beam") assert Mix.Tasks.Compile.Protocols.run([]) == :noop # Mark protocol as outdated - File.touch!("_build/dev/lib/bar/consolidated/Elixir.Foo.beam", - {{2010, 1, 1}, {0, 0, 0}}) + File.touch!("_build/dev/lib/bar/consolidated/Elixir.Foo.beam", {{2010, 1, 1}, {0, 0, 0}}) + + ensure_touched( + "_build/dev/lib/foo/ebin/Elixir.Foo.beam", + File.stat!("_build/dev/lib/bar/consolidated/.compile.protocols").mtime + ) - ensure_touched("_build/dev/lib/foo/ebin/Elixir.Foo.beam", - File.stat!("_build/dev/lib/bar/consolidated/.compile.protocols").mtime) assert Mix.Tasks.Compile.Protocols.run([]) == :ok # Check new timestamp - assert File.stat!("_build/dev/lib/bar/consolidated/Elixir.Foo.beam").mtime > - {{2010, 1, 1}, {0, 0, 0}} + assert File.stat!("_build/dev/lib/bar/consolidated/Elixir.Foo.beam").mtime > { + {2010, 1, 1}, + {0, 0, 0} + } end) end) end @@ -444,7 +479,7 @@ defmodule Mix.UmbrellaTest do # Emulate the dependency being removed Mix.Project.in_project(:foo, "apps/foo", [build_path: "../../_build", deps: []], fn _ -> - File.rm_rf "../../_build/dev/lib/bar" + File.rm_rf("../../_build/dev/lib/bar") Mix.Task.run("compile.protocols") end) end) @@ -452,8 +487,8 @@ defmodule Mix.UmbrellaTest do test "apps cannot refer to themselves as a dep" do in_fixture("umbrella_dep/deps/umbrella", fn -> - Mix.Project.in_project :umbrella, ".", fn _ -> - File.write! "apps/bar/mix.exs", """ + Mix.Project.in_project(:umbrella, ".", fn _ -> + File.write!("apps/bar/mix.exs", """ defmodule Bar.MixProject do use Mix.Project @@ -463,12 +498,12 @@ defmodule Mix.UmbrellaTest do deps: [{:bar, in_umbrella: true}]] end end - """ + """) assert_raise Mix.Error, "App bar lists itself as a dependency", fn -> Mix.Task.run("deps.get", ["--verbose"]) == [:ok, :ok] end - end + end) end) end end