From 2548965a1ee3cb92a10fbd77fb0e951e455f3249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 13 Jun 2019 13:49:47 +0200 Subject: [PATCH] Ensure started/loaded apps do not leak between Mix tests, closes #9137 --- lib/mix/test/mix/tasks/app.start_test.exs | 10 --------- lib/mix/test/mix/tasks/profile.cprof_test.exs | 2 -- lib/mix/test/mix/tasks/profile.eprof_test.exs | 2 -- lib/mix/test/mix/tasks/profile.fprof_test.exs | 2 -- lib/mix/test/mix/tasks/run_test.exs | 2 -- lib/mix/test/mix/umbrella_test.exs | 2 -- lib/mix/test/test_helper.exs | 21 +++++++------------ 7 files changed, 8 insertions(+), 33 deletions(-) diff --git a/lib/mix/test/mix/tasks/app.start_test.exs b/lib/mix/test/mix/tasks/app.start_test.exs index a7565733f4..7ae3b89e2a 100644 --- a/lib/mix/test/mix/tasks/app.start_test.exs +++ b/lib/mix/test/mix/tasks/app.start_test.exs @@ -19,7 +19,6 @@ defmodule Mix.Tasks.App.StartTest do end end - @tag apps: [:app_start_sample] test "compiles and starts the project" do Mix.Project.push(AppStartSample) @@ -50,7 +49,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:app_start_sample, :app_loaded_sample] test "start checks for invalid configuration", context do Mix.Project.push(AppStartSample) @@ -77,7 +75,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:error] test "validates Elixir version requirement", context do Mix.ProjectStack.post_config(elixir: "~> ~> 0.8.1") Mix.Project.push(WrongElixirProject) @@ -89,7 +86,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:error] test "validates the Elixir version with requirement", context do Mix.Project.push(WrongElixirProject) @@ -100,7 +96,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:error] test "does not validate the Elixir version with requirement when disabled", context do Mix.Project.push(WrongElixirProject) @@ -136,7 +131,6 @@ defmodule Mix.Tasks.App.StartTest do def start(_type, return), do: return end - @tag apps: [:return_sample] test "start points to report on error", context do Mix.Project.push(ReturnSample) @@ -155,7 +149,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:return_sample] test "start points to report on exception error", context do Mix.Project.push(ReturnSample) @@ -177,7 +170,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:return_sample] test "start points to report on bad return", context do Mix.Project.push(ReturnSample) @@ -212,7 +204,6 @@ defmodule Mix.Tasks.App.StartTest do def start(_type, reason), do: exit(reason) end - @tag apps: [:exit_sample] test "start points to report on exit", context do Mix.Project.push(ExitSample) @@ -230,7 +221,6 @@ defmodule Mix.Tasks.App.StartTest do end) end - @tag apps: [:exit_sample] test "start points to report on normal exit", context do Mix.Project.push(ExitSample) diff --git a/lib/mix/test/mix/tasks/profile.cprof_test.exs b/lib/mix/test/mix/tasks/profile.cprof_test.exs index 30e432f63e..084b3a8d0e 100644 --- a/lib/mix/test/mix/tasks/profile.cprof_test.exs +++ b/lib/mix/test/mix/tasks/profile.cprof_test.exs @@ -4,10 +4,8 @@ defmodule Mix.Tasks.Profile.CprofTest do use MixTest.Case import ExUnit.CaptureIO - alias Mix.Tasks.Profile.Cprof - @moduletag apps: [:sample] @expr "Enum.each(1..5, &String.Chars.Integer.to_string/1)" test "profiles evaluated expression", context do diff --git a/lib/mix/test/mix/tasks/profile.eprof_test.exs b/lib/mix/test/mix/tasks/profile.eprof_test.exs index adc86b5a62..19e46856e3 100644 --- a/lib/mix/test/mix/tasks/profile.eprof_test.exs +++ b/lib/mix/test/mix/tasks/profile.eprof_test.exs @@ -4,10 +4,8 @@ defmodule Mix.Tasks.Profile.EprofTest do use MixTest.Case import ExUnit.CaptureIO - alias Mix.Tasks.Profile.Eprof - @moduletag apps: [:sample] @expr "Enum.each(1..5, &String.Chars.Integer.to_string/1)" test "profiles evaluated expression", context do diff --git a/lib/mix/test/mix/tasks/profile.fprof_test.exs b/lib/mix/test/mix/tasks/profile.fprof_test.exs index 8f84077e7b..d40717a256 100644 --- a/lib/mix/test/mix/tasks/profile.fprof_test.exs +++ b/lib/mix/test/mix/tasks/profile.fprof_test.exs @@ -4,9 +4,7 @@ defmodule Mix.Tasks.Profile.FprofTest do use MixTest.Case import ExUnit.CaptureIO - alias Mix.Tasks.Profile.Fprof - @moduletag apps: [:sample] test "profiles evaluated expression", context do in_tmp(context.test, fn -> diff --git a/lib/mix/test/mix/tasks/run_test.exs b/lib/mix/test/mix/tasks/run_test.exs index 6748130000..7d2ffe9888 100644 --- a/lib/mix/test/mix/tasks/run_test.exs +++ b/lib/mix/test/mix/tasks/run_test.exs @@ -5,8 +5,6 @@ defmodule Mix.Tasks.RunTest do import ExUnit.CaptureIO - @moduletag apps: [:sample] - setup do Mix.Project.push(MixTest.Case.Sample) end diff --git a/lib/mix/test/mix/umbrella_test.exs b/lib/mix/test/mix/umbrella_test.exs index 914da5aa6d..d6f8f1a4f5 100644 --- a/lib/mix/test/mix/umbrella_test.exs +++ b/lib/mix/test/mix/umbrella_test.exs @@ -3,8 +3,6 @@ Code.require_file("../test_helper.exs", __DIR__) defmodule Mix.UmbrellaTest do use MixTest.Case - @moduletag apps: [:foo, :bar] - test "apps_paths" do in_fixture("umbrella_dep/deps/umbrella", fn -> assert Mix.Project.apps_paths() == nil diff --git a/lib/mix/test/test_helper.exs b/lib/mix/test/test_helper.exs index 0204c7fecc..bce247b2f5 100644 --- a/lib/mix/test/test_helper.exs +++ b/lib/mix/test/test_helper.exs @@ -2,6 +2,9 @@ Mix.start() Mix.shell(Mix.Shell.Process) Application.put_env(:mix, :colors, enabled: false) +Logger.remove_backend(:console) +Application.put_env(:logger, :backends, []) + exclude = if match?({:win32, _}, :os.type()), do: [unix: true], else: [windows: true] ExUnit.start(trace: "--trace" in System.argv(), exclude: exclude) @@ -32,12 +35,9 @@ defmodule MixTest.Case do end end - setup config do - if apps = config[:apps] do - Logger.remove_backend(:console) - Application.put_env(:logger, :backends, []) - end + @apps Enum.map(Application.loaded_applications(), &elem(&1, 0)) + setup do on_exit(fn -> Application.start(:logger) Mix.env(:dev) @@ -48,14 +48,9 @@ defmodule MixTest.Case do Mix.ProjectStack.clear_stack() delete_tmp_paths() - if apps do - for app <- apps do - Application.stop(app) - Application.unload(app) - end - - Logger.add_backend(:console, flush: true) - Application.put_env(:logger, :backends, [:console]) + for {app, _, _} <- Application.loaded_applications(), app not in @apps do + Application.stop(app) + Application.unload(app) end end)