Skip to content

Commit cb43070

Browse files
committed
Preserve variable metadata during collection from assertion pattern
Closes #4174.
1 parent 6aaa4bb commit cb43070

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ defmodule ExUnit.Assertions do
102102
# is not nil nor false. We need to rewrite the if
103103
# to avoid silly warnings though.
104104
return =
105-
no_warning(quote do
106-
if right do
107-
right
108-
else
109-
raise ExUnit.AssertionError,
110-
expr: expr,
111-
message: "Expected truthy, got #{inspect right}"
112-
end
113-
end)
105+
no_warning(quote do
106+
if right do
107+
right
108+
else
109+
raise ExUnit.AssertionError,
110+
expr: expr,
111+
message: "Expected truthy, got #{inspect right}"
112+
end
113+
end)
114114

115115
quote do
116116
right = unquote(right)
@@ -408,8 +408,8 @@ defmodule ExUnit.Assertions do
408408
{:ok, acc}
409409
{:_, _, context}, acc when is_atom(context) ->
410410
{:ok, acc}
411-
{name, _, context}, acc when is_atom(name) and is_atom(context) ->
412-
{:ok, [{name, [generated: true], context}|acc]}
411+
{name, meta, context}, acc when is_atom(name) and is_atom(context) ->
412+
{:ok, [{name, [generated: true] ++ meta, context} | acc]}
413413
node, acc ->
414414
{node, acc}
415415
end)

lib/ex_unit/test/ex_unit/assertions_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ alias ExUnit.AssertionsTest.Value
1111
defmodule ExUnit.AssertionsTest do
1212
use ExUnit.Case, async: true
1313

14+
defmacrop assert_ok(arg) do
15+
quote do
16+
assert {:ok, val} = ok(unquote(arg))
17+
end
18+
end
19+
20+
test "assert inside macro" do
21+
assert_ok 42
22+
end
23+
1424
test "assert with true value" do
1525
true = assert Value.truthy
1626
end

0 commit comments

Comments
 (0)