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.
Asked
Active
Viewed 3,895 times
10

Henry
- 1,311
- 1
- 9
- 26
-
The best you can do is test a single file at a time. You can also manually disable testing a specific code sample in documentation by adding `ignore` to the code block. Reference: https://doc.rust-lang.org/rustdoc/documentation-tests.html#attributes – Locke Mar 01 '21 at 04:20
-
How would you select this particular test? – the busybee Mar 01 '21 at 07:17
1 Answers
11
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.

smitop
- 4,770
- 2
- 20
- 53