From 4177288b11ba5c965a274e7377bc45c41faef713 Mon Sep 17 00:00:00 2001 From: Jaime Valdemoros Date: Tue, 16 Jan 2018 22:13:47 +0000 Subject: [PATCH] Add test to make sure pre-processors are being run --- src/lib.rs | 2 +- tests/testing.rs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 163f3619..08c4c37e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/tests/testing.rs b/tests/testing.rs index 8e060eb7..a61c8ec5 100644 --- a/tests/testing.rs +++ b/tests/testing.rs @@ -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 = 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()) +}