Migrate failing_alternate_backend to BookTest
This commit is contained in:
parent
5bc25e32eb
commit
a2cf838baf
2 changed files with 36 additions and 15 deletions
|
|
@ -6,13 +6,6 @@ use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tempfile::{Builder as TempFileBuilder, TempDir};
|
use tempfile::{Builder as TempFileBuilder, TempDir};
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn failing_alternate_backend() {
|
|
||||||
let (md, _temp) = dummy_book_with_backend("failing", fail_cmd(), false);
|
|
||||||
|
|
||||||
md.build().unwrap_err();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn missing_backends_are_fatal() {
|
fn missing_backends_are_fatal() {
|
||||||
let (md, _temp) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn", false);
|
let (md, _temp) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn", false);
|
||||||
|
|
@ -128,14 +121,6 @@ fn dummy_book_with_backend(
|
||||||
(md, temp)
|
(md, temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fail_cmd() -> &'static str {
|
|
||||||
if cfg!(windows) {
|
|
||||||
r#"cmd.exe /c "exit 1""#
|
|
||||||
} else {
|
|
||||||
"false"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rust_exe(temp: &Path, name: &str, src: &str) {
|
fn rust_exe(temp: &Path, name: &str, src: &str) {
|
||||||
let rs = temp.join(name).with_extension("rs");
|
let rs = temp.join(name).with_extension("rs");
|
||||||
fs::write(&rs, src).unwrap();
|
fs::write(&rs, src).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,39 @@ fn runs_renderers() {
|
||||||
let inner = spy.lock().unwrap();
|
let inner = spy.lock().unwrap();
|
||||||
assert_eq!(inner.run_count, 1);
|
assert_eq!(inner.run_count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test renderer with a failing command fails.
|
||||||
|
#[test]
|
||||||
|
fn failing_command() {
|
||||||
|
BookTest::init(|_| {})
|
||||||
|
.rust_program(
|
||||||
|
"failing",
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
// Read from stdin to avoid random pipe failures on Linux.
|
||||||
|
use std::io::Read;
|
||||||
|
let mut s = String::new();
|
||||||
|
std::io::stdin().read_to_string(&mut s).unwrap();
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.change_file(
|
||||||
|
"book.toml",
|
||||||
|
"[output.failing]\n\
|
||||||
|
command = './failing'\n",
|
||||||
|
)
|
||||||
|
.run("build", |cmd| {
|
||||||
|
cmd.expect_failure()
|
||||||
|
.expect_stdout(str![[""]])
|
||||||
|
.expect_stderr(str![[r#"
|
||||||
|
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
|
||||||
|
[TIMESTAMP] [INFO] (mdbook::book): Running the failing backend
|
||||||
|
[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "failing" renderer
|
||||||
|
[TIMESTAMP] [ERROR] (mdbook::renderer): Renderer exited with non-zero return code.
|
||||||
|
[TIMESTAMP] [ERROR] (mdbook::utils): Error: Rendering failed
|
||||||
|
[TIMESTAMP] [ERROR] (mdbook::utils): [TAB]Caused By: The "failing" renderer failed
|
||||||
|
|
||||||
|
"#]]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue