Skip to content

doctests are not run when specifying a target #140996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tyilo opened this issue May 14, 2025 · 1 comment
Closed

doctests are not run when specifying a target #140996

tyilo opened this issue May 14, 2025 · 1 comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tyilo
Copy link
Contributor

tyilo commented May 14, 2025

Steps to reproduce:

cd /tmp
cargo new --lib doctest-test
cd doctest-test

Add a doctest to src/lib.rs to:

/// ```
/// use doctest_test::add;
///
/// assert_eq!(add(1, 2), 3);
/// ```
pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

Run the tests with different targets:

$ cargo test
cargo test
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.01s
     Running unittests src/lib.rs (target/debug/deps/doctest_test-80cbe61ba5d23d25)

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests doctest_test

running 1 test
test src/lib.rs - add (line 1) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
$ cargo test --target x86_64-unknown-linux-musl
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/lib.rs (target/x86_64-unknown-linux-musl/debug/deps/doctest_test-414700a1c2498589)

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
$ cargo test --target i686-unknown-linux-gnu
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/lib.rs (target/i686-unknown-linux-gnu/debug/deps/doctest_test-00139adbea66aca7)

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

As you can see only the normal test is run, but not the doctest.

Meta

This happens in both the current stable and nightly version.

rustc --version --verbose:

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

rustc +nightly --version --verbose:

rustc 1.89.0-nightly (414482f6a 2025-05-13)
binary: rustc
commit-hash: 414482f6a0d4e7290f614300581a0b55442552a3
commit-date: 2025-05-13
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.4
@tyilo tyilo added the C-bug Category: This is a bug. label May 14, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 14, 2025
@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-doctests Area: Documentation tests, run by rustdoc and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 14, 2025
@ehuss
Copy link
Contributor

ehuss commented May 14, 2025

Thanks for the report! This is a known issue, which hopefully will get resolved soon via rust-lang/cargo#15462. Closing as a duplicate of rust-lang/cargo#7040.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

4 participants