2018-09-16 14:49:52 +00:00
|
|
|
extern crate mdbook;
|
|
|
|
|
2018-09-16 15:33:58 +00:00
|
|
|
mod dummy_book;
|
|
|
|
|
|
|
|
use dummy_book::DummyBook;
|
2018-09-16 14:49:52 +00:00
|
|
|
use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
|
2018-09-16 15:23:03 +00:00
|
|
|
use mdbook::MDBook;
|
2018-09-16 14:49:52 +00:00
|
|
|
|
|
|
|
fn example() -> CmdPreprocessor {
|
2018-12-03 23:11:41 +00:00
|
|
|
CmdPreprocessor::new(
|
|
|
|
"nop-preprocessor".to_string(),
|
|
|
|
"cargo run --example nop-preprocessor --".to_string(),
|
|
|
|
)
|
2018-09-16 14:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-09-16 15:00:19 +00:00
|
|
|
fn example_supports_whatever() {
|
2018-09-16 14:49:52 +00:00
|
|
|
let cmd = example();
|
|
|
|
|
|
|
|
let got = cmd.supports_renderer("whatever");
|
|
|
|
|
|
|
|
assert_eq!(got, true);
|
|
|
|
}
|
2018-09-16 15:00:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn example_doesnt_support_not_supported() {
|
|
|
|
let cmd = example();
|
|
|
|
|
|
|
|
let got = cmd.supports_renderer("not-supported");
|
|
|
|
|
|
|
|
assert_eq!(got, false);
|
|
|
|
}
|
2018-09-16 15:23:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ask_the_preprocessor_to_blow_up() {
|
2018-09-16 15:33:58 +00:00
|
|
|
let dummy_book = DummyBook::new();
|
|
|
|
let temp = dummy_book.build().unwrap();
|
|
|
|
let mut md = MDBook::load(temp.path()).unwrap();
|
2019-05-03 18:32:56 +00:00
|
|
|
md.with_preprocessor(example());
|
2018-09-16 15:23:03 +00:00
|
|
|
|
2018-12-03 23:11:41 +00:00
|
|
|
md.config
|
|
|
|
.set("preprocessor.nop-preprocessor.blow-up", true)
|
|
|
|
.unwrap();
|
2018-09-16 15:23:03 +00:00
|
|
|
|
|
|
|
let got = md.build();
|
|
|
|
|
|
|
|
assert!(got.is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn process_the_dummy_book() {
|
2018-09-16 15:33:58 +00:00
|
|
|
let dummy_book = DummyBook::new();
|
|
|
|
let temp = dummy_book.build().unwrap();
|
|
|
|
let mut md = MDBook::load(temp.path()).unwrap();
|
2019-05-03 18:32:56 +00:00
|
|
|
md.with_preprocessor(example());
|
2018-09-16 15:23:03 +00:00
|
|
|
|
|
|
|
md.build().unwrap();
|
|
|
|
}
|