Skip to content
Closed
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
20 changes: 19 additions & 1 deletion lib/mix/lib/mix/tasks/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,25 @@ defmodule Mix.Tasks.Test do
|> filter_to_allowed_files(allowed_files)
|> filter_by_partition(shell, partitions)

display_warn_test_pattern(test_files, test_pattern, unfiltered_test_files, warn_test_pattern)
warnings =
display_warn_test_pattern(
test_files,
test_pattern,
unfiltered_test_files,
warn_test_pattern
)

if warnings != [] and Keyword.get(opts, :warnings_as_errors) do
System.at_exit(fn _ ->
message =
"\nERROR! Test suite aborted after successful execution due to " <>
"warnings while using the --warnings-as-errors option"

Mix.shell().error(message)

exit({:shutdown, 1})
end)
end

try do
Enum.each(test_paths, &require_test_helper(shell, &1))
Expand Down
58 changes: 30 additions & 28 deletions lib/mix/test/mix/tasks/compile.erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,36 @@ defmodule Mix.Tasks.Compile.ErlangTest do
my_fn() -> ok.
""")

capture_io(fn ->
assert {:ok, [diagnostic]} = Mix.Tasks.Compile.Erlang.run([])

assert %Mix.Task.Compiler.Diagnostic{
file: ^source,
source: ^source,
compiler_name: "erl_lint",
message: "function my_fn/0 is unused",
position: position(2, 1),
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 ->
capture_io(fn ->
Comment on lines +121 to +122
Copy link
Contributor Author

@eksperimental eksperimental Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to find a way to catch both stdio and stderr in one go, so I resorted to this:

assert {:ok, [diagnostic]} = Mix.Tasks.Compile.Erlang.run([])

assert %Mix.Task.Compiler.Diagnostic{
file: ^source,
source: ^source,
compiler_name: "erl_lint",
message: "function my_fn/0 is unused",
position: position(2, 1),
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([])
end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, why was this file changed? It seems unrelated to this PR?

Copy link
Contributor Author

@eksperimental eksperimental Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was part of the other PR #14018. It ended up here when I split up the commits.

end)
end)
end
Expand Down