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

Run doc tests on README #383

Open
huonw opened this Issue Aug 16, 2014 · 14 comments

Comments

Projects
None yet
@huonw
Copy link
Member

huonw commented Aug 16, 2014

cargo test could run (the equivalent of) rustdoc --test README.md, since people often have a basic example in it.

@tomjakubowski

This comment has been minimized.

Copy link
Contributor

tomjakubowski commented Aug 17, 2014

I imagine people might have many markdown files which are documentation and contain examples; it would be nice to be able to specify additional .md files to run rustdoc --test on in Cargo.toml.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Aug 19, 2014

Sounds like a good idea! We could at least start out with a README and expand it with a manifest key later on.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Aug 27, 2014

Some concerns were raised in #445 which are applicable to this as well.

@tomaka

This comment has been minimized.

Copy link
Contributor

tomaka commented Aug 27, 2014

The question is: how will README interact with the Cargo registry?

Currently the examples are in the README file mainly because it's easy to read when you discover a library on github.

But if the registry automatically provides the rustdoc output of each package, then I think that the basic examples should simply be in the crate root documentation, just like the standard regex and green crates do.

@skade

This comment has been minimized.

Copy link

skade commented Nov 22, 2014

I'd like to have this feature. Broken README code is worse then broken code in the crate docs, as this is the first place where people go to. Outdated READMEs are even worse of an issue, a thing tested READMEs elegantly circumvent.

Also, I prefer writing README code, as crate documentation is a bit cumbersume and hard to read in source, given the amount of comment characters it needs.

Rust code can be highlighted on github and ignored by using:

   ```{.rust .ignore}

(this currently is parsed correctly, but not properly picked up. {.ignore .rust} works. I'll file a bug on rustdoc after validating)

As a middleground, my suggestion is to allow listing additional documents to test with rustdoc in the Manifest and generate a Cargo.toml including "README.md" in that list per default. This raises awareness of the feature, but ultimately leaves the user in control.

@skade

This comment has been minimized.

Copy link

skade commented Feb 5, 2015

I'd like to push this one, I just ran into precisely the problem that my README examples were the only ones broken.

@pzol

This comment has been minimized.

Copy link

pzol commented Feb 5, 2015

+1

@pythonesque

This comment has been minimized.

Copy link

pythonesque commented Feb 5, 2015

I would love this.

Concerns can be addressed by making the feature opt-in (and maybe also with attribute metadata, but I don't know markdown well enough to know if that's a thing).

@moonglum

This comment has been minimized.

Copy link

moonglum commented Feb 6, 2015

👍

@s-panferov

This comment has been minimized.

Copy link

s-panferov commented Feb 6, 2015

Always forget to update README.md in my projects 👍

@huonw huonw referenced this issue May 27, 2015

Open

README testing #4

@huonw

This comment has been minimized.

Copy link
Member Author

huonw commented Jul 20, 2015

@carols10cents

This comment has been minimized.

Copy link
Member

carols10cents commented May 10, 2017

potentially relevant: rust-lang/rfcs#1990

@abonander

This comment has been minimized.

Copy link

abonander commented Jan 23, 2019

The external docs include feature (RFC 1990) is definitely the best way to go about this, IMO. You could include your README.md as the docs for a hidden item and then rustdoc should be able to automatically test the examples. There's a bit of engineering effort left to make it stabilizable though.

@abonander

This comment has been minimized.

Copy link

abonander commented Jan 25, 2019

In case anyone missed it, I've got a proof-of-concept project for using the external_doc feature to test code examples in README.md: https://github.com/abonander/readme-doctest-poc

This can be done conditionally under a Cargo feature so it doesn't require nightly to test.

cc rust-lang/rust#44732 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.