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

Documentation should make it clear where to put doctest! #25

Open
robinst opened this issue Nov 26, 2020 · 6 comments
Open

Documentation should make it clear where to put doctest! #25

robinst opened this issue Nov 26, 2020 · 6 comments

Comments

@robinst
Copy link

robinst commented Nov 26, 2020

I was adding this crate to my library like this:

tests/readme.rs:

use doc_comment::doctest;

doctest!("../README.md");

And I added an error into the code in README to see if it would fail. But cargo test succeeded.

What actually worked was adding this to src/lib.rs instead:

#[cfg(doctest)]
use doc_comment::doctest;

#[cfg(doctest)]
doctest!("../README.md");

It would be good if the documentation made it very clear where to add the code. Or was I missing something else?

@GuillaumeGomez
Copy link
Owner

This seems highly surprising. You can see the source code of the macro here. So I think the issue lies outside of this crate at this point...

@robinst
Copy link
Author

robinst commented Nov 26, 2020

Alright, I've created a minimal repo to reproduce here: https://github.com/robinst/test-doc-comment

Can you clone and run cargo test and see if it succeeds or fails?

My Rust version is 1.47.0 if that matters.

@GuillaumeGomez
Copy link
Owner

I just realized: you need to add #[cfg(doctest)] because doc-comment is in your dev-dependencies (as it should). All other troubles are from cargo I think. It should fail in case you run cargo test.

@robinst
Copy link
Author

robinst commented Nov 26, 2020

Doesn't help: robinst/test-doc-comment@8ac8c8f

Note, adding this to tests/readme.rs doesn't make it fail either:

/// ```
/// assert_eq!("foo", "bar");
/// ```
fn foo() {}

So I think the problem is that doctests in integration tests are not run at all. It just needs to be documented.

@GuillaumeGomez
Copy link
Owner

Ah ok! Now I get your issue. Yes, tests are handled completely separately and rustdoc doesn't know about them. Can you please open an issue on https://github.com/rust-lang/rust and ask for documentation about this please? (and tag me on it so I can send a fix shortly).

@robinst
Copy link
Author

robinst commented Dec 1, 2020

Done: https://github.com/rust-lang/rust/issues/79587

But also, I think the docs for this crate (doc-comment) should mention it as well.

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

2 participants