Skip to content

Commit

Permalink
fix: mix dialyzer crashes when a custom ignore file provided that doe…
Browse files Browse the repository at this point in the history
…sn't match the default
  • Loading branch information
pdm-jd committed Nov 12, 2024
1 parent b960c7d commit 621fc4a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
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

0 comments on commit 621fc4a

Please sign in to comment.