Search code examples
testingrustdocumentationrust-cargo

How to generate documentation for modules that are behind #[cfg(test)]?


In a Rust project there is a module with utilities to support testing, packed in a module test_utils:

#[cfg(test)]
pub mod test_utils;

Is there a way to make cargo doc generate also the documentation for test_utils module and the things inside?


Solution

  • There are probably multiple ways of generating documentation for tests, but I think the easier approach is to generate the documentation with cargo rustdoc and pass the --cfg test flag through:

    cargo rustdoc -- --cfg test