From 25c47ed0bc0a7cadf9e8dc092629a21371803afc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 18 Aug 2025 11:02:13 -0700 Subject: [PATCH] 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. --- tests/testsuite/book_test.rs | 3 ++- tests/testsuite/preprocessor.rs | 24 ++++++++++++++++++++++++ tests/testsuite/renderer.rs | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/book_test.rs b/tests/testsuite/book_test.rs index 2f5e9d63..3cf6b0a4 100644 --- a/tests/testsuite/book_test.rs +++ b/tests/testsuite/book_test.rs @@ -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, } diff --git a/tests/testsuite/preprocessor.rs b/tests/testsuite/preprocessor.rs index 9fa1df1c..81b7b4e7 100644 --- a/tests/testsuite/preprocessor.rs +++ b/tests/testsuite/preprocessor.rs @@ -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> = 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] +"#]], + ); +} diff --git a/tests/testsuite/renderer.rs b/tests/testsuite/renderer.rs index a04ff0e3..4f845297 100644 --- a/tests/testsuite/renderer.rs +++ b/tests/testsuite/renderer.rs @@ -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> = 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] +"#]], + ); +}