2017-07-10 18:17:19 +08:00
|
|
|
extern crate mdbook;
|
|
|
|
|
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
|
|
|
|
|
|
|
use mdbook::book::Book;
|
|
|
|
use mdbook::config::Config;
|
|
|
|
use mdbook::errors::*;
|
2018-07-24 01:45:01 +08:00
|
|
|
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
|
|
|
|
use mdbook::MDBook;
|
2017-07-10 18:17:19 +08:00
|
|
|
|
2018-01-18 03:02:25 +08:00
|
|
|
use std::sync::{Arc, 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();
|
2018-07-26 01:17:17 +08:00
|
|
|
let mut md = 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() {
|
2018-01-18 03:02:25 +08:00
|
|
|
let has_run: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
|
2018-01-17 06:13:47 +08:00
|
|
|
|
2018-01-18 03:02:25 +08:00
|
|
|
struct DummyPreprocessor(Arc<Mutex<bool>>);
|
2018-01-17 06:13:47 +08:00
|
|
|
|
|
|
|
impl Preprocessor for DummyPreprocessor {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"dummy"
|
|
|
|
}
|
|
|
|
|
2018-08-30 21:31:14 +08:00
|
|
|
fn run(&self, _ctx: &PreprocessorContext, book: Book) -> Result<Book> {
|
2018-01-18 03:02:25 +08:00
|
|
|
*self.0.lock().unwrap() = true;
|
2018-08-30 21:31:14 +08:00
|
|
|
Ok(book)
|
2018-01-17 06:13:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let temp = DummyBook::new().build().unwrap();
|
|
|
|
let cfg = Config::default();
|
|
|
|
|
|
|
|
let mut book = MDBook::load_with_config(temp.path(), cfg).unwrap();
|
2018-01-18 03:02:25 +08:00
|
|
|
book.with_preprecessor(DummyPreprocessor(Arc::clone(&has_run)));
|
2018-01-17 06:13:47 +08:00
|
|
|
book.build().unwrap();
|
|
|
|
|
2018-01-18 03:02:25 +08:00
|
|
|
assert!(*has_run.lock().unwrap())
|
2018-01-17 06:13:47 +08:00
|
|
|
}
|