# ADR 0064: Test-only code: `@test import`, `[dev-dependencies]`, and `gen` **Status:** Proposed (2026-10-27); needs engineering review (#44), in particular dropping tests from program builds (what a build no longer checks), `louise check` loading `test/`, and unused imports being reported only where the tests are seen. ## Context An inline test could not use a package's `test/` modules: `louise build` loads only `src/`, so the import would fail the build. toki2 forbids it by rule, and its test helpers ended up in production files below the first `@test`, copied from module to module. A package could not depend on another for its tests only either: `[dependencies]` are built and linked with the program, and `louise.toml` rejected any other table. `@test` functions themselves were type-checked and lowered by every command and merely never used as entries. Rust answers with `#[cfg(test)]` and `[dev-dependencies]`; Louise had neither. There was also no way to write randomized tests beyond `std/random`. ## Decision **`@test import m`** imports `m` for tests only. - `louise test`, `louise check` and the language server resolve it, and only `@test` functions may use it: any other item that does is E0126, reported once, at the item. - A program build (`build`, `run`, `core`) leaves out every `@test` function and `@test import` before names are resolved. What only tests use is neither checked nor compiled, and a `test/` module can be imported, since only the analyses that load `test/` see the import. - A `@test import` does not count toward import cycles (E0105). Only `@test` functions use it, so no interface depends on it, and a module's tests may use a helper under `test/` that imports the module itself (a domain module's tests and its fixtures). Inference orders functions by their references, not modules, so nothing else needs the edge. - No other attribute applies to an import (E0114). `louise fmt` keeps `@test` on the import's line and sorts `@test import`s after the plain ones of their run. **Unused imports (W0102) are reported only where the tests are seen.** Without them, an import used only by a test looks unused, so program builds no longer report W0102; `check`, `test` and the language server do. **`louise check` loads `test/`**, and still checks `[application]`. Before, it checked `src/` only. **`[dev-dependencies]`** in `louise.toml` (the root package's only) are resolved and locked like `[dependencies]`, so a build and a test run agree on `louise.lock`. - They are loaded by `test`, `check` and the language server, and left out of program builds (`Resolution::without_dev`): not loaded, not linked. - A package reachable both ways is an ordinary dependency. A name may not be in both tables. **`louise test --native`** reports a multi-line panic message whole, as the interpreter does (it kept the first line). **`gen`** (`packages/gen`) is a package for randomized tests, taken as a dev-dependency: - `gen`: generators. A generator is any `fn() -> a / `: the `random` effect plays the part a generator monad plays elsewhere, sequencing is ordinary code, and `random.with_seed` makes a run repeatable. Every generator draws so that zero bytes give its smallest value. - `gen/fake`: words, sentences, names, emails and URLs. - `gen/check`: `property`, `seeded` and `counterexample`. A case runs under a handler of `random` that records its bytes; a failing case's bytes are shrunk (blocks deleted, blocks zeroed, bytes made 0, halved or one less) while the generator, replaying them under another handler, still makes a failing case, as Hypothesis does. No type needs a shrinker of its own. `property` takes its seed from `random`, so each test run tries new cases, and a failure names the seed to replay. ## Consequences - An inline test can use helpers kept under `test/`, and a package's test-only dependencies stay out of its builds. - **A program build no longer type-checks its tests.** `louise check` and `louise test` do, and CI runs both. - **Older compilers reject `[dev-dependencies]` and `@test import`**, so a package that uses them must require `louise = ">= 0.3.0"`. - **`louise check` reports problems in `test/`** that it did not see before. - **Handlers are lexical (ADR 0010), so generators cannot be kept in data.** `gen` chooses between values (`pick`, `weighted`), not between generators. - **Shrinking needs generators that draw through `random`.** One that keeps its own state, or ignores the bytes it draws, does not shrink well. - **Not done:** shrinking within a time budget, a database of past failures, generators derived from types.