Skip to content

Commit dc9a47d

Browse files
author
José Valim
committed
Do not warn on case template teardown/teardown_all definition
1 parent 2d1cf2e commit dc9a47d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/ex_unit/lib/ex_unit/callbacks.ex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ defmodule ExUnit.Callbacks do
129129
end
130130

131131
@doc false
132-
defmacro teardown(var \\ quote(do: _), block) do
133-
IO.write :stderr, "teardown in ExUnit is deprecated, please use on_exit/1 instead\n" <>
134-
Exception.format_stacktrace(Macro.Env.stacktrace(__CALLER__))
132+
defmacro teardown(var \\ quote(do: _), warn \\ true, block) do
133+
if warn do
134+
IO.write :stderr, "teardown in ExUnit is deprecated, please use on_exit/1 instead\n" <>
135+
Exception.format_stacktrace(Macro.Env.stacktrace(__CALLER__))
136+
end
135137
quote bind_quoted: [var: escape(var), block: escape(block)] do
136138
name = :"__ex_unit_teardown_#{length(@ex_unit_teardown)}"
137139
defp unquote(name)(unquote(var)), unquote(block)
@@ -140,9 +142,11 @@ defmodule ExUnit.Callbacks do
140142
end
141143

142144
@doc false
143-
defmacro teardown_all(var \\ quote(do: _), block) do
144-
IO.write :stderr, "teardown_all in ExUnit is deprecated, please use on_exit/1 instead\n" <>
145-
Exception.format_stacktrace(Macro.Env.stacktrace(__CALLER__))
145+
defmacro teardown_all(var \\ quote(do: _), warn \\ true, block) do
146+
if warn do
147+
IO.write :stderr, "teardown_all in ExUnit is deprecated, please use on_exit/1 instead\n" <>
148+
Exception.format_stacktrace(Macro.Env.stacktrace(__CALLER__))
149+
end
146150
quote bind_quoted: [var: escape(var), block: escape(block)] do
147151
name = :"__ex_unit_teardown_all_#{length(@ex_unit_teardown_all)}"
148152
defp unquote(name)(unquote(var)), unquote(block)

lib/ex_unit/lib/ex_unit/case_template.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule ExUnit.CaseTemplate do
33
This module allows a developer to define a test case
44
template to be used throughout his tests. This is useful
55
when there are a set of functions that should be shared
6-
between tests or a set of setup/teardown callbacks.
6+
between tests or a set of setup callbacks.
77
88
By using this module, the callbacks and assertions
99
available for regular test cases will also be available.
@@ -57,12 +57,12 @@ defmodule ExUnit.CaseTemplate do
5757
unquote(module).__ex_unit__(:setup, context)
5858
end
5959

60-
teardown context do
61-
unquote(module).__ex_unit__(:teardown, context)
60+
teardown_all context, false do
61+
unquote(module).__ex_unit__(:teardown_all, context)
6262
end
6363

64-
teardown_all context do
65-
unquote(module).__ex_unit__(:teardown_all, context)
64+
teardown context, false do
65+
unquote(module).__ex_unit__(:teardown, context)
6666
end
6767
end
6868
end

0 commit comments

Comments
 (0)