Skip to content

Commit b1cbe7a

Browse files
Send warnings to stderr in Erlang compiler (#14437)
Aligns compiler to these changes: erlang/otp#9363 Related PR: #14018
1 parent 97ee6b0 commit b1cbe7a

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

Diff for: lib/mix/lib/mix/compilers/erlang.ex

+3-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ defmodule Mix.Compilers.Erlang do
316316
for {_, warnings} <- entries,
317317
{file, issues} <- warnings,
318318
{location, module, message} <- issues do
319-
IO.puts("#{file}:#{location_to_string(location)} warning: #{module.format_error(message)}")
319+
message = "#{file}:#{location_to_string(location)} warning: #{module.format_error(message)}"
320+
321+
IO.puts(:stderr, message)
320322
end
321323
end
322324

Diff for: lib/mix/test/mix/tasks/compile.erlang_test.exs

+20-18
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,24 @@ defmodule Mix.Tasks.Compile.ErlangTest do
134134
severity: :warning
135135
} = diagnostic
136136

137-
# Should return warning without recompiling file
138-
assert {:noop, [^diagnostic]} = Mix.Tasks.Compile.Erlang.run(["--verbose"])
139-
refute_received {:mix_shell, :info, ["Compiled src/has_warning.erl"]}
140-
141-
assert [^diagnostic] = Mix.Tasks.Compile.Erlang.diagnostics()
142-
assert [^diagnostic] = Mix.Task.Compiler.diagnostics()
143-
144-
# Should not return warning after changing file
145-
File.write!(file, """
146-
-module(has_warning).
147-
-export([my_fn/0]).
148-
my_fn() -> ok.
149-
""")
150-
151-
ensure_touched(file)
152-
assert {:ok, []} = Mix.Tasks.Compile.Erlang.run([])
137+
capture_io(:stderr, fn ->
138+
# Should return warning without recompiling file
139+
assert {:noop, [^diagnostic]} = Mix.Tasks.Compile.Erlang.run(["--verbose"])
140+
refute_received {:mix_shell, :info, ["Compiled src/has_warning.erl"]}
141+
142+
assert [^diagnostic] = Mix.Tasks.Compile.Erlang.diagnostics()
143+
assert [^diagnostic] = Mix.Task.Compiler.diagnostics()
144+
145+
# Should not return warning after changing file
146+
File.write!(file, """
147+
-module(has_warning).
148+
-export([my_fn/0]).
149+
my_fn() -> ok.
150+
""")
151+
152+
ensure_touched(file)
153+
assert {:ok, []} = Mix.Tasks.Compile.Erlang.run([])
154+
end)
153155
end)
154156
end)
155157
end
@@ -165,11 +167,11 @@ defmodule Mix.Tasks.Compile.ErlangTest do
165167

166168
capture_io(fn -> Mix.Tasks.Compile.Erlang.run([]) end)
167169

168-
assert capture_io(fn ->
170+
assert capture_io(:stderr, fn ->
169171
assert {:noop, _} = Mix.Tasks.Compile.Erlang.run([])
170172
end) =~ ~r"has_warning.erl:2:(1:)? warning: function my_fn/0 is unused\n"
171173

172-
assert capture_io(fn ->
174+
assert capture_io(:stderr, fn ->
173175
assert {:noop, _} = Mix.Tasks.Compile.Erlang.run([])
174176
end) =~ ~r"has_warning.erl:2:(1:)? warning: function my_fn/0 is unused\n"
175177

0 commit comments

Comments
 (0)