Migrate empty theme to BookTest

This commit is contained in:
Eric Huss 2025-04-22 11:06:48 -07:00
parent 10fae8596c
commit 25b9acc321
5 changed files with 22 additions and 35 deletions

View file

@ -324,41 +324,6 @@ fn summary_with_markdown_formatting() {
);
}
/// Ensure building fails if `[output.html].theme` points to a non-existent directory
#[test]
fn failure_on_missing_theme_directory() {
// 1. Using default theme should work
let temp = DummyBook::new().build().unwrap();
let book_toml = r#"
[book]
title = "implicit"
src = "src"
"#;
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_ok());
// 2. Pointing to a normal directory should work
let temp = DummyBook::new().build().unwrap();
let created = fs::create_dir(temp.path().join("theme-directory"));
assert!(created.is_ok());
let book_toml = r#"
[book]
title = "implicit"
src = "src"
[output.html]
theme = "./theme-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_ok());
}
#[test]
fn custom_fonts() {
// Tests to ensure custom fonts are copied as expected.

View file

@ -17,3 +17,16 @@ cmd.expect_failure()
"#]]);
});
}
// Checks what happens if the theme directory is empty.
#[test]
fn empty_theme() {
BookTest::from_dir("theme/empty_theme").run("build", |cmd| {
std::fs::create_dir(cmd.dir.join("theme")).unwrap();
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
"#]]);
});
}

View file

@ -0,0 +1,5 @@
[book]
title = "empty_theme"
[output.html]
theme = "./theme"

View file

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

View file

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