-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add ability to reference 3rd-party crates #706
Comments
There appears to be a
fails with:
Whoops, even with a fresh build I still have three versions of rand to choose from! Perhaps the |
@dhardy Yeah, I like the suggestion about |
I'm making a suggestion in passing, nothing more. |
I know, but it's worth pursuing probably. |
Too right, and it makes it impossible to test my book properly: rust-random/book#1 Apparently another copy of |
I've been thinking about rewriting If someone wants to champion this feature,
Starting off as a plugin would let us iterate quickly outside the |
Just a tiny note: currently when I need to test code examples from the book part, I use doc-comment. With the add of |
Inspired by doc-comment, this is what I am using, in #[cfg(doctest)]
mod booktest {
macro_rules! booktest {
($i:ident) => {
#[doc = include_str!(concat!("../../book/", stringify!($i), ".md"))]
mod $i {}
}
}
booktest!(example_1);
booktest!(example_2);
} Note that because of Shows up like this when running
|
A derivative of the above, automating generation of test targets: https://github.com/rust-random/book/tree/master/tests # generate.sh
mkdir -p src
cat << EOF > src/lib.rs
#![allow(non_snake_case)]
#[macro_use]
extern crate doc_comment;
EOF
for doc in ../src/*.md
do
NAME=$(basename $doc .md)
NAME=${NAME//./_}
NAME=${NAME//-/_}
echo -e "doctest\041(\"../$doc\");" > src/$NAME.rs
echo "mod $NAME;" >> src/lib.rs
done Test steps: - name: Generate harness
working-directory: ./tests
run: ./generate.sh
- name: Test code samples
working-directory: ./tests
run: cargo test |
I'm just wondering if anyone has taken this on and made a mdBook extension as was suggested here? I'm working on a book for nom, and becoming frustrated with the way testing works currently. I have three main things I think would significantly improve the experience of editing a book:
If nobody is working on this, when some time frees up for me, I might have a go. (Some further reading indicates |
After looking into this, I think what makes sense is to write a preprocessor, which:
Two relatively big design decisions seem important to mention though:
These would both be relatively easy to achieve using the functions exposed by My remaining questions then:
|
Good news! v0.1.0 of my proposed crate has now been published, as mdbook-keeper. At the moment, it is an MVP. It:
As of yet, it does not:
I'd really appreciate feedback on this. Hopefully if enough projects use it, it's something we can bring into mdBook proper. |
Hey @tfpk, thanks for creating mdbook-keeper! I'm looking into using it for a Rust course I've written: google/comprehensive-rust#175. |
That's great to know! Hope it works out for you, and feel free to let me know if there are any issues :) |
Currently all tests are ignored. mdbook can't easily link to crates, see rust-lang/mdBook#706 for details.
- Loading with memmap - Loading a sharded tensor - Moved some snippets to `candle-examples/src/lib.rs` This is because managing book specific dependencies is a pain rust-lang/mdBook#706 - This causes a non aligned inclusion rust-lang/mdBook#1856 which we have to ignore fmt to remove. mdbook might need some more love :)
- Loading with memmap - Loading a sharded tensor - Moved some snippets to `candle-examples/src/lib.rs` This is because managing book specific dependencies is a pain rust-lang/mdBook#706 - This causes a non aligned inclusion rust-lang/mdBook#1856 which we have to ignore fmt to remove. mdbook might need some more love :)
- Loading with memmap - Loading a sharded tensor - Moved some snippets to `candle-examples/src/lib.rs` This is because managing book specific dependencies is a pain rust-lang/mdBook#706 - This causes a non aligned inclusion rust-lang/mdBook#1856 which we have to ignore fmt to remove. mdbook might need some more love :)
- Loading with memmap - Loading a sharded tensor - Moved some snippets to `candle-examples/src/lib.rs` This is because managing book specific dependencies is a pain rust-lang/mdBook#706 - This causes a non aligned inclusion rust-lang/mdBook#1856 which we have to ignore fmt to remove. mdbook might need some more love :)
- Loading with memmap - Loading a sharded tensor - Moved some snippets to `candle-examples/src/lib.rs` This is because managing book specific dependencies is a pain rust-lang/mdBook#706 - This causes a non aligned inclusion rust-lang/mdBook#1856 which we have to ignore fmt to remove. mdbook might need some more love :)
cee4953 feat: cookbook (Einherjar) Pull request description: - [x] Convert `build.sh` to a GitHub Actions and closes #6. - [x] Automated CI in GitHub Actions that test all the code in the cookbook: `.github/workflows/test.yml` - [x] Automated scheduled CI in GitHub Actions that check all markdown files for broken links (we are adding a LOT of links to the `rust-bitcoin` docs): `.github/workflows/check-links.yml` - [x] Dependabot to update (weekly) `.github/dependabot.yml`: - [x] GitHub Actions - [x] Test dependencies, this is good once we release `rust-bitcoin` new versions dependabot will open a PR here to update - [x] `justfile` to easy run the build and test with `just` - [x] ~~This is how you receive data over P2P~~ moved to #10. - [x] ~~This is how you parse blocks and transactions~~ moved to #11. - [x] This is how you construct and sign transactions - [x] [TABConf 2023 segwit signing exercise](https://github.com/tcharding/workshop/tree/master/sign-segwit-v0) - [x] [TABConf 2023 taproot signing exercise](https://github.com/tcharding/workshop/tree/master/sign-taproot) ## Details I want this cookbook to be tested automatically on CI, so the code will always run. The only solution that worked for me was [this workaround](rust-lang/mdBook#706 (comment)) that is used in [The Rust Rand Book](https://github.com/rust-random/book). ACKs for top commit: sanket1729: utACK [cee4953](cee4953). Go ahead tcharding: ACK cee4953 Tree-SHA512: 94a2349380b8dab0c913ab5665d64ae714a8afa56bef82fa47d6d03184db49472ba2b3580b4ac781be3e2356c684041ac33a15ee26aa24c284688d8e71548b22
Any updates on this ? |
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 likeextern crate foo;
.The text was updated successfully, but these errors were encountered: