@@ -109,7 +109,7 @@ defmodule ExUnit.Assertions do
109
109
# is not nil nor false. We need to rewrite the if
110
110
# to avoid silly warnings though.
111
111
return =
112
- no_warning ( quote do
112
+ suppress_warning ( quote do
113
113
case right do
114
114
x when x in [ nil , false ] ->
115
115
raise ExUnit.AssertionError ,
@@ -121,7 +121,7 @@ defmodule ExUnit.Assertions do
121
121
end )
122
122
123
123
match_expr =
124
- no_warning ( quote do
124
+ suppress_warning ( quote do
125
125
case right do
126
126
unquote ( left ) ->
127
127
unquote ( return )
@@ -401,6 +401,40 @@ defmodule ExUnit.Assertions do
401
401
quote ( do: unquote ( left ) = received )
402
402
end
403
403
404
+ pattern_finder =
405
+ quote do
406
+ fn message ->
407
+ unquote ( suppress_warning ( quote do
408
+ case message do
409
+ unquote ( pattern ) ->
410
+ _ = unquote ( vars )
411
+ true
412
+
413
+ _ ->
414
+ false
415
+ end
416
+ end ) )
417
+ end
418
+ end
419
+
420
+ failure_message_hit =
421
+ failure_message || quote do
422
+ """
423
+ Found message matching #{ unquote ( binary ) } after #{ timeout } ms.
424
+
425
+ This means the message was delivered too close to the timeout value, you may want to either:
426
+
427
+ 1. Give an increased timeout to `assert_receive/2`
428
+ 2. Increase the default timeout to all `assert_receive` in your
429
+ test_helper.exs by setting ExUnit.configure(assert_receive_timeout: ...)
430
+ """
431
+ end
432
+
433
+ failure_message_miss =
434
+ failure_message || quote do
435
+ "No message matching #{ unquote ( binary ) } after #{ timeout } ms."
436
+ end
437
+
404
438
quote do
405
439
timeout = unquote ( timeout )
406
440
@@ -412,29 +446,10 @@ defmodule ExUnit.Assertions do
412
446
timeout ->
413
447
{ :messages , messages } = Process . info ( self ( ) , :messages )
414
448
415
- pattern_finder = fn message ->
416
- case message do
417
- unquote ( pattern ) ->
418
- _ = unquote ( vars )
419
- true
420
- _ ->
421
- false
422
- end
423
- end
424
-
425
- if Enum . any? ( messages , pattern_finder ) do
426
- flunk ( unquote ( failure_message ) || """
427
- Found message matching #{ unquote ( binary ) } after #{ timeout } ms.
428
-
429
- This means the message was delivered too close to the timeout value, you may want to either:
430
-
431
- 1. Give an increased timeout to `assert_receive/2`
432
- 2. Increase the default timeout to all `assert_receive` in your
433
- test_helper.exs by setting ExUnit.configure(assert_receive_timeout: ...)
434
- """ )
449
+ if Enum . any? ( messages , unquote ( pattern_finder ) ) do
450
+ flunk ( unquote ( failure_message_hit ) )
435
451
else
436
- failure_message = unquote ( failure_message ) || "No message matching #{ unquote ( binary ) } after #{ timeout } ms."
437
- flunk ( failure_message <>
452
+ flunk ( unquote ( failure_message_miss ) <>
438
453
ExUnit.Assertions . __pins__ ( unquote ( pins ) ) <>
439
454
ExUnit.Assertions . __mailbox__ ( messages ) )
440
455
end
@@ -515,7 +530,7 @@ defmodule ExUnit.Assertions do
515
530
|> elem ( 1 )
516
531
end
517
532
518
- defp no_warning ( { name , meta , [ expr , [ do: clauses ] ] } ) do
533
+ defp suppress_warning ( { name , meta , [ expr , [ do: clauses ] ] } ) do
519
534
clauses = Enum . map clauses , fn { :-> , meta , args } ->
520
535
{ :-> , [ generated: true ] ++ meta , args }
521
536
end
0 commit comments