Skip to content

Commit 7f59aee

Browse files
ericentinJosé Valim
authored andcommitted
mix test --listen-on-stdin will no longer exit on failure (#4930)
Signed-off-by: José Valim <[email protected]>
1 parent e2abd35 commit 7f59aee

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

lib/mix/lib/mix/tasks/test.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ defmodule Mix.Tasks.Test do
175175
def run(args) do
176176
{opts, files} = OptionParser.parse!(args, strict: @switches)
177177

178+
if opts[:listen_on_stdin] do
179+
System.at_exit fn _ ->
180+
IO.gets(:stdio, "")
181+
Mix.shell.info "Restarting..."
182+
:init.restart()
183+
:timer.sleep(:infinity)
184+
end
185+
end
186+
178187
unless System.get_env("MIX_ENV") || Mix.env == :test do
179188
Mix.raise "\"mix test\" is running on environment \"#{Mix.env}\". If you are " <>
180189
"running tests along another task, please set MIX_ENV explicitly"
@@ -246,13 +255,6 @@ defmodule Mix.Tasks.Test do
246255
:noop ->
247256
:ok
248257
end
249-
250-
if opts[:listen_on_stdin] do
251-
IO.gets(:stdio, "")
252-
Mix.shell.info "Restarting..."
253-
:init.restart()
254-
:timer.sleep(:infinity)
255-
end
256258
end
257259

258260
defp display_warn_test_pattern(files, pattern) do

lib/mix/test/mix/tasks/test_test.exs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,58 @@ defmodule Mix.Tasks.TestTest do
116116
end
117117
end
118118

119+
test "--listen-on-stdin: does not exit on compilation failure" do
120+
in_fixture "test_stale", fn ->
121+
File.write!("lib/b.ex", """
122+
defmodule B do
123+
def f, do: error_not_a_var
124+
end
125+
""")
126+
127+
port = mix_port(~w[test --listen-on-stdin])
128+
129+
assert receive_until_match(port, "error", []) =~ "lib/b.ex"
130+
131+
File.write!("lib/b.ex", """
132+
defmodule B do
133+
def f, do: A.f
134+
end
135+
""")
136+
137+
Port.command(port, "\n")
138+
139+
assert receive_until_match(port, "seed", []) =~ "2 tests"
140+
141+
File.write!("test/b_test_stale.exs", """
142+
defmodule BTest do
143+
use ExUnit.Case
144+
145+
test "f" do
146+
assert B.f() == error_not_a_var
147+
end
148+
end
149+
""")
150+
151+
Port.command(port, "\n")
152+
153+
assert receive_until_match(port, "undefined function error_not_a_var", []) =~ "test/b_test_stale.exs"
154+
155+
File.write!("test/b_test_stale.exs", """
156+
defmodule BTest do
157+
use ExUnit.Case
158+
159+
test "f" do
160+
assert B.f() == :ok
161+
end
162+
end
163+
""")
164+
165+
Port.command(port, "\n")
166+
167+
assert receive_until_match(port, "seed", []) =~ "2 tests"
168+
end
169+
end
170+
119171
defp receive_until_match(port, expected, acc) do
120172
receive do
121173
{^port, {:data, charlist}} ->

0 commit comments

Comments
 (0)