Closed iddm closed 7 years ago
I have fixed this issue by myself. So, I have a usual directory structure:
projectdir ----src/ ----src/lib.rs ----Cargo.toml
To add skeptic
here we must to make our library a workspace (this will reduce compile time a lot and is better by some other reasons) and then create the submodule in the workspace - create a directory, called, for example, external_markdown_tests
, put a Cargo.toml
there with contents:
[package]
name = "external_markdown_tests"
version = "0.1.0"
build = "build.rs"
[build-dependencies]
skeptic = "0.9"
[dev-dependencies]
skeptic = "0.9"
toornament = { path = "../" }
My library is called toornament
so replace it with yours.
Then add add an empty library source there (src/lib.rs
). Then create a build script build.rs
:
extern crate skeptic;
fn main() {
skeptic::generate_doc_tests(&["../README.md"]);
}
Then create a tests
directory where you use the generated tests:
include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs"));
That's all. Simply go to this directory and run the tests via cargo test
.
I see no way to test the crate inside itself. It seems that I can't add my own crate to the
dev
andbuild
dependencies to make tests fromREADME.md
work, it needs to change the project hierarchy. More detailed, I have a simple library crate. It has a book inprojectdir/book
directory and a readme file inprojectdir
directory. What should I do to run tests inREADME.md
? The code samples in myREADME.md
haveextern crate
lines but theskeptic
can't find them.