@@ -142,6 +142,8 @@ defmodule ExUnit.Runner do
142
142
143
143
{ case_pid , case_ref } =
144
144
spawn_monitor ( fn ->
145
+ ExUnit.OnExitHandler . register ( self )
146
+
145
147
case exec_case_setup ( test_case ) do
146
148
{ :ok , test_case , context } ->
147
149
Enum . each ( tests , & run_test ( config , & 1 , context ) )
@@ -154,12 +156,16 @@ defmodule ExUnit.Runner do
154
156
end
155
157
end )
156
158
157
- receive do
158
- { ^ case_pid , :case_finished , test_case , tests } ->
159
- { test_case , tests }
160
- { :DOWN , ^ case_ref , :process , ^ case_pid , error } ->
161
- { % { test_case | state: { :failed , { { :EXIT , case_pid } , error , [ ] } } } , [ ] }
162
- end
159
+ { test_case , pending } =
160
+ receive do
161
+ { ^ case_pid , :case_finished , test_case , tests } ->
162
+ { test_case , tests }
163
+ { :DOWN , ^ case_ref , :process , ^ case_pid , error } ->
164
+ test_case = % { test_case | state: { :failed , { { :EXIT , case_pid } , error , [ ] } } }
165
+ { test_case , [ ] }
166
+ end
167
+
168
+ { exec_on_exit ( test_case , case_pid ) , pending }
163
169
end
164
170
165
171
defp exec_case_setup ( % ExUnit.TestCase { name: case_name } = test_case ) do
@@ -249,13 +255,13 @@ defmodule ExUnit.Runner do
249
255
% { test | state: state }
250
256
end
251
257
252
- defp exec_on_exit ( test , test_pid ) do
253
- case ExUnit.OnExitHandler . run ( test_pid ) do
258
+ defp exec_on_exit ( test_or_case , pid ) do
259
+ case ExUnit.OnExitHandler . run ( pid ) do
254
260
:ok ->
255
- test
261
+ test_or_case
256
262
{ kind , reason , stack } ->
257
- state = test . state || { :failed , { kind , reason , prune_stacktrace ( stack ) } }
258
- % { test | state: state }
263
+ state = test_or_case . state || { :failed , { kind , reason , prune_stacktrace ( stack ) } }
264
+ % { test_or_case | state: state }
259
265
end
260
266
end
261
267
0 commit comments