M0028 test-binaries¶
Rule: A crate builds its integration tests as one binary.
| Code | M0028 (stable, never reused) |
| Id | test-binaries |
| Category | repo |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | warn |
each integration-test binary links the library again; one tests/it binary links it once |
| big | warn |
each integration-test binary links the library again; one tests/it binary links it once |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
max-binaries |
integer | 1 |
integration-test binaries a crate may have |
Why¶
Every file directly under tests/ is an integration-test binary of its own: each links the library and its dependencies again and instantiates their generics again. Three files mean three links per test run. One binary with a module per file links once.
How to fix¶
Cargo builds tests/it/main.rs as one binary named it; files in subdirectories of tests/ are not binaries of their own. Tests that assume a process to themselves (a global, the working directory, environment variables) need that assumption removed first. A crate that needs several binaries, such as a harness with harness = false beside ordinary tests, raises the parameter max-binaries in an exception for that crate.
Configure¶
[lints.test-binaries]
level = "deny"
max-binaries = 1
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(test-binaries) <reason> (waivers); the code works there too, as in [lints.M0028].