Skip to content

Send warnings to stderr in Erlang compiler #14437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mix/lib/mix/compilers/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ defmodule Mix.Compilers.Erlang do
for {_, warnings} <- entries,
{file, issues} <- warnings,
{location, module, message} <- issues do
IO.puts("#{file}:#{location_to_string(location)} warning: #{module.format_error(message)}")
message = "#{file}:#{location_to_string(location)} warning: #{module.format_error(message)}"

IO.puts(:stderr, message)
end
end

Expand Down
38 changes: 20 additions & 18 deletions lib/mix/test/mix/tasks/compile.erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,24 @@ defmodule Mix.Tasks.Compile.ErlangTest do
severity: :warning
} = diagnostic

# Should return warning without recompiling file
assert {:noop, [^diagnostic]} = Mix.Tasks.Compile.Erlang.run(["--verbose"])
refute_received {:mix_shell, :info, ["Compiled src/has_warning.erl"]}

assert [^diagnostic] = Mix.Tasks.Compile.Erlang.diagnostics()
assert [^diagnostic] = Mix.Task.Compiler.diagnostics()

# Should not return warning after changing file
File.write!(file, """
-module(has_warning).
-export([my_fn/0]).
my_fn() -> ok.
""")

ensure_touched(file)
assert {:ok, []} = Mix.Tasks.Compile.Erlang.run([])
capture_io(:stderr, fn ->
# Should return warning without recompiling file
assert {:noop, [^diagnostic]} = Mix.Tasks.Compile.Erlang.run(["--verbose"])
refute_received {:mix_shell, :info, ["Compiled src/has_warning.erl"]}

assert [^diagnostic] = Mix.Tasks.Compile.Erlang.diagnostics()
assert [^diagnostic] = Mix.Task.Compiler.diagnostics()

# Should not return warning after changing file
File.write!(file, """
-module(has_warning).
-export([my_fn/0]).
my_fn() -> ok.
""")

ensure_touched(file)
assert {:ok, []} = Mix.Tasks.Compile.Erlang.run([])
end)
end)
end)
end
Expand All @@ -165,11 +167,11 @@ defmodule Mix.Tasks.Compile.ErlangTest do

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

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

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

Expand Down
Loading