How to compile (only) doc tests (for CI)

โš“ Rust    ๐Ÿ“… 2026-02-02    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 11      

surdeus

Warning

This post was published 77 days ago. The information described in this article may have changed.

For our CI (as well as local build command), I'd like to be able to include doc tests into standard compilation of our project.

I have the feeling that doc-tests are not a 'usual' target selectable for e.g. cargo check or cargo build
Also cargo doc doesn't seem to include neither check nor build nor running the doc-test/example.
I only know of cargo test command being aware of the doc-test/examples in a way to check, build or run them.
I learned that cargo test indeed has both a) target selection for doc-tests/examples (parameter --doc) and b) option --no-run. But using both in combination I am shown this output error: Can't skip running doc tests with --no-run

What can I do to check/build all my doc-test/examples without running them (and other tests) at the same time?

BTW: sarching for an answer, I encountered this: cargo test --all-targets does not run doc tests ยท Issue #6669 ยท rust-lang/cargo. Now I wonder if that issue and my challenge are related.

Thank you much for help!

BTW: I find terminology a bit confusing here: Examples in documentation sometimes seem to be referred to as: target: doc, doc-tests, examples, however this is not what examples mean in that sense, I suppose: Cargo target: examples as of Cargo Targets - The Cargo Book

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed