Skip to main content

Crate tests_bridge_macro

Crate tests_bridge_macro 

Source
Expand description

tests_bridge — compile-time “top-level anchor” for module tests.

Rust’s #[path] attribute only accepts string literals (relative to the containing source file), and the attribute evaluator rejects macro calls (#[path = concat!(...)]malformed path attribute input; RFC 2320 “eager macro expansion” was closed unmerged). This macro sidesteps the limitation by expanding — at macro-expansion time, before attribute evaluation — into a #[path = "<absolute>"] mod tests; where the path is anchored at CARGO_MANIFEST_DIR (the calling crate’s root, which is the environment the proc-macro runs in). That is the TS @/-equivalent Rust does not provide natively.

Usage (in the crate whose tests/<mirror>/mod.rs holds the module tests):

#[cfg(test)]
tests_bridge_macro::tests_bridge!("runtime/multiagent/graph/engine");
// expands to:
//   #[cfg(test)] #[path = "/abs/<CARGO_MANIFEST_DIR>/tests/runtime/multiagent/graph/engine/mod.rs"] mod tests;

The call site keeps the #[cfg(test)] prefix so plain cargo build skips the expansion entirely (the macro is a dev-dependency and unavailable to non-test builds). Mirror path is relative to the crate root, .. rejected.

Macros§

tests_bridge