Add test to make sure pre-processors are being run

This commit is contained in:
Jaime Valdemoros 2018-01-16 22:13:47 +00:00
parent b599956516
commit 4177288b11
2 changed files with 40 additions and 2 deletions

View File

@ -118,7 +118,7 @@ extern crate toml_query;
#[macro_use]
extern crate pretty_assertions;
mod preprocess;
pub mod preprocess;
pub mod book;
pub mod config;
pub mod renderer;

View File

@ -1,10 +1,18 @@
extern crate mdbook;
#[macro_use]
extern crate lazy_static;
mod dummy_book;
use dummy_book::DummyBook;
use mdbook::MDBook;
use mdbook::MDBook;
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use mdbook::book::Book;
use mdbook::config::Config;
use mdbook::errors::*;
use std::sync::Mutex;
#[test]
fn mdbook_can_correctly_test_a_passing_book() {
@ -21,3 +29,33 @@ fn mdbook_detects_book_with_failing_tests() {
assert!(md.test(vec![]).is_err());
}
#[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())
}