Skip to content

Commit 25c47ed

Browse files
committed
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.
1 parent 0f0d1f3 commit 25c47ed

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

tests/testsuite/book_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ enum StatusCode {
2222
pub struct BookTest {
2323
/// The temp directory where the test should perform its work.
2424
pub dir: PathBuf,
25-
assert: snapbox::Assert,
25+
/// Snapshot assertion support.
26+
pub assert: snapbox::Assert,
2627
/// This indicates whether or not the book has been built.
2728
built: bool,
2829
}

tests/testsuite/preprocessor.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,27 @@ fn missing_optional_not_fatal() {
180180
"#]]);
181181
});
182182
}
183+
184+
// with_preprocessor of an existing name.
185+
#[test]
186+
fn with_preprocessor_same_name() {
187+
let mut test = BookTest::init(|_| {});
188+
test.change_file(
189+
"book.toml",
190+
"[preprocessor.dummy]\n\
191+
command = 'mdbook-preprocessor-does-not-exist'\n",
192+
);
193+
let spy: Arc<Mutex<Inner>> = Default::default();
194+
let mut book = test.load_book();
195+
book.with_preprocessor(Spy(Arc::clone(&spy)));
196+
let err = book.build().unwrap_err();
197+
test.assert.eq(
198+
format!("{err:?}"),
199+
str![[r#"
200+
Unable to run the preprocessor `dummy`
201+
202+
Caused by:
203+
[NOT_FOUND]
204+
"#]],
205+
);
206+
}

tests/testsuite/renderer.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,28 @@ fn relative_command_path() {
241241
})
242242
.check_file("book/output", "test");
243243
}
244+
245+
// with_renderer of an existing name.
246+
#[test]
247+
fn with_renderer_same_name() {
248+
let mut test = BookTest::init(|_| {});
249+
test.change_file(
250+
"book.toml",
251+
"[output.dummy]\n\
252+
command = 'mdbook-renderer-does-not-exist'\n",
253+
);
254+
let spy: Arc<Mutex<Inner>> = Default::default();
255+
let mut book = test.load_book();
256+
book.with_renderer(Spy(Arc::clone(&spy)));
257+
let err = book.build().unwrap_err();
258+
test.assert.eq(
259+
format!("{err:?}"),
260+
str![[r#"
261+
Rendering failed
262+
263+
Caused by:
264+
0: Unable to run the backend `dummy`
265+
1: [NOT_FOUND]
266+
"#]],
267+
);
268+
}

0 commit comments

Comments
 (0)