Migrate ask_the_preprocessor_to_blow_up to BookTest

This commit is contained in:
Eric Huss 2025-04-21 19:20:51 -07:00
parent fca149a52c
commit d815b0cc52
4 changed files with 20 additions and 28 deletions

View file

@ -28,31 +28,3 @@ fn example_doesnt_support_not_supported() {
assert_eq!(got, false);
}
#[test]
fn ask_the_preprocessor_to_blow_up() {
let dummy_book = DummyBook::new();
let temp = dummy_book.build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
md.with_preprocessor(example());
md.config
.set("preprocessor.nop-preprocessor.blow-up", true)
.unwrap();
let got = md.build();
assert!(got.is_err());
let error_message = got.err().unwrap().to_string();
let status = if cfg!(windows) {
"exit code: 1"
} else {
"exit status: 1"
};
assert_eq!(
error_message,
format!(
r#"The "nop-preprocessor" preprocessor exited unsuccessfully with {status} status"#
)
);
}

View file

@ -52,3 +52,19 @@ fn nop_preprocessor() {
"#]]);
});
}
// Failing preprocessor generates an error.
#[test]
fn failing_preprocessor() {
BookTest::from_dir("preprocessor/failing_preprocessor")
.run("build", |cmd| {
cmd.expect_failure()
.expect_stdout(str![[""]])
.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
Boom!!1!
[TIMESTAMP] [ERROR] (mdbook::utils): Error: The "nop-preprocessor" preprocessor exited unsuccessfully with [EXIT_STATUS]: 1 status
"#]]);
});
}

View file

@ -0,0 +1,4 @@
[preprocessor.nop-preprocessor]
command = "cargo run --quiet --example nop-preprocessor --"
blow-up = true