Skip to content

Commit 2548965

Browse files
author
José Valim
committed
Ensure started/loaded apps do not leak between Mix tests, closes #9137
1 parent 09c01da commit 2548965

File tree

7 files changed

+8
-33
lines changed

7 files changed

+8
-33
lines changed

lib/mix/test/mix/tasks/app.start_test.exs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ defmodule Mix.Tasks.App.StartTest do
1919
end
2020
end
2121

22-
@tag apps: [:app_start_sample]
2322
test "compiles and starts the project" do
2423
Mix.Project.push(AppStartSample)
2524

@@ -50,7 +49,6 @@ defmodule Mix.Tasks.App.StartTest do
5049
end)
5150
end
5251

53-
@tag apps: [:app_start_sample, :app_loaded_sample]
5452
test "start checks for invalid configuration", context do
5553
Mix.Project.push(AppStartSample)
5654

@@ -77,7 +75,6 @@ defmodule Mix.Tasks.App.StartTest do
7775
end)
7876
end
7977

80-
@tag apps: [:error]
8178
test "validates Elixir version requirement", context do
8279
Mix.ProjectStack.post_config(elixir: "~> ~> 0.8.1")
8380
Mix.Project.push(WrongElixirProject)
@@ -89,7 +86,6 @@ defmodule Mix.Tasks.App.StartTest do
8986
end)
9087
end
9188

92-
@tag apps: [:error]
9389
test "validates the Elixir version with requirement", context do
9490
Mix.Project.push(WrongElixirProject)
9591

@@ -100,7 +96,6 @@ defmodule Mix.Tasks.App.StartTest do
10096
end)
10197
end
10298

103-
@tag apps: [:error]
10499
test "does not validate the Elixir version with requirement when disabled", context do
105100
Mix.Project.push(WrongElixirProject)
106101

@@ -136,7 +131,6 @@ defmodule Mix.Tasks.App.StartTest do
136131
def start(_type, return), do: return
137132
end
138133

139-
@tag apps: [:return_sample]
140134
test "start points to report on error", context do
141135
Mix.Project.push(ReturnSample)
142136

@@ -155,7 +149,6 @@ defmodule Mix.Tasks.App.StartTest do
155149
end)
156150
end
157151

158-
@tag apps: [:return_sample]
159152
test "start points to report on exception error", context do
160153
Mix.Project.push(ReturnSample)
161154

@@ -177,7 +170,6 @@ defmodule Mix.Tasks.App.StartTest do
177170
end)
178171
end
179172

180-
@tag apps: [:return_sample]
181173
test "start points to report on bad return", context do
182174
Mix.Project.push(ReturnSample)
183175

@@ -212,7 +204,6 @@ defmodule Mix.Tasks.App.StartTest do
212204
def start(_type, reason), do: exit(reason)
213205
end
214206

215-
@tag apps: [:exit_sample]
216207
test "start points to report on exit", context do
217208
Mix.Project.push(ExitSample)
218209

@@ -230,7 +221,6 @@ defmodule Mix.Tasks.App.StartTest do
230221
end)
231222
end
232223

233-
@tag apps: [:exit_sample]
234224
test "start points to report on normal exit", context do
235225
Mix.Project.push(ExitSample)
236226

lib/mix/test/mix/tasks/profile.cprof_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ defmodule Mix.Tasks.Profile.CprofTest do
44
use MixTest.Case
55

66
import ExUnit.CaptureIO
7-
87
alias Mix.Tasks.Profile.Cprof
98

10-
@moduletag apps: [:sample]
119
@expr "Enum.each(1..5, &String.Chars.Integer.to_string/1)"
1210

1311
test "profiles evaluated expression", context do

lib/mix/test/mix/tasks/profile.eprof_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ defmodule Mix.Tasks.Profile.EprofTest do
44
use MixTest.Case
55

66
import ExUnit.CaptureIO
7-
87
alias Mix.Tasks.Profile.Eprof
98

10-
@moduletag apps: [:sample]
119
@expr "Enum.each(1..5, &String.Chars.Integer.to_string/1)"
1210

1311
test "profiles evaluated expression", context do

lib/mix/test/mix/tasks/profile.fprof_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ defmodule Mix.Tasks.Profile.FprofTest do
44
use MixTest.Case
55

66
import ExUnit.CaptureIO
7-
87
alias Mix.Tasks.Profile.Fprof
9-
@moduletag apps: [:sample]
108

119
test "profiles evaluated expression", context do
1210
in_tmp(context.test, fn ->

lib/mix/test/mix/tasks/run_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ defmodule Mix.Tasks.RunTest do
55

66
import ExUnit.CaptureIO
77

8-
@moduletag apps: [:sample]
9-
108
setup do
119
Mix.Project.push(MixTest.Case.Sample)
1210
end

lib/mix/test/mix/umbrella_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Code.require_file("../test_helper.exs", __DIR__)
33
defmodule Mix.UmbrellaTest do
44
use MixTest.Case
55

6-
@moduletag apps: [:foo, :bar]
7-
86
test "apps_paths" do
97
in_fixture("umbrella_dep/deps/umbrella", fn ->
108
assert Mix.Project.apps_paths() == nil

lib/mix/test/test_helper.exs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Mix.start()
22
Mix.shell(Mix.Shell.Process)
33
Application.put_env(:mix, :colors, enabled: false)
44

5+
Logger.remove_backend(:console)
6+
Application.put_env(:logger, :backends, [])
7+
58
exclude = if match?({:win32, _}, :os.type()), do: [unix: true], else: [windows: true]
69
ExUnit.start(trace: "--trace" in System.argv(), exclude: exclude)
710

@@ -32,12 +35,9 @@ defmodule MixTest.Case do
3235
end
3336
end
3437

35-
setup config do
36-
if apps = config[:apps] do
37-
Logger.remove_backend(:console)
38-
Application.put_env(:logger, :backends, [])
39-
end
38+
@apps Enum.map(Application.loaded_applications(), &elem(&1, 0))
4039

40+
setup do
4141
on_exit(fn ->
4242
Application.start(:logger)
4343
Mix.env(:dev)
@@ -48,14 +48,9 @@ defmodule MixTest.Case do
4848
Mix.ProjectStack.clear_stack()
4949
delete_tmp_paths()
5050

51-
if apps do
52-
for app <- apps do
53-
Application.stop(app)
54-
Application.unload(app)
55-
end
56-
57-
Logger.add_backend(:console, flush: true)
58-
Application.put_env(:logger, :backends, [:console])
51+
for {app, _, _} <- Application.loaded_applications(), app not in @apps do
52+
Application.stop(app)
53+
Application.unload(app)
5954
end
6055
end)
6156

0 commit comments

Comments
 (0)