Add tests for with_renderer and with_preprocessor collisions

This adds tests with with_renderer and with_preprocessor are used with
extensions that have the same name.
This commit is contained in:
Eric Huss 2025-08-18 11:02:13 -07:00
parent 0f0d1f3377
commit 25c47ed0bc
3 changed files with 51 additions and 1 deletions

View file

@ -22,7 +22,8 @@ enum StatusCode {
pub struct BookTest {
/// The temp directory where the test should perform its work.
pub dir: PathBuf,
assert: snapbox::Assert,
/// Snapshot assertion support.
pub assert: snapbox::Assert,
/// This indicates whether or not the book has been built.
built: bool,
}

View file

@ -180,3 +180,27 @@ fn missing_optional_not_fatal() {
"#]]);
});
}
// with_preprocessor of an existing name.
#[test]
fn with_preprocessor_same_name() {
let mut test = BookTest::init(|_| {});
test.change_file(
"book.toml",
"[preprocessor.dummy]\n\
command = 'mdbook-preprocessor-does-not-exist'\n",
);
let spy: Arc<Mutex<Inner>> = Default::default();
let mut book = test.load_book();
book.with_preprocessor(Spy(Arc::clone(&spy)));
let err = book.build().unwrap_err();
test.assert.eq(
format!("{err:?}"),
str![[r#"
Unable to run the preprocessor `dummy`
Caused by:
[NOT_FOUND]
"#]],
);
}

View file

@ -241,3 +241,28 @@ fn relative_command_path() {
})
.check_file("book/output", "test");
}
// with_renderer of an existing name.
#[test]
fn with_renderer_same_name() {
let mut test = BookTest::init(|_| {});
test.change_file(
"book.toml",
"[output.dummy]\n\
command = 'mdbook-renderer-does-not-exist'\n",
);
let spy: Arc<Mutex<Inner>> = Default::default();
let mut book = test.load_book();
book.with_renderer(Spy(Arc::clone(&spy)));
let err = book.build().unwrap_err();
test.assert.eq(
format!("{err:?}"),
str![[r#"
Rendering failed
Caused by:
0: Unable to run the backend `dummy`
1: [NOT_FOUND]
"#]],
);
}