Skip to content

Commit adf7834

Browse files
author
José Valim
committed
Ensure ExUnit doesn't hang on linked failures
Thanks to @pminten for reporting this issue.
1 parent c837d8e commit adf7834

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed

lib/ex_unit/lib/ex_unit/formatter.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ defmodule ExUnit.Formatter do
131131
location_info("at #{location[:file]}:#{location[:line]}", color)
132132
end
133133

134+
defp format_stacktrace([], _case, _test, _color) do
135+
""
136+
end
137+
134138
defp format_stacktrace(stacktrace, _case, _test, color) do
135139
location_info("stacktrace:", color) <>
136140
Enum.map_join(stacktrace, fn(s) -> stacktrace_info format_stacktrace_entry(s), color end)

lib/ex_unit/lib/ex_unit/runner.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ defmodule ExUnit.Runner do
138138
receive do
139139
{ ^case_pid, :case_finished, test_case, tests } ->
140140
{ test_case, tests }
141-
{ :DOWN, ^case_ref, :process, ^case_pid, { error, stacktrace } } ->
142-
{ test_case.state({ :failed, { :EXIT, error, prune_stacktrace(stacktrace) } }), [] }
141+
{ :DOWN, ^case_ref, :process, ^case_pid, error } ->
142+
{ test_case.state({ :failed, { :EXIT, error, [] } }), [] }
143143
end
144144
end
145145

@@ -187,8 +187,8 @@ defmodule ExUnit.Runner do
187187
receive do
188188
{ ^test_pid, :test_finished, test } ->
189189
test
190-
{ :DOWN, ^test_ref, :process, ^test_pid, { error, stacktrace } } ->
191-
test.state { :failed, { :EXIT, error, prune_stacktrace(stacktrace) } }
190+
{ :DOWN, ^test_ref, :process, ^test_pid, error } ->
191+
test.state { :failed, { :EXIT, error, [] } }
192192
end
193193
end
194194

lib/ex_unit/test/ex_unit/formatter_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ defmodule ExUnit.FormatterTest do
2929
assert format_test_failure(Hello, :world, failure, 1, nil) =~ """
3030
1) world (Hello)
3131
** (RuntimeError) oops
32-
stacktrace:
3332
"""
3433
end
3534

@@ -38,7 +37,6 @@ defmodule ExUnit.FormatterTest do
3837
assert format_test_failure(Hello, :world, failure, 1, nil) == """
3938
1) world (Hello)
4039
** (exit) 1
41-
stacktrace:
4240
"""
4341
end
4442

@@ -47,7 +45,6 @@ defmodule ExUnit.FormatterTest do
4745
assert format_test_failure(Hello, :world, failure, 1, nil) == """
4846
1) world (Hello)
4947
** (throw) 1
50-
stacktrace:
5148
"""
5249
end
5350

@@ -58,7 +55,6 @@ defmodule ExUnit.FormatterTest do
5855
** (ExUnit.ExpectationError)
5956
expected: 1
6057
to be equal to (==): 2
61-
stacktrace:
6258
"""
6359
end
6460

@@ -70,7 +66,6 @@ defmodule ExUnit.FormatterTest do
7066
expected: ExUnit.FormatterTest.falsy()
7167
to be: true
7268
instead got: false
73-
stacktrace:
7469
"""
7570
end
7671

@@ -98,7 +93,6 @@ defmodule ExUnit.FormatterTest do
9893
assert format_test_case_failure(Hello, failure, 1, nil) =~ """
9994
1) Hello: failure on setup_all/teardown_all callback, tests invalidated
10095
** (RuntimeError) oops
101-
stacktrace:
10296
"""
10397
end
10498
end

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,6 @@
11
Code.require_file "test_helper.exs", __DIR__
22

3-
defmodule ExUnit.NilFormatter do
4-
@behaviour ExUnit.Formatter
5-
6-
def suite_started(_opts) do
7-
:ok
8-
end
9-
10-
def suite_finished(:ok, _run_us, _load_us) do
11-
1
12-
end
13-
14-
def case_started(:ok, _test_case) do
15-
:ok
16-
end
17-
18-
def case_finished(:ok, _test_case) do
19-
:ok
20-
end
21-
22-
def test_started(:ok, _test) do
23-
:ok
24-
end
25-
26-
def test_finished(:ok, _test) do
27-
:ok
28-
end
29-
end
30-
31-
defmodule ExUnit.TestsCounterFormatter do
3+
defmodule ExUnit.CounterFormatter do
324
@timeout 30_000
335
@behaviour ExUnit.Formatter
346

@@ -79,9 +51,17 @@ end
7951
defmodule ExUnitTest do
8052
use ExUnit.Case, async: false
8153

82-
test "it supports many runs" do
83-
ExUnit.configure(formatter: ExUnit.NilFormatter)
54+
setup do
55+
ExUnit.configure(formatter: ExUnit.CounterFormatter)
56+
:ok
57+
end
8458

59+
teardown do
60+
ExUnit.configure(formatter: ExUnit.CLIFormatter)
61+
:ok
62+
end
63+
64+
test "it supports many runs" do
8565
defmodule SampleTest do
8666
use ExUnit.Case, async: false
8767

@@ -94,12 +74,25 @@ defmodule ExUnitTest do
9474
end
9575
end
9676

77+
assert ExUnit.run == 2
78+
end
79+
80+
test "it doesn't hang on exists" do
81+
defmodule EventServerTest do
82+
use ExUnit.Case, async: false
83+
84+
test "spawn and crash" do
85+
Process.spawn_link(fn ->
86+
exit :foo
87+
end)
88+
receive after: (1000 -> :ok)
89+
end
90+
end
91+
9792
assert ExUnit.run == 1
9893
end
9994

10095
test "filtering cases with tags" do
101-
ExUnit.configure(formatter: ExUnit.TestsCounterFormatter)
102-
10396
defmodule ParityTest do
10497
use ExUnit.Case
10598

0 commit comments

Comments
 (0)