Skip to content

Commit 90951be

Browse files
author
José Valim
committed
Remove deprecated on_exit callbacks
1 parent 65cf31d commit 90951be

File tree

9 files changed

+12
-47
lines changed

9 files changed

+12
-47
lines changed

lib/elixir/test/elixir/gen_event_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ defmodule GenEventTest do
3030

3131
@receive_timeout 1000
3232

33-
teardown _ do
34-
Process.flag(:trap_exit, false)
35-
:ok
36-
end
37-
3833
test "start_link/2 and handler workflow" do
3934
{:ok, pid} = GenEvent.start_link()
4035

lib/elixir/test/elixir/kernel/lexical_tracker_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ defmodule Kernel.LexicalTrackerTest do
99
{:ok, [pid: D.start_link]}
1010
end
1111

12-
teardown config do
13-
D.stop(config[:pid])
14-
:ok
15-
end
16-
1712
test "can add remote dispatches", config do
1813
D.remote_dispatch(config[:pid], String)
1914
assert D.remotes(config[:pid]) == [String]

lib/elixir/test/elixir/module/locals_tracker_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ defmodule Module.LocalsTrackerTest do
99
{:ok, [pid: D.start_link]}
1010
end
1111

12-
teardown config do
13-
D.stop(config[:pid])
14-
:ok
15-
end
16-
1712
## Locals
1813

1914
test "can add definitions", config do

lib/ex_unit/lib/ex_unit/case.ex

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,10 @@ defmodule ExUnit.Case do
7373
if cd = context[:cd] do
7474
prev_cd = File.cwd!
7575
File.cd!(cd)
76-
{:ok, [prev_cd: prev_cd]}
77-
else
78-
:ok
76+
on_exit fn -> File.cd!(prev_cd) end
7977
end
80-
end
8178
82-
teardown context do
83-
# Revert to the previous working directory
84-
if cd = context[:prev_cd] do
85-
File.cd!(cd)
86-
end
79+
:ok
8780
end
8881
8982
@tag cd: "fixtures"
@@ -93,10 +86,8 @@ defmodule ExUnit.Case do
9386
end
9487
9588
In the example above, we have defined a tag called `:cd` that is
96-
read in the setup callback to configure the working directory the test is
97-
going to run on. We then use the same context to store the
98-
previous working directory that is reverted to after the test
99-
in the teardown callback.
89+
read in the setup callback to configure the working directory the
90+
test is going to run on.
10091
10192
Tags are also very effective when used with case templates
10293
(`ExUnit.CaseTemplate`) allowing callbacks in the case template

lib/ex_unit/lib/ex_unit/formatter.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ defmodule ExUnit.Formatter do
214214
defp with_counter(counter, msg) when counter < 100 do " #{counter}) #{msg}" end
215215
defp with_counter(counter, msg) do "#{counter}) #{msg}" end
216216

217-
defp test_case_info(msg, nil), do: msg <> "failure on setup_all/teardown_all callback, tests invalidated\n"
217+
defp test_case_info(msg, nil), do: msg <> "failure on setup_all callback, tests invalidated\n"
218218
defp test_case_info(msg, formatter), do: test_case_info(formatter.(:test_case_info, msg), nil)
219219

220220
defp test_info(msg, nil), do: msg <> "\n"

lib/ex_unit/test/ex_unit/formatter_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ defmodule ExUnit.FormatterTest do
103103
test "formats test case errors" do
104104
failure = {:error, catch_error(raise "oops"), []}
105105
assert format_test_case_failure(case(), failure, 1, 80, &formatter/2) =~ """
106-
1) Hello: failure on setup_all/teardown_all callback, tests invalidated
106+
1) Hello: failure on setup_all callback, tests invalidated
107107
** (RuntimeError) oops
108108
"""
109109
end
110110

111111
test "formats assertions with operators with no limit" do
112112
failure = {:error, catch_assertion(assert [1, 2, 3] == [4, 5, 6]), []}
113113
assert format_test_case_failure(case(), failure, 1, :infinity, &formatter/2) =~ """
114-
1) Hello: failure on setup_all/teardown_all callback, tests invalidated
114+
1) Hello: failure on setup_all callback, tests invalidated
115115
Assertion with == failed
116116
code: [1, 2, 3] == [4, 5, 6]
117117
lhs: [1, 2, 3]
@@ -122,7 +122,7 @@ defmodule ExUnit.FormatterTest do
122122
test "formats assertions with operators with column limit" do
123123
failure = {:error, catch_assertion(assert [1, 2, 3] == [4, 5, 6]), []}
124124
assert format_test_case_failure(case(), failure, 1, 15, &formatter/2) =~ """
125-
1) Hello: failure on setup_all/teardown_all callback, tests invalidated
125+
1) Hello: failure on setup_all callback, tests invalidated
126126
Assertion with == failed
127127
code: [1, 2, 3] == [4, 5, 6]
128128
lhs: [1,

lib/iex/test/test_helper.exs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ defmodule IEx.Case do
3434
setup do
3535
opts = IEx.configuration |>
3636
Keyword.take([:default_prompt, :alive_prompt, :inspect, :colors, :history_size])
37-
{:ok, [iex_opts: opts]}
38-
end
39-
40-
teardown context do
41-
IEx.configure context[:iex_opts]
37+
on_exit fn -> IEx.configure(opts) end
4238
:ok
4339
end
4440

lib/mix/test/mix/rebar_test.exs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ defmodule Mix.RebarTest do
1919
setup do
2020
available = Mix.SCM.available
2121
Application.put_env(:mix, :scm, [Mix.SCM.Git, MyPath])
22-
{:ok, [scm: available]}
23-
end
24-
25-
teardown context do
26-
Application.put_env(:mix, :scm, context[:scm])
22+
on_exit fn -> Application.put_env(:mix, :scm, available) end
2723
:ok
2824
end
2925

lib/mix/test/mix/scm_test.exs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ defmodule Mix.SCMTest do
44
use MixTest.Case
55

66
setup do
7-
{:ok, [scm: Mix.SCM.available]}
8-
end
9-
10-
teardown context do
11-
Application.put_env(:mix, :scm, context[:scm])
7+
available = Mix.SCM.available
8+
on_exit fn -> Application.put_env(:mix, :scm, available) end
129
:ok
1310
end
1411

0 commit comments

Comments
 (0)