defmodule Mix.Tasks.UnusedTest do @moduledoc """ Smoke test for `mix unused`. The task is a static analyzer that walks `_build//lib/microwaveprop/ebin/Elixir.*.beam` and reports functions defined but never called. We just verify that running it with normal and verbose flags exercises the AST traversal pipeline end-to-end without raising. """ use ExUnit.Case, async: false alias Mix.Tasks.Unused setup do original_shell = Mix.shell() Mix.shell(Mix.Shell.Process) on_exit(fn -> Mix.shell(original_shell) end) :ok end test "run/1 with no args walks every beam without raising" do assert :ok = Unused.run([]) || :ok # First message confirms the scan started against the test build dir. assert_received {:mix_shell, :info, [msg]} assert msg =~ "Scanning" end test "run/1 with --skip-external still completes" do assert :ok = Unused.run(["--skip-external"]) || :ok assert_received {:mix_shell, :info, [msg]} assert msg =~ "Scanning" end test "run/1 with --verbose emits the all-functions section" do Unused.run(["--verbose"]) messages = fn -> receive do {:mix_shell, :info, [m]} -> m after 0 -> nil end end |> Stream.repeatedly() |> Enum.take_while(& &1) combined = Enum.join(messages, "\n") assert combined =~ "Scanning" # Verbose flag should print the per-function CALLED/UNUSED listing # at the bottom of the report. assert String.contains?(combined, ["All defined functions", "CALLED", "UNUSED"]) end end