Hi I feel like I'm going crazy, but do I have wrong syntax here or something? My understanding was that docs are tested but I tried it and it doesn't get caught, I don't know what I'm doing wrong.
I'd expect the test to fail because both I haven't namespaced the method correctly and do the wrong calculation, but it appears to not be run?
cargo 1.44.1 (88ba85757 2020-06-11)
I was looking at the following: https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html
You can see in the output I'm just running cargo test

If you notice this message:
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
No test is being run at all.
You'll have to move that code to a lib.rs file. Notice that in the documentation you linked also mentions the example file being Filename: src/lib.rs.
More generally, doctests don't work bin targets (where your main.rs is your entry point). There's a current open issue on the topic: https://github.com/rust-lang/rust/issues/50784
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With