11

I would like to only run a particular doc test instead of running all of them. Is there a way I can do this? I know that you can pass --doc to run only doc tests but is there a flag that allows me to run just a particular one.

2

1 Answer 1

13

You can run doc-tests at the granularity of individual documented items.

If you have some source code like this:

/// ## Example
/// ```
/// panic!("doctest #1");
/// ```
/// ```
/// panic!("doctest #2");
/// ```
pub fn first() {}

/// ## Example
/// ```
/// panic!("doctest #3");
/// ```
pub fn second() {}

Then you can run cargo test --doc first to run doctest #1 and doctest #2, and cargo test --doc second to run doctest #3. Any tests with a path matching the string after --doc will be run.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.