Doctests don't work in bin targets
Open
Nobody has claimed this yet.
A-doctests
Command-test
S-blocked-external
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
It's surprising that doctests don't work binary targets:
cargo new foo --bin
/// ```rust
/// assert!(false);
/// ```
fn main() {
println!("Hello, world!");
}
cargo test --all
I'd expect the above to fail, but it looks like the doc-comment code is never ran. Even if I explicitly enable doctests for the binary:
[[bin]]
name = "foo"
path = "src/main.rs"
doctest = true
they still aren't run.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in src/main.rs and the binary configuration in Cargo.toml, then run cargo test --all with and without doctest = true. Trace how Cargo handles doctests for bin targets; done means the documented assertion is executed and causes the expected test failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100