Skip to content

Commit

Permalink
Moved build process tests out into their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Apr 7, 2018
1 parent 78be7f3 commit e84136c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 35 deletions.
61 changes: 61 additions & 0 deletions tests/build_process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
extern crate mdbook;

mod dummy_book;

use dummy_book::DummyBook;
use mdbook::MDBook;
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use mdbook::renderer::{Renderer, RenderContext};
use mdbook::book::Book;
use mdbook::config::Config;
use mdbook::errors::*;

use std::sync::{Arc, Mutex};

struct DummyPreprocessor(Arc<Mutex<bool>>);

impl Preprocessor for DummyPreprocessor {
fn name(&self) -> &str {
"dummy"
}

fn run(&self, _ctx: &PreprocessorContext, book: Book) -> Result<Book> {
*self.0.lock().unwrap() = true;
Ok(book)
}
}

/// A dummy renderer with a custom name.
struct DummyRenderer(Arc<Mutex<bool>>, &'static str);

impl Renderer for DummyRenderer {
fn name(&self) -> &str {
self.1
}

fn render(&self, ctx: &RenderContext) -> Result<()> {
*self.0.lock().unwrap() = true;
Ok(())
}
}

#[test]
fn mdbook_runs_preprocessors() {
let has_run: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));

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(Arc::clone(&has_run)));
book.build().unwrap();

assert!(*has_run.lock().unwrap())
}

/// Specify a preprocessor and it should work with *only* the one specific
/// renderer.
#[test]
fn name() {

}
35 changes: 0 additions & 35 deletions tests/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ extern crate mdbook;
mod dummy_book;

use dummy_book::DummyBook;

use mdbook::MDBook;
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use mdbook::book::Book;
use mdbook::config::Config;
use mdbook::errors::*;

use std::sync::{Arc, Mutex};

#[test]
fn mdbook_can_correctly_test_a_passing_book() {
Expand All @@ -27,31 +20,3 @@ fn mdbook_detects_book_with_failing_tests() {

assert!(md.test(vec![]).is_err());
}

#[test]
fn mdbook_runs_preprocessors() {

let has_run: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));

struct DummyPreprocessor(Arc<Mutex<bool>>);

impl Preprocessor for DummyPreprocessor {
fn name(&self) -> &str {
"dummy"
}

fn run(&self, _ctx: &PreprocessorContext, book: Book) -> Result<Book> {
*self.0.lock().unwrap() = true;
Ok(book)
}
}

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(Arc::clone(&has_run)));
book.build().unwrap();

assert!(*has_run.lock().unwrap())
}

0 comments on commit e84136c

Please sign in to comment.