test(units): trybuild compile-fail cases for dimensional errors #39

Merged
patman merged 1 commit from patman/uom-trybuild into main 2026-07-09 23:11:25 +00:00
Owner

What this does

Adds trybuild compile-fail tests that assert the typed units layer rejects dimensionally incoherent code — the negative guardrail the in-crate #[test]s cannot express (a passing test can't prove a compile error). Cases in common/tests/ui/:

  • length_plus_time.rsLength + Time (incoherent add).
  • angular_bare_operator.rsAngle / Time without .into() (the documented AngleKind trap; use angular::DivDt).
  • boundary_type_mismatch.rs — passing a Length where a Velocity is expected.

⚠️ For evaluation — cargo-only, not in buck2

trybuild shells out to cargo to compile each ui case, which the hermetic buck2 sandbox can't provide. So this is not wired into the buck2 test graph (tests/ is outside common/BUCK's src/** glob, and trybuild is a common/Cargo.toml dev-dep only — the buck2 graph and third-party BUCK are untouched; buck2 test //common/... still passes 89).

Run it with cargo:

TRYBUILD=overwrite cargo test -p common --test ui   # first run: generates tests/ui/*.stderr
cargo test -p common --test ui                      # thereafter

The generated .stderr files are not committed yet (they need a cargo run to produce); commit them once reviewed.

The decision to make

This is the crux you wanted to evaluate: trybuild gives real compile-fail enforcement but only under cargo, which conflicts with the buck2-only build mandate. Options: (a) accept a cargo-only enforcement lane for compile-fail tests (run in a cargo CI job); (b) invest in a custom buck2 rule that asserts compile failure (no cargo); (c) drop trybuild and rely on the compile_fail doctests in #37 as documentation only. No buck2 wiring is included pending your call.

Stack position

PR 4 of 4. Based on #38 (angular helpers) → #37#36. Merge order: #36#37#38#39.

## What this does Adds `trybuild` compile-fail tests that assert the typed units layer **rejects** dimensionally incoherent code — the negative guardrail the in-crate `#[test]`s cannot express (a passing test can't prove a compile error). Cases in `common/tests/ui/`: - `length_plus_time.rs` — `Length + Time` (incoherent add). - `angular_bare_operator.rs` — `Angle / Time` without `.into()` (the documented `AngleKind` trap; use `angular::DivDt`). - `boundary_type_mismatch.rs` — passing a `Length` where a `Velocity` is expected. ## ⚠️ For evaluation — cargo-only, not in buck2 trybuild shells out to **cargo** to compile each ui case, which the hermetic buck2 sandbox can't provide. So this is **not** wired into the buck2 test graph (`tests/` is outside `common/BUCK`'s `src/**` glob, and `trybuild` is a `common/Cargo.toml` dev-dep only — the buck2 graph and third-party `BUCK` are untouched; `buck2 test //common/...` still passes 89). Run it with cargo: ```text TRYBUILD=overwrite cargo test -p common --test ui # first run: generates tests/ui/*.stderr cargo test -p common --test ui # thereafter ``` The generated `.stderr` files are not committed yet (they need a cargo run to produce); commit them once reviewed. ## The decision to make This is the crux you wanted to evaluate: trybuild gives real compile-fail enforcement but only under **cargo**, which conflicts with the buck2-only build mandate. Options: (a) accept a cargo-only enforcement lane for compile-fail tests (run in a cargo CI job); (b) invest in a custom buck2 rule that asserts compile failure (no cargo); (c) drop trybuild and rely on the `compile_fail` doctests in #37 as documentation only. No buck2 wiring is included pending your call. ## Stack position PR 4 of 4. Based on #38 (angular helpers) → #37 → #36. Merge order: #36 → #37 → #38 → #39.
Adds trybuild-based compile-fail tests proving the typed units layer
rejects dimensionally incoherent code (m/s + m, the AngleKind bare-operator
trap, and passing a Length where a Velocity is expected) — the negative
guardrail the positive unit tests cannot assert.

trybuild shells out to cargo to compile each ui case, which the hermetic
buck2 sandbox cannot provide, so this is wired for cargo only (not the
buck2 test graph). For evaluation; see tests/ui.rs for how to run.

Co-authored-by: patman-assist <patrick-ai@kgroo.co>
patman changed target branch from patman/uom-angular-helpers to main 2026-07-09 23:11:24 +00:00
patman merged commit 98a8dba59e into main 2026-07-09 23:11:25 +00:00
Sign in to join this conversation.
No description provided.