2017-07-10 18:17:19 +08:00
|
|
|
extern crate mdbook;
|
2018-01-17 06:13:47 +08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2017-07-10 18:17:19 +08:00
|
|
|
|
2017-11-16 15:51:12 +08:00
|
|
|
mod dummy_book;
|
2017-09-02 07:40:39 +08:00
|
|
|
|
2017-11-16 15:51:12 +08:00
|
|
|
use dummy_book::DummyBook;
|
2018-01-17 06:13:47 +08:00
|
|
|
|
2017-07-10 18:17:19 +08:00
|
|
|
use mdbook::MDBook;
|
2018-01-17 06:13:47 +08:00
|
|
|
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
|
|
|
|
use mdbook::book::Book;
|
|
|
|
use mdbook::config::Config;
|
|
|
|
use mdbook::errors::*;
|
2017-07-10 18:17:19 +08:00
|
|
|
|
2018-01-17 06:13:47 +08:00
|
|
|
use std::sync::Mutex;
|
2017-07-10 18:17:19 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mdbook_can_correctly_test_a_passing_book() {
|
2017-11-16 15:51:12 +08:00
|
|
|
let temp = DummyBook::new().with_passing_test(true).build().unwrap();
|
2017-11-18 20:41:04 +08:00
|
|
|
let mut md = MDBook::load(temp.path()).unwrap();
|
2017-07-10 18:17:19 +08:00
|
|
|
|
|
|
|
assert!(md.test(vec![]).is_ok());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mdbook_detects_book_with_failing_tests() {
|
2017-11-16 15:51:12 +08:00
|
|
|
let temp = DummyBook::new().with_passing_test(false).build().unwrap();
|
2017-11-18 20:41:04 +08:00
|
|
|
let mut md: MDBook = MDBook::load(temp.path()).unwrap();
|
2017-07-10 18:17:19 +08:00
|
|
|
|
|
|
|
assert!(md.test(vec![]).is_err());
|
2017-09-02 07:40:39 +08:00
|
|
|
}
|
2018-01-17 06:13:47 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mdbook_runs_preprocessors() {
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref HAS_RUN: Mutex<bool> = Mutex::new(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DummyPreprocessor;
|
|
|
|
|
|
|
|
impl Preprocessor for DummyPreprocessor {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"dummy"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(&self, _ctx: &PreprocessorContext, _book: &mut Book) -> Result<()> {
|
|
|
|
*HAS_RUN.lock().unwrap() = true;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let temp = DummyBook::new().build().unwrap();
|
|
|
|
let cfg = Config::default();
|
|
|
|
|
|
|
|
let mut book = MDBook::load_with_config(temp.path(), cfg).unwrap();
|
|
|
|
book.with_preprecessor(DummyPreprocessor);
|
|
|
|
book.build().unwrap();
|
|
|
|
|
|
|
|
assert!(*HAS_RUN.lock().unwrap())
|
|
|
|
}
|