From 621fc4aded0e76f9bd21e97dd233b9fc40c634e7 Mon Sep 17 00:00:00 2001 From: Josiah Dahl Date: Tue, 12 Nov 2024 09:28:27 -0800 Subject: [PATCH] fix: mix dialyzer crashes when a custom ignore file provided that doesn't match the default --- CHANGELOG.md | 3 +++ lib/mix/tasks/dialyzer.ex | 2 +- .../ignore_custom_empty/ignore_test.exs | 0 test/fixtures/ignore_custom_empty/mix.exs | 16 ++++++++++++ test/fixtures/ignore_custom_missing/mix.exs | 16 ++++++++++++ test/mix/tasks/dialyzer_test.exs | 26 +++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/ignore_custom_empty/ignore_test.exs create mode 100644 test/fixtures/ignore_custom_empty/mix.exs create mode 100644 test/fixtures/ignore_custom_missing/mix.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 7abb6637..fa292460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/mix/tasks/dialyzer.ex b/lib/mix/tasks/dialyzer.ex index ceca8445..24c4a3c4 100644 --- a/lib/mix/tasks/dialyzer.ex +++ b/lib/mix/tasks/dialyzer.ex @@ -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. """) diff --git a/test/fixtures/ignore_custom_empty/ignore_test.exs b/test/fixtures/ignore_custom_empty/ignore_test.exs new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/ignore_custom_empty/mix.exs b/test/fixtures/ignore_custom_empty/mix.exs new file mode 100644 index 00000000..758a0684 --- /dev/null +++ b/test/fixtures/ignore_custom_empty/mix.exs @@ -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 diff --git a/test/fixtures/ignore_custom_missing/mix.exs b/test/fixtures/ignore_custom_missing/mix.exs new file mode 100644 index 00000000..e4970efa --- /dev/null +++ b/test/fixtures/ignore_custom_missing/mix.exs @@ -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 diff --git a/test/mix/tasks/dialyzer_test.exs b/test/mix/tasks/dialyzer_test.exs index d606e1f4..c1fff0f0 100644 --- a/test/mix/tasks/dialyzer_test.exs +++ b/test/mix/tasks/dialyzer_test.exs @@ -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