Skip to content

cargo test --all-targets does NOT run doctests #11015

Closed as not planned
Closed as not planned
@crepererum

Description

@crepererum

Problem

While cargo test runs unit tests AND doctests (no matter if they are marked to run or just to compile), cargo test --all-targets does not which is counterintuitive. The documentation for --all-targets reads: "Test all targets".

Steps

  1. Create a new crate via cargo init --lib
  2. Add a failing doctest at the top of src/lib.rs:
    //! ```
    //! does not compile
    //! ```
    
  3. Run cargo test, this will fail.
  4. Run cargo test --all-targets, this will pass.

Possible Solution(s)

Also run doctests when --all-targets is passed.

Notes

This MIGHT be related to #6424, but that issue talks specifically about cargo check and that is seems to be impossible to run check on doctests.

Version

cargo 1.63.0 (fd9c4297c 2022-07-01)
release: 1.63.0
commit-hash: fd9c4297ccbee36d39e9a79067edab0b614edb5a
commit-date: 2022-07-01
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1n)
os: Arch Linux [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions