Skip to content

Commit 91b5f83

Browse files
authored
Fix async_test behaviour under for/Enum (#72)
* Fix async_test behaviour under for/Enum * don't require unquote in async_test name
1 parent a7d474e commit 91b5f83

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

test/support/async.ex

+19-11
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ defmodule Support.Async do
1313
end,
1414
do: block
1515
) do
16-
id = :crypto.strong_rand_bytes(12) |> Base.encode16()
17-
test_module_name = Module.concat(__CALLER__.module, "AsyncTest_#{id}")
18-
fun_name = :"async_test_#{id}"
19-
after_compile_fun_name = :"async_test_ac_#{id}"
20-
2116
quote do
17+
id = :crypto.strong_rand_bytes(12) |> Base.encode16()
18+
test_module_name = Module.concat(__MODULE__, "AsyncTest_#{id}")
19+
fun_name = :"async_test_#{id}"
20+
after_compile_fun_name = :"async_test_ac_#{id}"
21+
2222
@tags_attrs [:tag, :describetag, :moduletag]
2323
|> Enum.flat_map(fn attr ->
2424
Module.get_attribute(__MODULE__, attr)
2525
|> Enum.map(&{attr, &1})
2626
end)
2727

28-
def unquote(fun_name)(unquote(context)) do
28+
def unquote(unquoted_var(:fun_name))(unquote(context)) do
2929
unquote(block)
3030
end
3131

32-
def unquote(after_compile_fun_name)(_bytecode, _env) do
33-
test_name = unquote(test_name)
34-
fun_name = unquote(fun_name)
32+
def unquote(unquoted_var(:after_compile_fun_name))(_bytecode, _env) do
33+
test_name = unquote(unquoted(test_name))
34+
fun_name = unquote(unquoted_var(:fun_name))
3535

3636
content =
3737
quote do
@@ -46,12 +46,20 @@ defmodule Support.Async do
4646
end
4747
end
4848

49-
Module.create(unquote(test_module_name), content, __ENV__)
49+
Module.create(unquote(unquoted_var(:test_module_name)), content, __ENV__)
5050
end
5151

52-
@after_compile {__MODULE__, unquote(after_compile_fun_name)}
52+
@after_compile {__MODULE__, after_compile_fun_name}
5353

5454
Module.delete_attribute(__MODULE__, :tag)
5555
end
5656
end
57+
58+
defp unquoted_var(name) do
59+
unquoted(Macro.var(name, __MODULE__))
60+
end
61+
62+
defp unquoted(ast) do
63+
{:unquote, [], [ast]}
64+
end
5765
end

0 commit comments

Comments
 (0)