ArchTest.Freeze (ArchTest v0.2.0)

Copy Markdown View Source

Violation baseline ("freeze") support for gradual architectural adoption.

When a rule has existing violations that cannot be fixed immediately, use freeze/2 to record the current set of violations as a baseline. Future test runs only fail on new violations not in the baseline.

Usage

test "legacy dependencies being cleaned up" do
  modules_matching("MyApp.**")
  |> should_not_depend_on(modules_matching("MyApp.Legacy.**"))
  |> freeze("legacy_deps")
end

Baseline files

Baselines are stored as text files (one violation key per line) in the directory configured by:

config :arch_test, freeze_store: "test/arch_test_violations"

The default store path is test/arch_test_violations/.

Commit these files to version control. To "unfreeze" and require all violations to be fixed, delete the corresponding file.

Updating the baseline

Run with ARCH_TEST_UPDATE_FREEZE=true to overwrite baselines with the current violation set:

ARCH_TEST_UPDATE_FREEZE=true mix test

Summary

Functions

Runs assertion_fn and freezes violations against a stored baseline.

Returns the path to the freeze store directory.

Returns true if the ARCH_TEST_UPDATE_FREEZE environment variable is set.

Functions

freeze(rule_id, assertion_fn)

@spec freeze(String.t(), (-> :ok)) :: :ok

Runs assertion_fn and freezes violations against a stored baseline.

rule_id is used to name the baseline file (should be unique per rule).

Only violations not in the baseline cause test failure. If ARCH_TEST_UPDATE_FREEZE=true, the baseline is updated to the current violation set.

store_path()

@spec store_path() :: String.t()

Returns the path to the freeze store directory.

update_freeze?()

@spec update_freeze?() :: boolean()

Returns true if the ARCH_TEST_UPDATE_FREEZE environment variable is set.