Skip to content

C0015 test-support-gated

Rule: Test fakes and testing modules compile only for tests or behind the test-support feature.

Code C0015 (stable, never reused)
Id test-support-gated
Category code
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small off
small-workspace off
medium warn fakes and test helpers never ship: cfg(test), a test-support feature from dev-dependencies, or a test crate
big warn fakes and test helpers never ship: cfg(test), a test-support feature from dev-dependencies, or a test crate
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Parameters

Name Type Default Meaning
feature string "test-support" the feature that turns test helpers on
modules list of strings ["testing", "test_utils", "test_support", "fakes", "mocks"] module names that hold test helpers
prefixes list of strings ["Fake", "Mock"] type name prefixes of test fakes
test-crates list of strings ["*_testkit", "*_test_support", "*_testing"] crates that exist for tests and are exempt
test-dirs list of strings ["**/tests/**"] directories whose crates exist for tests and are exempt

Why

Fakes (FakeFs, MockClient) and helper modules (testing, test_utils) exist for tests. Compiled into the library they ship in every binary, widen its public API, and let production code call a fake by accident. zed keeps them behind a test-support feature in about 150 crates, turned on by dev-dependencies only; rerun puts the shared harness in a crate of its own.

How to fix

Gate the helpers and turn the feature on only where tests build:

#[cfg(any(test, feature = "test-support"))]
pub mod testing;
# crates/fs/Cargo.toml
[features]
# fakes for other crates' tests: FakeFs
test-support = []

# crates/app/Cargo.toml
[dev-dependencies]
fs = { workspace = true, features = ["test-support"] }

Or move them into a test-only crate: one named for it (*_testkit, parameter test-crates), one under a tests/ directory (parameter test-dirs), or one that every member takes only as a dev-dependency. Two findings are certain: a normal or build dependency that turns the feature on, and a default feature that holds it. Public helper modules and public fake types are found by name (parameters modules and prefixes), so those findings are estimates.

Configure

[lints.test-support-gated]
level = "deny"
feature = "test-support"
modules = ["testing", "test_utils", "test_support", "fakes", "mocks"]
prefixes = ["Fake", "Mock"]
test-crates = ["*_testkit", "*_test_support", "*_testing"]
test-dirs = ["**/tests/**"]
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(test-support-gated) <reason> (waivers); the code works there too, as in [lints.C0015].