Skip to content
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

fix: mix dialyzer crashes when a custom ignore file provided that doesn't match the default #549

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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Versions follow [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html)

## Unreleased changes post [1.4.4]

### Fixed
- Crash when default ignore file missing and custom file specified

## [1.4.3] - 2023-12-28
### Fixed
- Warnings with line & column.
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/dialyzer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ defmodule Mix.Tasks.Dialyzer do
""")

ignore_warnings && File.exists?(ignore_warnings) &&
match?(%{size: size} when size == 0, File.stat!(default)) ->
match?(%{size: size} when size == 0, File.stat!(ignore_warnings)) ->
info("""
:ignore_warnings opt specified in mix.exs: #{ignore_warnings}, but file is empty.
""")
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions test/fixtures/ignore_custom_empty/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule IgnoreCustomEmpty.Mixfile do
use Mix.Project

def project do
[
app: :ignore_custom_empty,
version: "0.1.0",
prune_code_paths: false,
dialyzer: [
# this file is expected to not exist
ignore_warnings: "ignore_test.exs",
list_unused_filters: true
]
]
end
end
16 changes: 16 additions & 0 deletions test/fixtures/ignore_custom_missing/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule IgnoreCustomMissing.Mixfile do
use Mix.Project

def project do
[
app: :ignore_custom_missing,
version: "0.1.0",
prune_code_paths: false,
dialyzer: [
# this file is expected to not exist
ignore_warnings: "ignore_test.exs",
list_unused_filters: true
]
]
end
end
26 changes: 26 additions & 0 deletions test/mix/tasks/dialyzer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,30 @@ defmodule Mix.Tasks.DialyzerTest do
assert result =~
"Unrecognized formatter foo received. Known formatters are dialyzer, dialyxir, github, ignore_file, ignore_file_strict, raw, and short. Falling back to dialyxir."
end

test "task runs when custom ignore file provided and exists" do
in_project(:ignore, fn ->
fun = fn -> Mix.Tasks.Dialyzer.run(["--ignore-exit-status"]) end

assert capture_io(fun) =~ "ignore_warnings: ignore_test.exs"
end)
end

test "task runs when custom ignore file provided and does not exist" do
in_project(:ignore_custom_missing, fn ->
fun = fn -> Mix.Tasks.Dialyzer.run(["--ignore-exit-status"]) end

assert capture_io(fun) =~
":ignore_warnings opt specified in mix.exs: ignore_test.exs, but file does not exist"
end)
end

test "task runs when custom ignore file provided and it is empty" do
in_project(:ignore_custom_empty, fn ->
fun = fn -> Mix.Tasks.Dialyzer.run(["--ignore-exit-status"]) end

assert capture_io(fun) =~
":ignore_warnings opt specified in mix.exs: ignore_test.exs, but file is empty"
end)
end
end
Loading