prop/test/mix/tasks/unused_test.exs
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

53 lines
1.6 KiB
Elixir

defmodule Mix.Tasks.UnusedTest do
@moduledoc """
Smoke test for `mix unused`. The task is a static analyzer that walks
`_build/<env>/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