Skip to content

cargo test does not run documentation tests on binary projects #2009

@bltavares

Description

@bltavares

Hi there folks,

I was preparing an introduction to cargo to share with some coworkers and I wanted to show how the documentation testing works.

So I created a binary project to show a 'Hello world' and added a documentation code that should fail to exemplify the documentation testing, but it didn't run with cargo test.

Here are examples to reproduce:

cargo new --bin binary
cd binary
echo '///```
///assert_eq!(1, 2);
///```
fn main() {
    println!("Hello, world!");
}
' > src/main.rs
cargo test
# Expected: 1 doc-test failed, found 0 failures
cargo new library
cd library
echo '///```
///assert_eq!(1, 2);
///```
fn lib() {
    println!("Hello, world!");
}
' > src/lib.rs
cargo test
# Expected: 1 doc-test failed, found 1 failure

Thanks and keep the good work folks! (:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions