Skip to content

cargo test --doc does not test examples #2684

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
mkroman opened this issue May 13, 2016 · 11 comments
Closed

cargo test --doc does not test examples #2684

mkroman opened this issue May 13, 2016 · 11 comments

Comments

@mkroman
Copy link
Contributor

mkroman commented May 13, 2016

When running cargo doc --test in a project folder, cargo does not test documentation examples, it only builds the project and exits.

This is when running cargo from nightly.

mk@maero ~/Projects/SoundCloud % cargo test --doc
mk@maero ~/Projects/SoundCloud % 
@mkroman
Copy link
Contributor Author

mkroman commented May 13, 2016

I've submitted a pull request. #2685

bors added a commit that referenced this issue May 17, 2016
Fix `cargo test --doc` not testing examples

When running cargo doc --test in a project folder, cargo does not test documentation examples, it only builds the project and exits.

Refer to issue #2684
@huonw
Copy link
Member

huonw commented May 17, 2016

Fixed by #2685.

@huonw huonw closed this as completed May 17, 2016
@dianpopa
Copy link

Hi,

I am able to replicate this problem with rustdoc 1.27.2 (58cc626de 2018-07-18)
and rustc 1.27.2 (58cc626de 2018-07-18). Running cargo test --doc exits without running documentation examples even though the folders that I am trying to run the command for are library crate-types. Any suggestions?

@maddiemort
Copy link

maddiemort commented Jul 26, 2018

+1 on 1.27.0 and 1.27.2.

Edit: It works on 1.28.0-beta (cb019b621 2018-07-05) and 1.29.0-nightly (af9e40c26 2018-07-05), but I need to pass the --doc flag. Just running cargo test doesn't run doc tests. I seem to remember that cargo test used to run doc tests as well... is this an intentional change?

@ehuss
Copy link
Contributor

ehuss commented Jul 26, 2018

@dianpopa Can you post an example package that demonstrates the problem?

@sorenmortensen cargo test should run the doc tests. Is cargo not even printing Doc-tests my-package? Does it happen with a simple package with just a library?

@maddiemort
Copy link

maddiemort commented Jul 26, 2018

@ehuss That's correct, it doesn't even print Doc-tests foo. I did just create a simple library package, though, and haven't been able to reproduce it yet. Will keep trying.

Edit: even when I force it to run the doc tests by running cargo +nightly test --doc, it seems not to be able to find the crate, even when I add an extern crate foo; declaration.

@maddiemort
Copy link

I believe I've found the culprit. It's because I've set the crate-type in Cargo.toml. I'm using crate-type = ["staticlib"], but I can reproduce this also with "dylib". Should I open a new issue, as this seems to be different?

Here is a minimal example that reproduces the problem.

@ehuss
Copy link
Contributor

ehuss commented Jul 26, 2018

@sorenmortensen Thanks for the info. Only rlibs support doctests. It was an unintentional change to allow you to even try with test --doc. I'll take care of that, thanks!

@dwijnand
Copy link
Member

@ehuss' is taking care of it in #5801 :)

@dianpopa
Copy link

I discovered what was the problem for me. If I remove x86_64-unknown-linux-musl target from .cargo/config I am able to see the Doc-tests being run. I am compiling on an x86 machine. If I keep the musl target and I specifically run cargo test like cargo test --target x86_64-unknown-linux-gnu the Doc-tests are successfully run. I am guessing I stumbled upon #4471 which seems to be the expected behavior. However, to me this is not exactly cross-compilation as I am on an x86 host and trying to obtain a musl enabled binary for the same type of architecture (i.e. x86). What is your opinion on this?

@ehuss
Copy link
Contributor

ehuss commented Jul 26, 2018

@dianpopa I suggest you add your use case on rust-lang/rust#44404. Unfortunately I suspect it's not easy to fix, but collecting feedback might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants