Skip to content

Commit 7b4576f

Browse files
committed
Consider variables are on different lines in assert_receive
1 parent 9192907 commit 7b4576f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,10 @@ defmodule ExUnit.Assertions do
429429

430430
defp collect_vars_from_pattern({:when, _, [left, right]}) do
431431
pattern = collect_vars_from_pattern(left)
432-
guards = for var <- collect_vars_from_pattern(right), var in pattern, do: var
433-
pattern ++ guards
432+
for {name, _, context} = var <- collect_vars_from_pattern(right),
433+
Enum.any?(pattern, &match?({^name, _, ^context}, &1)),
434+
into: pattern,
435+
do: var
434436
end
435437

436438
defp collect_vars_from_pattern(expr) do

lib/ex_unit/test/ex_unit/assertions_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ defmodule ExUnit.AssertionsTest do
267267
end
268268

269269
test "assert received does not leak external variables used in guards" do
270-
send self, {:hello, :world}
270+
send self(), {:hello, :world}
271271
guard_world = :world
272272
assert_received {:hello, world} when world == guard_world
273273
:world = world

0 commit comments

Comments
 (0)