diff --git a/lib/mix/lib/mix/compilers/erlang.ex b/lib/mix/lib/mix/compilers/erlang.ex index 077ca375cf3..ab94b0a03de 100644 --- a/lib/mix/lib/mix/compilers/erlang.ex +++ b/lib/mix/lib/mix/compilers/erlang.ex @@ -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 diff --git a/lib/mix/test/mix/tasks/compile.erlang_test.exs b/lib/mix/test/mix/tasks/compile.erlang_test.exs index 0cf07c118d0..2cc13d301a5 100644 --- a/lib/mix/test/mix/tasks/compile.erlang_test.exs +++ b/lib/mix/test/mix/tasks/compile.erlang_test.exs @@ -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 @@ -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"