Skip to content

Commit 980dbc9

Browse files
committed
Fix ExUnit.Assertions receive macros compiler warnings
Previously receive macros would produce warnings when a message was supplied.
1 parent 3139168 commit 980dbc9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,16 @@ defmodule ExUnit.Assertions do
305305

306306
defp do_assert_receive(expected, timeout, message) do
307307
binary = Macro.to_string(expected)
308+
message = message ||
309+
"Expected to have received message matching #{binary}"
308310

309311
{ :receive, meta, args } =
310312
quote do
311313
receive do
312314
unquote(expected) = received -> received
313315
after
314316
unquote(timeout) ->
315-
flunk unquote(message) || "Expected to have received message matching #{unquote binary}"
317+
flunk unquote(message)
316318
end
317319
end
318320

@@ -488,18 +490,31 @@ defmodule ExUnit.Assertions do
488490
end
489491

490492
defp do_refute_receive(not_expected, timeout, message) do
491-
binary = Macro.to_string(not_expected)
493+
receive_clause = refute_receive_recv(not_expected, message)
492494

493495
quote do
494496
receive do
495-
unquote(not_expected) = actual ->
496-
flunk unquote(message) || "Expected to not have received message matching #{unquote binary}, got #{inspect actual}"
497+
unquote(receive_clause)
497498
after
498499
unquote(timeout) -> false
499500
end
500501
end
501502
end
502503

504+
defp refute_receive_recv(not_expected, nil) do
505+
binary = Macro.to_string(not_expected)
506+
quote do
507+
unquote(not_expected) = actual ->
508+
flunk "Expected to not have received message matching #{unquote binary}, got #{inspect actual}"
509+
end
510+
end
511+
512+
defp refute_receive_recv(not_expected, message) do
513+
quote do
514+
unquote(not_expected) -> flunk unquote(message)
515+
end
516+
end
517+
503518
@doc """
504519
Asserts the `expected` and `received` are not within `delta`.
505520

0 commit comments

Comments
 (0)