@@ -121,8 +121,7 @@ defmodule ExUnit.Callbacks do
121
121
122
122
@ doc false
123
123
defmacro __before_compile__ ( env ) do
124
- [ compile_callbacks ( env , :setup ) ,
125
- compile_callbacks ( env , :setup_all ) ]
124
+ [ compile_callbacks ( env , :setup ) , compile_callbacks ( env , :setup_all ) ]
126
125
end
127
126
128
127
@ doc """
@@ -139,7 +138,7 @@ defmodule ExUnit.Callbacks do
139
138
else
140
139
quote do
141
140
@ ex_unit_setup ExUnit.Callbacks . __callback__ ( unquote ( block ) , @ ex_unit_describe ) ++
142
- @ ex_unit_setup
141
+ @ ex_unit_setup
143
142
end
144
143
end
145
144
end
@@ -179,10 +178,12 @@ defmodule ExUnit.Callbacks do
179
178
do_setup_all ( quote ( do: _ ) , block )
180
179
else
181
180
quote do
182
- @ ex_unit_describe && raise "cannot invoke setup_all/1 inside describe as setup_all/1 " <>
183
- "always applies to all tests in a module"
181
+ @ ex_unit_describe &&
182
+ raise "cannot invoke setup_all/1 inside describe as setup_all/1 " <>
183
+ "always applies to all tests in a module"
184
+
184
185
@ ex_unit_setup_all ExUnit.Callbacks . __callback__ ( unquote ( block ) , nil ) ++
185
- @ ex_unit_setup_all
186
+ @ ex_unit_setup_all
186
187
end
187
188
end
188
189
end
@@ -225,7 +226,9 @@ defmodule ExUnit.Callbacks do
225
226
@ spec on_exit ( term , ( ( ) -> term ) ) :: :ok | no_return
226
227
def on_exit ( name_or_ref \\ make_ref ( ) , callback ) when is_function ( callback , 0 ) do
227
228
case ExUnit.OnExitHandler . add ( self ( ) , name_or_ref , callback ) do
228
- :ok -> :ok
229
+ :ok ->
230
+ :ok
231
+
229
232
:error ->
230
233
raise ArgumentError , "on_exit/2 callback can only be invoked from the test process"
231
234
end
@@ -266,17 +269,19 @@ defmodule ExUnit.Callbacks do
266
269
This function returns `{:ok, pid}` in case of success, otherwise it
267
270
returns `{:error, reason}`.
268
271
"""
269
- @ spec start_supervised ( Supervisor . child_spec | module | { module , term } , keyword ) ::
270
- Supervisor . on_start_child
272
+ @ spec start_supervised ( Supervisor . child_spec ( ) | module | { module , term } , keyword ) ::
273
+ Supervisor . on_start_child ( )
271
274
def start_supervised ( child_spec_or_module , opts \\ [ ] ) do
272
275
sup =
273
276
case ExUnit.OnExitHandler . get_supervisor ( self ( ) ) do
274
277
{ :ok , nil } ->
275
278
{ :ok , sup } = Supervisor . start_link ( [ ] , @ supervisor_opts )
276
279
ExUnit.OnExitHandler . put_supervisor ( self ( ) , sup )
277
280
sup
281
+
278
282
{ :ok , sup } ->
279
283
sup
284
+
280
285
:error ->
281
286
raise ArgumentError , "start_supervised/2 can only be invoked from the test process"
282
287
end
@@ -288,25 +293,24 @@ defmodule ExUnit.Callbacks do
288
293
Same as `start_supervised/2` but returns the PID on success and raises if
289
294
not started properly.
290
295
"""
291
- @ spec start_supervised! ( Supervisor . child_spec | module | { module , term } , keyword ) :: pid
296
+ @ spec start_supervised! ( Supervisor . child_spec ( ) | module | { module , term } , keyword ) :: pid
292
297
def start_supervised! ( child_spec_or_module , opts \\ [ ] ) do
293
298
case start_supervised ( child_spec_or_module , opts ) do
294
299
{ :ok , pid } ->
295
300
pid
301
+
296
302
{ :ok , pid , _info } ->
297
303
pid
304
+
298
305
{ :error , reason } ->
299
- raise "failed to start child with the spec #{ inspect child_spec_or_module } .\n " <>
300
- "Reason: #{ start_supervised_error ( reason ) } "
306
+ raise "failed to start child with the spec #{ inspect ( child_spec_or_module ) } .\n " <>
307
+ "Reason: #{ start_supervised_error ( reason ) } "
301
308
end
302
309
end
303
310
304
- defp start_supervised_error ( { { :EXIT , reason } , _info } ) ,
305
- do: Exception . format_exit ( reason )
306
- defp start_supervised_error ( { reason , _info } ) ,
307
- do: Exception . format_exit ( reason )
308
- defp start_supervised_error ( reason ) ,
309
- do: Exception . format_exit ( reason )
311
+ defp start_supervised_error ( { { :EXIT , reason } , _info } ) , do: Exception . format_exit ( reason )
312
+ defp start_supervised_error ( { reason , _info } ) , do: Exception . format_exit ( reason )
313
+ defp start_supervised_error ( reason ) , do: Exception . format_exit ( reason )
310
314
311
315
@ doc """
312
316
Stops a child process started via `start_supervised/2`.
@@ -325,10 +329,12 @@ defmodule ExUnit.Callbacks do
325
329
case ExUnit.OnExitHandler . get_supervisor ( self ( ) ) do
326
330
{ :ok , nil } ->
327
331
{ :error , :not_found }
332
+
328
333
{ :ok , sup } ->
329
334
with :ok <- Supervisor . terminate_child ( sup , id ) ,
330
335
:ok <- Supervisor . delete_child ( sup , id ) ,
331
336
do: :ok
337
+
332
338
:error ->
333
339
raise ArgumentError , "stop_supervised/1 can only be invoked from the test process"
334
340
end
@@ -342,12 +348,14 @@ defmodule ExUnit.Callbacks do
342
348
def __callback__ ( callback , describe ) do
343
349
for k <- List . wrap ( callback ) do
344
350
if not is_atom ( k ) do
345
- raise ArgumentError , "setup/setup_all expect a callback name as an atom or " <>
346
- "a list of callback names, got: #{ inspect k } "
351
+ raise ArgumentError ,
352
+ "setup/setup_all expect a callback name as an atom or " <>
353
+ "a list of callback names, got: #{ inspect ( k ) } "
347
354
end
348
355
349
356
{ k , describe }
350
- end |> Enum . reverse ( )
357
+ end
358
+ |> Enum . reverse ( )
351
359
end
352
360
353
361
@ doc false
@@ -383,39 +391,41 @@ defmodule ExUnit.Callbacks do
383
391
Map . merge ( context , data , fn
384
392
k , v1 , v2 when k in @ reserved ->
385
393
if v1 == v2 , do: v1 , else: raise_merge_reserved! ( mod , k , v2 )
394
+
386
395
_ , _ , v ->
387
396
v
388
397
end )
389
398
end
390
399
391
400
defp raise_merge_failed! ( mod , return_value ) do
392
- raise "expected ExUnit callback in #{ inspect mod } to return :ok | keyword | map, " <>
393
- "got #{ inspect return_value } instead"
401
+ raise "expected ExUnit callback in #{ inspect ( mod ) } to return :ok | keyword | map, " <>
402
+ "got #{ inspect ( return_value ) } instead"
394
403
end
395
404
396
405
defp raise_merge_reserved! ( mod , key , value ) do
397
- raise "ExUnit callback in #{ inspect mod } is trying to set " <>
398
- "reserved field #{ inspect key } to #{ inspect value } "
406
+ raise "ExUnit callback in #{ inspect ( mod ) } is trying to set " <>
407
+ "reserved field #{ inspect ( key ) } to #{ inspect ( value ) } "
399
408
end
400
409
401
410
defp escape ( contents ) do
402
411
Macro . escape ( contents , unquote: true )
403
412
end
404
413
405
414
defp compile_callbacks ( env , kind ) do
406
- callbacks = Module . get_attribute ( env . module , :"ex_unit_#{ kind } " ) |> Enum . reverse
415
+ callbacks = Module . get_attribute ( env . module , :"ex_unit_#{ kind } " ) |> Enum . reverse ( )
407
416
408
417
acc =
409
418
case callbacks do
410
419
[ ] ->
411
- quote do: context
420
+ quote ( do: context )
421
+
412
422
[ h | t ] ->
413
- Enum . reduce t , compile_merge ( h ) , fn callback_describe , acc ->
423
+ Enum . reduce ( t , compile_merge ( h ) , fn callback_describe , acc ->
414
424
quote do
415
425
context = unquote ( acc )
416
426
unquote ( compile_merge ( callback_describe ) )
417
427
end
418
- end
428
+ end )
419
429
end
420
430
421
431
quote do
0 commit comments