Migrate missing theme to BookTest

This commit is contained in:
Eric Huss 2025-04-22 11:05:48 -07:00
parent 909bd1c54e
commit 10fae8596c
6 changed files with 29 additions and 16 deletions

View file

@ -357,22 +357,6 @@ fn failure_on_missing_theme_directory() {
let md = MDBook::load(temp.path()).unwrap();
let got = md.build();
assert!(got.is_ok());
// 3. Pointing to a non-existent directory should fail
let temp = DummyBook::new().build().unwrap();
let book_toml = r#"
[book]
title = "implicit"
src = "src"
[output.html]
theme = "./non-existent-directory"
"#;
write_file(temp.path(), "book.toml", book_toml.as_bytes()).unwrap();
let md = MDBook::load(temp.path()).unwrap();
let got = md.build();
assert!(got.is_err());
}
#[test]

View file

@ -18,6 +18,7 @@ mod rendering;
#[cfg(feature = "search")]
mod search;
mod test;
mod theme;
mod prelude {
pub use crate::book_test::BookTest;

19
tests/testsuite/theme.rs Normal file
View file

@ -0,0 +1,19 @@
//! Tests for theme handling.
use crate::prelude::*;
// Checks what happens if the theme directory is missing.
#[test]
fn missing_theme() {
BookTest::from_dir("theme/missing_theme")
.run("build", |cmd| {
cmd.expect_failure()
.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [ERROR] (mdbook::utils): Error: Rendering failed
[TIMESTAMP] [ERROR] (mdbook::utils): [TAB]Caused By: theme dir [ROOT]/./non-existent-directory does not exist
"#]]);
});
}

View file

@ -0,0 +1,5 @@
[book]
title = "missing_theme"
[output.html]
theme = "./non-existent-directory"

View file

@ -0,0 +1,3 @@
# Summary
- [Chapter 1](./chapter_1.md)

View file

@ -0,0 +1 @@
# Chapter 1