Skip to content
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

Doc tests not run with cargo test TESTNAME on stable (1.35.0) #6981

Open
tspiteri opened this issue May 24, 2019 · 5 comments
Open

Doc tests not run with cargo test TESTNAME on stable (1.35.0) #6981

tspiteri opened this issue May 24, 2019 · 5 comments
Labels
A-doctests Area: rustdoc --test A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug Command-test E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@tspiteri
Copy link

The contents of doc/src/lib.rs:

/// ```rust
/// let _ = {};
/// ```
pub fn foo() {}

Running cargo test foo, doc tests matching the pattern are not run for stable 1.35.0, but they run fine with 1.34.2.

$ cargo version
cargo 1.35.0 (6f3e9c367 2019-04-04)
$ cargo test foo
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running target/debug/deps/doc-86434eb559164ed5

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

$ cargo +1.34.2 test foo
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running target/debug/deps/doc-f8e8caa996ffb988

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests doc

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

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
@tspiteri tspiteri added the C-bug Category: bug label May 24, 2019
@ehuss
Copy link
Contributor

ehuss commented May 27, 2019

For now you can use the --doc flag to do doc tests only.

This was changed in #6683. I didn't really consider filters with doc tests. It may not be trivial to fix due to how filters work. We also haven't really concluded how the --doc flag should behave (is it a filter or a mode?).

@tspiteri
Copy link
Author

For my actual use case I have almost 900 examples (in the Rug crate). If I write a new example or modify an existing example, the --doc flag is not so helpful.

@ehuss
Copy link
Contributor

ehuss commented May 27, 2019

I'm not sure I understand. cargo test --doc foo should doctest things that match the name foo, which should be what was asked for in the original report? Can you clarify why that won't work?

@tspiteri
Copy link
Author

Oh sorry, I misunderstood. I thought you suggested --doc instead of foo, not as well as foo. Your suggestion works.

@ehuss ehuss added the A-doctests Area: rustdoc --test label Jun 24, 2019
@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

I was also just very confused by this. The documentation for the <TESTNAME> argument does not mention that this also excludes doctests. Also this means that cargo test filter and cargo test -- filter have different behavior, which is very surprising.

@weihanglo weihanglo added A-documenting-cargo-itself Area: Cargo's documentation S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. E-hard Experience: Hard labels May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: rustdoc --test A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug Command-test E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
Status: No status
Development

No branches or pull requests

4 participants