Skip to content

Commit 621fc4a

Browse files
committed
fix: mix dialyzer crashes when a custom ignore file provided that doesn't match the default
1 parent b960c7d commit 621fc4a

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Versions follow [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html)
88

99
## Unreleased changes post [1.4.4]
1010

11+
### Fixed
12+
- Crash when default ignore file missing and custom file specified
13+
1114
## [1.4.3] - 2023-12-28
1215
### Fixed
1316
- Warnings with line & column.

lib/mix/tasks/dialyzer.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ defmodule Mix.Tasks.Dialyzer do
188188
""")
189189

190190
ignore_warnings && File.exists?(ignore_warnings) &&
191-
match?(%{size: size} when size == 0, File.stat!(default)) ->
191+
match?(%{size: size} when size == 0, File.stat!(ignore_warnings)) ->
192192
info("""
193193
:ignore_warnings opt specified in mix.exs: #{ignore_warnings}, but file is empty.
194194
""")

test/fixtures/ignore_custom_empty/ignore_test.exs

Whitespace-only changes.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule IgnoreCustomEmpty.Mixfile do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :ignore_custom_empty,
7+
version: "0.1.0",
8+
prune_code_paths: false,
9+
dialyzer: [
10+
# this file is expected to not exist
11+
ignore_warnings: "ignore_test.exs",
12+
list_unused_filters: true
13+
]
14+
]
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule IgnoreCustomMissing.Mixfile do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :ignore_custom_missing,
7+
version: "0.1.0",
8+
prune_code_paths: false,
9+
dialyzer: [
10+
# this file is expected to not exist
11+
ignore_warnings: "ignore_test.exs",
12+
list_unused_filters: true
13+
]
14+
]
15+
end
16+
end

test/mix/tasks/dialyzer_test.exs

+26
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,30 @@ defmodule Mix.Tasks.DialyzerTest do
7777
assert result =~
7878
"Unrecognized formatter foo received. Known formatters are dialyzer, dialyxir, github, ignore_file, ignore_file_strict, raw, and short. Falling back to dialyxir."
7979
end
80+
81+
test "task runs when custom ignore file provided and exists" do
82+
in_project(:ignore, fn ->
83+
fun = fn -> Mix.Tasks.Dialyzer.run(["--ignore-exit-status"]) end
84+
85+
assert capture_io(fun) =~ "ignore_warnings: ignore_test.exs"
86+
end)
87+
end
88+
89+
test "task runs when custom ignore file provided and does not exist" do
90+
in_project(:ignore_custom_missing, fn ->
91+
fun = fn -> Mix.Tasks.Dialyzer.run(["--ignore-exit-status"]) end
92+
93+
assert capture_io(fun) =~
94+
":ignore_warnings opt specified in mix.exs: ignore_test.exs, but file does not exist"
95+
end)
96+
end
97+
98+
test "task runs when custom ignore file provided and it is empty" do
99+
in_project(:ignore_custom_empty, fn ->
100+
fun = fn -> Mix.Tasks.Dialyzer.run(["--ignore-exit-status"]) end
101+
102+
assert capture_io(fun) =~
103+
":ignore_warnings opt specified in mix.exs: ignore_test.exs, but file is empty"
104+
end)
105+
end
80106
end

0 commit comments

Comments
 (0)