From 25b9acc32195126a5192c35afac7d4d6e0771150 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 22 Apr 2025 11:06:48 -0700 Subject: [PATCH] Migrate empty theme to BookTest --- tests/rendered_output.rs | 35 ------------------- tests/testsuite/theme.rs | 13 +++++++ tests/testsuite/theme/empty_theme/book.toml | 5 +++ .../theme/empty_theme/src/SUMMARY.md | 3 ++ .../theme/empty_theme/src/chapter_1.md | 1 + 5 files changed, 22 insertions(+), 35 deletions(-) create mode 100644 tests/testsuite/theme/empty_theme/book.toml create mode 100644 tests/testsuite/theme/empty_theme/src/SUMMARY.md create mode 100644 tests/testsuite/theme/empty_theme/src/chapter_1.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 9f026839..bd52b551 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -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. diff --git a/tests/testsuite/theme.rs b/tests/testsuite/theme.rs index e403b6c4..c1c39227 100644 --- a/tests/testsuite/theme.rs +++ b/tests/testsuite/theme.rs @@ -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 + +"#]]); + }); +} diff --git a/tests/testsuite/theme/empty_theme/book.toml b/tests/testsuite/theme/empty_theme/book.toml new file mode 100644 index 00000000..1c3ab31e --- /dev/null +++ b/tests/testsuite/theme/empty_theme/book.toml @@ -0,0 +1,5 @@ +[book] +title = "empty_theme" + +[output.html] +theme = "./theme" diff --git a/tests/testsuite/theme/empty_theme/src/SUMMARY.md b/tests/testsuite/theme/empty_theme/src/SUMMARY.md new file mode 100644 index 00000000..7390c828 --- /dev/null +++ b/tests/testsuite/theme/empty_theme/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Chapter 1](./chapter_1.md) diff --git a/tests/testsuite/theme/empty_theme/src/chapter_1.md b/tests/testsuite/theme/empty_theme/src/chapter_1.md new file mode 100644 index 00000000..b743fda3 --- /dev/null +++ b/tests/testsuite/theme/empty_theme/src/chapter_1.md @@ -0,0 +1 @@ +# Chapter 1