Skip to content

Commit 7dd0aab

Browse files
author
José Valim
committed
Deprecate ExUnit.after_spawn callbacks
1 parent 658d7c7 commit 7dd0aab

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* enhancements
22
* [ExUnit] Tests can now receive metadata set on setup/teardown callbacks
3+
* [ExUnit] Add support to ExUnit.CaseTemplate to share callbacks in between test cases
34
* [IO] Add `IO.ANSI` to make it easy to write ANSI escape codes
45
* [Kernel] Better support for Unicode lists
56
* [Kernel] Reduce variables footprint in `case`/`receive` clauses

Diff for: lib/ex_unit/lib/ex_unit.ex

+3-4
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ defmodule ExUnit do
129129
ExUnit.Server.merge_options(options)
130130
end
131131

132-
@doc """
133-
Registers a callback to be invoked every time a
134-
new ExUnit process is spawned.
135-
"""
132+
@doc false
136133
def after_spawn(callback) do
134+
IO.puts "ExUnit.after_spawn is deprecated, please use setup_all instead"
135+
Exception.print_stacktrace
137136
ExUnit.Server.add_after_spawn(callback)
138137
end
139138

Diff for: lib/ex_unit/test/ex_unit_test.exs

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ end
3131
defmodule ExUnitTest do
3232
use ExUnit.Case, async: false
3333

34-
test "it runs after_spawn hooks" do
35-
assert Process.get(:after_spawn) == :ex_unit
36-
end
37-
3834
test "it can read user config" do
3935
File.write("ex_unit.test.config","[extra_option: true]")
4036
assert ExUnit.user_options("nosuchfile.config") == []

Diff for: lib/ex_unit/test/test_helper.exs

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# Configure ExUnit, no options supported yet.
21
ExUnit.start []
3-
ExUnit.after_spawn fn -> Process.put(:after_spawn, :ex_unit) end

Diff for: lib/mix/test/test_helper.exs

+13-12
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,24 @@ Enum.each [:invalidapp, :invalidvsn, :noappfile, :ok], fn(dep) ->
4747
end
4848

4949
defmodule MixTest.Case do
50-
defmacro __using__(opts) do
50+
use ExUnit.CaseTemplate
51+
52+
using do
5153
quote do
52-
use ExUnit.Case, unquote(opts)
5354
import MixTest.Case
54-
55-
teardown do
56-
Mix.env(:dev)
57-
Mix.Task.clear
58-
Mix.Shell.Process.flush
59-
Mix.Deps.Converger.clear_cache
60-
System.put_env("MIX_HOME", tmp_path(".mix"))
61-
del_tmp_paths
62-
:ok
63-
end
6455
end
6556
end
6657

58+
teardown do
59+
Mix.env(:dev)
60+
Mix.Task.clear
61+
Mix.Shell.Process.flush
62+
Mix.Deps.Converger.clear_cache
63+
System.put_env("MIX_HOME", tmp_path(".mix"))
64+
del_tmp_paths
65+
:ok
66+
end
67+
6768
def mix(args) do
6869
System.cmd "#{elixir_executable} #{mix_executable} #{args}"
6970
end

0 commit comments

Comments
 (0)