diff --git a/CHANGELOG.md b/CHANGELOG.md index 46772c4..aa65359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [Unreleased] + +### Added + +- `--quiet` flag for `mix assay` to suppress informational output (header, + ignore logs, summary, and the warnings exit message). Formatted warning + output and exit codes are unchanged. + ## [0.6.1] - 2026-06-05 ### Fixed diff --git a/README.md b/README.md index 54955e5..3cac6d3 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ mix assay mix assay --print-config mix assay --format github --format sarif mix assay --no-compile # skip compilation (project must already be compiled) +mix assay --quiet # suppress header, ignore logs, summary, and exit message ``` Exit codes: `0` (clean), `1` (warnings), `2` (error). diff --git a/lib/mix/tasks/assay.ex b/lib/mix/tasks/assay.ex index 3473bae..dd6d34a 100644 --- a/lib/mix/tasks/assay.ex +++ b/lib/mix/tasks/assay.ex @@ -13,6 +13,7 @@ defmodule Mix.Tasks.Assay do * `--dialyzer-flag FLAG` - Pass additional Dialyzer flags * `--ignore-file PATH` - Override ignore file path (default: `dialyzer_ignore.exs`) * `--explain-ignores` - Show detailed information about which warnings were ignored and which rules matched them + * `--quiet` - Suppress informational output (header, ignore logs, summary, and warnings exit message) ## Exit Codes @@ -29,6 +30,7 @@ defmodule Mix.Tasks.Assay do mix assay --dialyzer-flag="--statistics" mix assay --ignore-file="custom_ignore.exs" mix assay --explain-ignores + mix assay --quiet --format json """ use Mix.Task @@ -43,7 +45,10 @@ defmodule Mix.Tasks.Assay do :ok :warnings -> - Mix.shell().info("Dialyzer reported warnings") + if !Keyword.get(opts, :quiet, false) do + Mix.shell().info("Dialyzer reported warnings") + end + exit({:shutdown, 1}) end end @@ -60,7 +65,8 @@ defmodule Mix.Tasks.Assay do apps: :string, warning_apps: :string, ignore_file: :string, - explain_ignores: :boolean + explain_ignores: :boolean, + quiet: :boolean ], aliases: [f: :format] ) @@ -92,6 +98,7 @@ defmodule Mix.Tasks.Assay do |> Keyword.put(:formats, normalized_formats) |> Keyword.put(:no_compile, Keyword.get(opts, :no_compile, false)) |> Keyword.put(:explain_ignores, Keyword.get(opts, :explain_ignores, false)) + |> Keyword.put(:quiet, Keyword.get(opts, :quiet, false)) |> maybe_put(:apps, apps_override) |> maybe_put(:warning_apps, warning_override) |> maybe_put(:dialyzer_flags, flag_overrides) diff --git a/test/mix_tasks_assay_test.exs b/test/mix_tasks_assay_test.exs index bb60c77..834b1f0 100644 --- a/test/mix_tasks_assay_test.exs +++ b/test/mix_tasks_assay_test.exs @@ -166,6 +166,39 @@ defmodule Mix.Tasks.AssayTest do assert Keyword.get(runner_opts, :no_compile) == false end + test "run forwards --quiet flag" do + Process.put(:runner_stub_status, :ok) + + ExUnit.CaptureIO.capture_io(fn -> + Assay.run(["--quiet"]) + end) + + assert_received {:runner_called, _config, runner_opts} + assert Keyword.get(runner_opts, :quiet) == true + end + + test "run defaults quiet to false when flag is omitted" do + Process.put(:runner_stub_status, :ok) + + ExUnit.CaptureIO.capture_io(fn -> + Assay.run([]) + end) + + assert_received {:runner_called, _config, runner_opts} + assert Keyword.get(runner_opts, :quiet) == false + end + + test "run suppresses warnings exit message when --quiet is set" do + Process.put(:runner_stub_status, :warnings) + + output = + capture_io(fn -> + assert catch_exit(Assay.run(["--quiet"])) == {:shutdown, 1} + end) + + refute output =~ "Dialyzer reported warnings" + end + test "assay.daemon task boots the daemon" do Application.put_env(:assay, :daemon_module, DaemonStub) diff --git a/test/test_helper.exs b/test/test_helper.exs index 7b02452..6956a0e 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -203,7 +203,7 @@ defmodule Assay.TestSupport.IOProxy do case :binary.match(buffer, "\n") do {pos, _len} -> len = pos + 1 - <> = buffer + <> = buffer {:reply, line, rest} :nomatch -> @@ -215,7 +215,7 @@ defmodule Assay.TestSupport.IOProxy do defp fetch_chars(buffer, true, len) do if byte_size(buffer) >= len do - <> = buffer + <> = buffer {:reply, chunk, rest} else {:reply, buffer, <<>>} @@ -224,7 +224,7 @@ defmodule Assay.TestSupport.IOProxy do defp fetch_chars(buffer, false, len) do if byte_size(buffer) >= len do - <> = buffer + <> = buffer {:reply, chunk, rest} else :pending