mdBook/tests/alternate_backends.rs
Michael Bryan fd7e8d1b7b
Add support for alternative backends (#507)
* Added a mechanism for creating alternate backends

* Added a CmdRenderer and the ability to have multiple renderers

* Made MDBook::load() autodetect renderers

* Added a couple methods to RenderContext

* Converted RenderContext.version to a String

* Made sure all alternate renderers are invoked as `mdbook-*`

* Factored out the logic for determining which renderer to use

* Added tests for renderer detection

* Made it so `mdbook test` works on the book-example again

* Updated the "For Developers" docs

* Removed `[output.epub]` from the example book's book.toml

* Added a bit more info on how backends should work

* Added a `destination` key to the RenderContext

* Altered how we wait for an alternate backend to finish

* Refactored the Renderer trait to not use MDBook and moved livereload to the template

* Moved info for developers out of the book.toml format chapter

* MOAR docs

* MDBook::build() no longer takes &mut self

* Replaced a bunch of println!()'s with proper log macros

* Cleaned up the build() method and backend discovery

* Added a couple notes and doc-comments

* Found a race condition when backends exit really quickly

* Added support for backends with arguments

* Fixed a funny doc-comment
2018-01-07 22:10:48 +08:00

45 lines
988 B
Rust

//! Integration tests to make sure alternate backends work.
extern crate mdbook;
extern crate tempdir;
use tempdir::TempDir;
use mdbook::config::Config;
use mdbook::MDBook;
#[test]
fn passing_alternate_backend() {
let (md, _temp) = dummy_book_with_backend("passing", "true");
md.build().unwrap();
}
#[test]
fn failing_alternate_backend() {
let (md, _temp) = dummy_book_with_backend("failing", "false");
md.build().unwrap_err();
}
#[test]
fn alternate_backend_with_arguments() {
let (md, _temp) = dummy_book_with_backend("arguments", "echo Hello World!");
md.build().unwrap();
}
fn dummy_book_with_backend(name: &str, command: &str) -> (MDBook, TempDir) {
let temp = TempDir::new("mdbook").unwrap();
let mut config = Config::default();
config
.set(format!("output.{}.command", name), command)
.unwrap();
let md = MDBook::init(temp.path())
.with_config(config)
.build()
.unwrap();
(md, temp)
}