Skip to content

Commit dc0897e

Browse files
author
José Valim
committed
Also allow unquoting on setup and teardown callbacks
1 parent 369fd75 commit dc0897e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/ex_unit/lib/ex_unit/callbacks.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,31 @@ defmodule ExUnit.Callbacks do
8787
defmacro setup(var // quote(do: _), block) do
8888
quote do
8989
name = :"__exunit_setup_#{length(@exunit_setup)}"
90-
defp name, [unquote(Macro.escape var)], [], unquote(Macro.escape block)
90+
defp name, [unquote(escape var)], [], unquote(escape block)
9191
@exunit_setup [name|@exunit_setup]
9292
end
9393
end
9494

9595
defmacro teardown(var // quote(do: _), block) do
9696
quote do
9797
name = :"__exunit_teardown_#{length(@exunit_teardown)}"
98-
defp name, [unquote(Macro.escape var)], [], unquote(Macro.escape block)
98+
defp name, [unquote(escape var)], [], unquote(escape block)
9999
@exunit_teardown [name|@exunit_teardown]
100100
end
101101
end
102102

103103
defmacro setup_all(var // quote(do: _), block) do
104104
quote do
105105
name = :"__exunit_setup_all_#{length(@exunit_setup_all)}"
106-
defp name, [unquote(Macro.escape var)], [], unquote(Macro.escape block)
106+
defp name, [unquote(escape var)], [], unquote(escape block)
107107
@exunit_setup_all [name|@exunit_setup_all]
108108
end
109109
end
110110

111111
defmacro teardown_all(var // quote(do: _), block) do
112112
quote do
113113
name = :"__exunit_teardown_all_#{length(@exunit_teardown_all)}"
114-
defp name, [unquote(Macro.escape var)], [], unquote(Macro.escape block)
114+
defp name, [unquote(escape var)], [], unquote(escape block)
115115
@exunit_teardown_all [name|@exunit_teardown_all]
116116
end
117117
end
@@ -125,6 +125,10 @@ defmodule ExUnit.Callbacks do
125125
" or { :ok, data }, got #{inspect failure} instead"
126126
end
127127

128+
defp escape(contents) do
129+
Macro.escape(contents, escape_unquoted: false)
130+
end
131+
128132
defp compile_callbacks(env, kind) do
129133
callbacks = Module.get_attribute(env.module, kind) |> Enum.reverse
130134

0 commit comments

Comments
 (0)