-
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
mdbook test
extern crate functionality
#394
Comments
I think the feature you are looking for has been merged in https://github.com/azerupi/mdBook/pull/340 but not yet released. Is that what you tested?
|
I have tried this. I cloned the repo, and then from the root of the book directory did
which came back with
It's totally possible I'm not understanding what It would be great from my point of view if |
@frankmcsherry At the moment I would suggest using skeptic which is designed just for that purpose (testing with multiple extern crates). It is used to great success in rust-cookbook (another project using mdbook). If you have any question regarding the the integration I'll gladly help.
edit: And I'm corrected ;) |
Ah, thank you! This is helpful info, and skeptic looks like like it fits the bill for keeping examples correct. :D Happy to close this as "understood", or leave it open if it is a longer-term goal to have the functionality. As you like. |
I'll close this as works ok. We'll just need to update the docs |
I couldn't get either cases to work is there some secret I'm not getting |
@andrewdavidmackenzie I am also struggling to get this work. Did you find a solution? |
No, I have forgotten what changed - but I think in recent versions of my book I was somehow (magically) able to just remove those extern crate statements and it all works. Sorry I can't help more. |
I wasn't able to get this to work either :( Should this issue be re-opened? |
To answer previous questions - no, I didn't find a solution to this, but haven't tried recently. |
Hi all, I too was struggling with this today. I can almost get it to work, here are the steps I took. I wanted to test an example using Tokio. So to create the magic [dependencies]
tokio = { version = "1.21.1", features = ["full"] } I created an extern crate tokio;
use std::time::Duration;
async fn sleep_then_print(timer: i32) {
println!("Start timer {}.", timer);
tokio::time::sleep(Duration::from_millis(200)).await;
println!("Timer {} done.", timer);
}
#[tokio::main]
async fn main() {
println!("Creating futures");
let f1 = sleep_then_print(1);
let f2 = sleep_then_print(2);
let f3 = sleep_then_print(3);
println!("Joining futures");
tokio::join!(f1, f2, f3);
} I ran the example once with % ls target/debug/deps/libtokio*
target/debug/deps/libtokio-53487e49f22932e2.rlib
target/debug/deps/libtokio_macros-6700705ed016b494.so
target/debug/deps/libtokio-53487e49f22932e2.rmeta With this setup, I can now include the Rust file in an # Example
```rust,edition2021
{{#include ../../examples/async.rs}}
``` Finally, I can run % mdbook test -c 'Example' -L target/debug/deps
2022-09-23 16:54:30 [INFO] (mdbook::book): Testing chapter 'Example': "async/example.md" Some things to note:
Worse, when the example changes, the workflow breaks. Something generates an additional crate file in the mdbook test -c 'Example' -L target/debug/deps
2022-09-23 16:57:55 [INFO] (mdbook::book): Testing chapter 'Example': "async/example.md"
2022-09-23 16:57:55 [ERROR] (mdbook::book): rustdoc returned an error:
--- stdout
running 1 test
test /tmp/mdbook-fUXdOO/async/example.md - Example (line 3) ... FAILED
failures:
---- /tmp/mdbook-fUXdOO/async/example.md - Example (line 3) stdout ----
error[E0464]: multiple matching crates for `tokio`
--> /tmp/mdbook-fUXdOO/async/example.md:4:1
|
2 | extern crate tokio;
| ^^^^^^^^^^^^^^^^^^^
|
= note: candidates:
crate `tokio`: .../target/debug/deps/libtokio-38e8b4ca412fced7.rmeta
crate `tokio`: .../target/debug/deps/libtokio-53487e49f22932e2.rlib
.../target/debug/deps/libtokio-53487e49f22932e2.rmeta I do see the extra file in my % ls target/debug/deps/libtokio*
target/debug/deps/libtokio-38e8b4ca412fced7.rmeta
target/debug/deps/libtokio-53487e49f22932e2.rmeta
target/debug/deps/libtokio-53487e49f22932e2.rlib
target/debug/deps/libtokio_macros-6700705ed016b494.so I have Have anybody found a more stable way to use this flag? The above seems like it could be made to work in a CI pipeline, but for daily editing of the files it's very brittle. |
Reöpening this |
Using #706 is open to add more first-class support of external crates, I don't think this needs to be reopened. For now, if you need external crates, I might suggest not using |
Thanks @ehuss, I have indeed used separate Rust files for some of my larger code snippets. I've found I'll subscribe to #706 and see how we can improve this. |
One note on @ehuss’s suggestion of making this work by using full-on crates: that does indeed work, and you must still use |
I apologize if this isn't an "issue" per se, but I've not had much luck finding answers.
Is
mdbook test
intended to work for books containing references to crates (e.g.extern crate my_crate;
)? I've tried the-L
argument, which .. I couldn't get to do anything when pointed at the associated crate root.I saw some language in other issues that perhaps
test
is mostly targeting the Rust book, and if that means no it isn't meant to work for other projects, that would be great to know. And, if I'm just doing it wrong and it should work, even better. :DThe text was updated successfully, but these errors were encountered: