2018-01-07 22:10:48 +08:00
|
|
|
//! Integration tests to make sure alternate backends work.
|
|
|
|
|
|
|
|
extern crate mdbook;
|
2018-03-27 07:47:37 +08:00
|
|
|
extern crate tempfile;
|
2018-01-07 22:10:48 +08:00
|
|
|
|
2018-03-27 07:47:37 +08:00
|
|
|
use tempfile::{TempDir, Builder as TempFileBuilder};
|
2018-01-07 22:10:48 +08:00
|
|
|
use mdbook::config::Config;
|
|
|
|
use mdbook::MDBook;
|
|
|
|
|
|
|
|
#[test]
|
2018-04-23 02:36:02 +08:00
|
|
|
#[cfg_attr(all(windows, not(feature = "win-bash-tests")), ignore)]
|
2018-01-07 22:10:48 +08:00
|
|
|
fn passing_alternate_backend() {
|
|
|
|
let (md, _temp) = dummy_book_with_backend("passing", "true");
|
|
|
|
|
|
|
|
md.build().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-04-23 02:36:02 +08:00
|
|
|
#[cfg_attr(all(windows, not(feature = "win-bash-tests")), ignore)]
|
2018-01-07 22:10:48 +08:00
|
|
|
fn failing_alternate_backend() {
|
|
|
|
let (md, _temp) = dummy_book_with_backend("failing", "false");
|
|
|
|
|
|
|
|
md.build().unwrap_err();
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:15:29 +08:00
|
|
|
#[test]
|
|
|
|
fn missing_backends_arent_fatal() {
|
|
|
|
let (md, _temp) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn");
|
|
|
|
|
|
|
|
assert!(md.build().is_ok());
|
|
|
|
}
|
|
|
|
|
2018-01-07 22:10:48 +08:00
|
|
|
#[test]
|
|
|
|
fn alternate_backend_with_arguments() {
|
|
|
|
let (md, _temp) = dummy_book_with_backend("arguments", "echo Hello World!");
|
|
|
|
|
|
|
|
md.build().unwrap();
|
|
|
|
}
|
|
|
|
|
2018-01-14 19:14:27 +08:00
|
|
|
#[test]
|
2018-04-23 02:36:02 +08:00
|
|
|
#[cfg_attr(windows, ignore)]
|
2018-01-14 19:14:27 +08:00
|
|
|
fn backends_receive_render_context_via_stdin() {
|
2018-03-07 21:02:06 +08:00
|
|
|
use std::fs::File;
|
|
|
|
use mdbook::renderer::RenderContext;
|
|
|
|
|
2018-03-27 07:47:37 +08:00
|
|
|
let temp = TempFileBuilder::new().prefix("output").tempdir().unwrap();
|
2018-01-14 19:14:27 +08:00
|
|
|
let out_file = temp.path().join("out.txt");
|
2018-04-23 02:36:02 +08:00
|
|
|
let cmd = format!("tee {}", out_file.display());
|
2018-01-14 19:14:27 +08:00
|
|
|
|
|
|
|
let (md, _temp) = dummy_book_with_backend("cat-to-file", &cmd);
|
|
|
|
|
|
|
|
assert!(!out_file.exists());
|
|
|
|
md.build().unwrap();
|
|
|
|
assert!(out_file.exists());
|
|
|
|
|
|
|
|
let got = RenderContext::from_json(File::open(&out_file).unwrap());
|
|
|
|
assert!(got.is_ok());
|
|
|
|
}
|
|
|
|
|
2018-01-07 22:10:48 +08:00
|
|
|
fn dummy_book_with_backend(name: &str, command: &str) -> (MDBook, TempDir) {
|
2018-03-27 07:47:37 +08:00
|
|
|
let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap();
|
2018-01-07 22:10:48 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|