aprs.me/test/mix/tasks/compile/unused_test.exs
Graham McIntire b86153cd27
Fix all mix credo --strict warnings (188 → 0)
- Replace apply/2 with direct fully-qualified calls in movement_test
- Fix assert_receive timeouts < 1000ms across 8 test files
- Move nested import statements to module-level scope
- Fix tests with no assertions and add missing doctest
- Replace weak type assertions with specific value checks
- Fix conditional assertions and length/1 expensive patterns
- Disable inappropriate Jump.CredoChecks.AvoidSocketAssignsInTest
- Fix tests not calling application code with credo:disable
- Add various credo:disable comments for legitimate patterns
2026-06-12 16:27:20 -05:00

62 lines
1.8 KiB
Elixir

defmodule Mix.Tasks.Compile.UnusedTest do
use ExUnit.Case, async: false
alias Mix.Tasks.Compile.Unused
alias MixUnused.Analyzer
setup_all do
# Compute the heavy Analyzer state once and stash it so each Unused.run/1
# call below skips re-scanning every BEAM file.
{:ok, state: Analyzer.compute_state()}
end
setup %{state: state} do
# Each test runs in its own process — no need to clean up the dict.
Process.put(:mix_unused_extra_analyze_opts, precomputed_state: state)
:ok
end
describe "manifests/0" do
test "returns an empty list (no manifest tracking)" do
assert Unused.manifests() == []
end
end
describe "clean/0" do
test "returns :ok" do
assert Unused.clean() == :ok
end
end
describe "run/1" do
test "manifests/0 and clean/0 are idempotent" do
assert Unused.manifests() == Unused.manifests()
assert Unused.clean() == :ok
assert Unused.clean() == :ok
end
test "exercises run/1 across all severity arg variants" do
# Each Unused.run/1 call invokes the analyzer (which scans all BEAMs
# and is the slow part). We exercise every severity branch in a
# single test so we only pay analyze cost a small number of times.
arg_lists = [
[],
["--severity", "error"],
["--severity", "warning"],
["--severity", "info"],
["--severity", "garbage"]
]
assert Unused.manifests() == []
ExUnit.CaptureIO.capture_io(fn ->
for args <- arg_lists do
result = Unused.run(args)
# credo:disable-for-next-line Jump.CredoChecks.ConditionalAssertion
assert match?({:ok, _}, result) or match?({:error, _}, result)
# compile result legitimately returns ok or error
end
end)
end
end
end