Skip to main content

Module checkout

Module checkout 

Source
Expand description

Is a test binary running the code of the checkout that runs it?

Cargo names a workspace’s own crates the same in every clone of the repository. Two clones that share one target directory (CARGO_TARGET_DIR) therefore write the same artifacts, and cargo, which checks the source files the existing artifact was built from, can call another clone’s build fresh: cargo test in one clone then runs the other clone’s code and reports its results as this clone’s. Seen on 2026-10-17, with four clones sharing a target dir: passes and failures that belonged to other branches, and a “cannot find type” for code that was plainly there.

Every test binary of the workspace (each crate’s unit tests and each file under tests/) invokes [checkout_guard!]. It runs [guard] when the binary starts, before the test harness, so a test-name filter can’t skip it. The crate folder compiled into the binary (CARGO_MANIFEST_DIR at build time) must be the one cargo runs it for (CARGO_MANIFEST_DIR at run time); and each workspace library it links must have been compiled in the same workspace, since cargo can rebuild the test binary yet link another checkout’s library it thinks fresh. Each library exports the folder it was compiled in (COMPILED_IN here, CHECKOUT_DIR in the others) for that.

Constants§

COMPILED_IN
The folder this library was compiled in, for [checkout_guard!].

Functions§

check
Err with what to do when the test binary was compiled from another checkout than the one running it. compiled is the invoking crate’s env!("CARGO_MANIFEST_DIR"). Ok when the binary isn’t run by cargo (no CARGO_MANIFEST_DIR at run time), so it can’t tell.
check_linked
Err when a workspace library linked into the test binary was compiled in another workspace than the binary itself (compiled): their workspace roots, two folders up, must be the same folder.