Skip to content

Commit c377483

Browse files
author
José Valim
committed
Ensure mix test print app name for umbrella
1 parent 3ded858 commit c377483

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

lib/mix/lib/mix/project_stack.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ defmodule Mix.ProjectStack do
5555
end
5656
end
5757

58-
@spec output_app?() :: boolean
59-
def output_app? do
58+
@spec print_app?() :: boolean
59+
def print_app? do
6060
get_and_update fn %{stack: stack} = state ->
6161
case stack do
6262
[h|t] ->

lib/mix/lib/mix/shell.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ defmodule Mix.Shell do
3232
defcallback cmd(command :: String.t) :: integer
3333

3434
@doc """
35-
Returns if we should output application name to shell.
35+
Prints the current application to shell if
36+
it was not printed yet.
37+
"""
38+
defcallback print_app() :: any
39+
40+
@doc """
41+
Returns if we should print application name to shell.
42+
3643
Calling this function automatically toggles its value
3744
to false.
3845
"""
39-
def output_app? do
40-
Mix.ProjectStack.output_app?
46+
def print_app? do
47+
Mix.ProjectStack.print_app?
4148
end
4249

4350
@doc """

lib/mix/lib/mix/shell/io.ex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,38 @@ defmodule Mix.Shell.IO do
66

77
@behaviour Mix.Shell
88

9+
@doc """
10+
Prints the currently running application if it
11+
was not printed yet.
12+
"""
13+
def print_app do
14+
if Mix.Shell.print_app? do
15+
IO.puts "==> #{Mix.Project.config[:app]}"
16+
end
17+
end
18+
919
@doc """
1020
Executes the given command and prints its output
1121
to stdout as it comes.
1222
"""
1323
def cmd(command) do
14-
put_app
24+
print_app
1525
Mix.Shell.cmd(command, &IO.write(&1))
1626
end
1727

1828
@doc """
1929
Writes a message to the shell followed by new line.
2030
"""
2131
def info(message) do
22-
put_app
32+
print_app
2333
IO.puts IO.ANSI.escape(message)
2434
end
2535

2636
@doc """
2737
Writes an error message to the shell followed by new line.
2838
"""
2939
def error(message) do
30-
put_app
40+
print_app
3141
IO.puts :stderr, IO.ANSI.escape "%{red,bright}#{message}"
3242
end
3343

@@ -36,7 +46,7 @@ defmodule Mix.Shell.IO do
3646
input. Input will be consumed until enter is pressed.
3747
"""
3848
def prompt(message) do
39-
put_app
49+
print_app
4050
IO.gets IO.ANSI.escape(message <> " ")
4151
end
4252

@@ -46,7 +56,7 @@ defmodule Mix.Shell.IO do
4656
regex `~r/^Y(es)?$/i`.
4757
"""
4858
def yes?(message) do
49-
put_app
59+
print_app
5060
got_yes? IO.gets(message <> IO.ANSI.escape(" [Yn] "))
5161
end
5262

@@ -56,10 +66,4 @@ defmodule Mix.Shell.IO do
5666

5767
# The io server may return :eof or :error
5868
defp got_yes?(_), do: false
59-
60-
defp put_app do
61-
if Mix.Shell.output_app? do
62-
IO.puts "==> #{Mix.Project.config[:app]}"
63-
end
64-
end
6569
end

lib/mix/lib/mix/shell/process.ex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,22 @@ defmodule Mix.Shell.Process do
3939
end
4040
end
4141

42+
@doc """
43+
Prints the currently running application if it
44+
was not printed yet.
45+
"""
46+
def print_app do
47+
if Mix.Shell.print_app? do
48+
send self, {:mix_shell, :info, ["==> #{Mix.Project.config[:app]}"]}
49+
end
50+
end
51+
4252
@doc """
4353
Executes the given command and forwards its messages to
4454
the current process.
4555
"""
4656
def cmd(command) do
47-
put_app
57+
print_app
4858
Mix.Shell.cmd(command, fn(data) ->
4959
send self, {:mix_shell, :run, [data]}
5060
end)
@@ -54,15 +64,15 @@ defmodule Mix.Shell.Process do
5464
Forwards the message to the current process.
5565
"""
5666
def info(message) do
57-
put_app
67+
print_app
5868
send self, {:mix_shell, :info, [IO.ANSI.escape(message, false)]}
5969
end
6070

6171
@doc """
6272
Forwards the message to the current process.
6373
"""
6474
def error(message) do
65-
put_app
75+
print_app
6676
send self, {:mix_shell, :error, [IO.ANSI.escape(message, false)]}
6777
end
6878

@@ -76,7 +86,7 @@ defmodule Mix.Shell.Process do
7686
process inputs given. Value must be a string.
7787
"""
7888
def prompt(message) do
79-
put_app
89+
print_app
8090
send self, {:mix_shell, :prompt, [IO.ANSI.escape(message, false)]}
8191

8292
receive do
@@ -96,7 +106,7 @@ defmodule Mix.Shell.Process do
96106
process inputs given. Value must be `true` or `false`.
97107
"""
98108
def yes?(message) do
99-
put_app
109+
print_app
100110
send self, {:mix_shell, :yes?, [IO.ANSI.escape(message, false)]}
101111

102112
receive do
@@ -105,10 +115,4 @@ defmodule Mix.Shell.Process do
105115
0 -> raise "No shell process input given for yes?/1"
106116
end
107117
end
108-
109-
defp put_app do
110-
if Mix.Shell.output_app? do
111-
send self, {:mix_shell, :info, ["==> #{Mix.Project.config[:app]}"]}
112-
end
113-
end
114118
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ defmodule Mix.Tasks.Test do
152152
# before requiring test_helper.exs so that the configuration is
153153
# available in test_helper.exs. Then configure exunit again so
154154
# that command line options override test_helper.exs
155+
Mix.shell.print_app
155156
Mix.Task.run "app.start", args
156157
Application.load(:ex_unit)
157158

0 commit comments

Comments
 (0)