1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
From 2548965a1ee3cb92a10fbd77fb0e951e455f3249 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@plataformatec.com.br>
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)
|