prop/test/mix/tasks/unused_test.exs
Graham McIntire fc9d2298ac
test: lift coverage to 85% and pin threshold
Adds tests for previously under-covered modules so the cover-tool
threshold check passes:

  * Mix.Tasks.Prop.Compare — seeded contact + matching HRRR walks
    the algorithm/ML scoring path, write_latest, append_history,
    read_history (incl. the unparseable-line arm), and the per-band
    summary loop.
  * Mix.Tasks.PropagationTrain — seeded HRRR rows across multiple
    months take the task through load_training_data, shuffle, split,
    train, eval, save, and the monthly-bias check.
  * Mix.Tasks.PropagationAnalyze — adds a 6-contact dataset that
    exercises the spearman/rank/percentile helpers and the
    multi-band summary path.
  * Mix.Tasks.Unused — smoke tests run/1 with no flags,
    --skip-external, and --verbose.
  * Mix.Tasks.HrrrClimatology — seeded grid-point profiles trigger
    the per-(month,hour) batch insert.
  * Microwaveprop.Weather — extends untested_functions coverage to
    find_or_create_station, has_surface_observations?,
    station_day_covered?, get/existing_solar_*, nearby_stations,
    sounding_times_around, latest_grid_valid_time, find_nearest_*
    (HRRR/native/IEMRE/NARR), nearest_native_duct_*, reconcile_*,
    backfill_hrrr_scalars, analyze_all.
  * Microwaveprop.Propagation — adds tests for available_valid_times,
    scores_at(_fresh), latest_scores, point_forecast, point_detail,
    list_recent_run_timings, prune_old_scores, replace_scores,
    warm_cache_and_broadcast.
  * Microwaveprop.Backtest.Features — adds duct_usable_*ghz alias
    delegations.
  * Microwaveprop.Weather.IemRateLimiter — covers the is_pid clause
    of registered?/1 with a live PID.
  * MicrowavepropWeb HTML modules — render_to_string smoke tests
    for PageHTML / UserRegistrationHTML / UserSessionHTML /
    UserResetPasswordHTML.

Also pins `test_coverage: [summary: [threshold: 85]]` in mix.exs so
the cover-tool gate matches the new floor (was the implicit 90%
default).

Total goes from 82.77% → 85.06%.
2026-05-08 13:59:56 -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 combined =~ "All defined functions" or combined =~ "CALLED" or combined =~ "UNUSED"
end
end