You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to have the ability to reference 3rd-party (e.g. crates.io) crates, for the sake of things like mdbook test, which currently fail when doing something like extern crate foo;.
mgeisler, max-sixty, tgross35, chriskrycho and scarf005
I've been thinking about rewriting mdbook test for a while now but haven't really had the time or known if the demand is there. At the moment we just shell out to rustdoc and effectively run rustdoc --test path/to/chapter.md for each chapter in the book, passing the -L argument straight through. It's clunky because we're directly calling rustdoc when cargo would normally set up all the dependency stuff for you.
If someone wants to champion this feature, mdbook already has pretty decent plugin support and lets you provide your own program for consuming a book and doing something with it. As an example of a backend which processes a book instead of rendering it, mdbook-linkcheck will validate all links in a book. So It's possible to create a backend which will:
Create an empty crate under the output directory
Dump the contents of each chapter into individual files in this crate
Add the necessary dependencies to Cargo.toml
Use rust-skeptic to generate the corresponding test code
Starting off as a plugin would let us iterate quickly outside the mdbook repository, possibly merging it into mdbook as a built-in renderer if that makes sense. I'd be happy to help out with reviewing and mentoring if needed 🙂
Just a tiny note: currently when I need to test code examples from the book part, I use doc-comment. With the add of cfg(doctest), it only runs on test so it can be a dev-dependency and has the advantage to not force you to rebuild everytime (which is a down side of rust-skeptic).
Activity
dhardy commentedon Oct 22, 2018
There appears to be a
-L
option to help here, but it leaves a lot to be desired. E.g.:fails with:
Whoops, even with a fresh build I still have three versions of rand to choose from!
Perhaps the
book.toml
should contain adependencies
section (ordev-dependencies
) likeCargo.toml
does?alexreg commentedon Oct 22, 2018
@dhardy Yeah, I like the suggestion about
book.toml
(shouldn't we name itMdBook.toml
or something for consistency?)dhardy commentedon Oct 22, 2018
I'm making a suggestion in passing, nothing more.
alexreg commentedon Oct 22, 2018
I know, but it's worth pursuing probably.
dhardy commentedon Oct 23, 2018
Too right, and it makes it impossible to test my book properly: rust-random/book#1
Apparently another copy of
rand
is already provided by rustup — but it's not the version I want to test against.Michael-F-Bryan commentedon Oct 23, 2018
I've been thinking about rewriting
mdbook test
for a while now but haven't really had the time or known if the demand is there. At the moment we just shell out torustdoc
and effectively runrustdoc --test path/to/chapter.md
for each chapter in the book, passing the-L
argument straight through. It's clunky because we're directly callingrustdoc
whencargo
would normally set up all the dependency stuff for you.If someone wants to champion this feature,
mdbook
already has pretty decent plugin support and lets you provide your own program for consuming a book and doing something with it. As an example of a backend which processes a book instead of rendering it, mdbook-linkcheck will validate all links in a book. So It's possible to create a backend which will:Cargo.toml
Starting off as a plugin would let us iterate quickly outside the
mdbook
repository, possibly merging it intomdbook
as a built-in renderer if that makes sense. I'd be happy to help out with reviewing and mentoring if needed 🙂edition2018
attribute rust-lang/rust#58875mdbook test
? #1006GuillaumeGomez commentedon Jun 21, 2020
Just a tiny note: currently when I need to test code examples from the book part, I use doc-comment. With the add of
cfg(doctest)
, it only runs on test so it can be a dev-dependency and has the advantage to not force you to rebuild everytime (which is a down side of rust-skeptic).31 remaining items