From 0732cb47b9a4dea90aba21331fba6688140a736b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 19:03:33 -0700 Subject: [PATCH] Migrate copy_theme to BookTest --- tests/init.rs | 51 ----------------------------------------- tests/testsuite/init.rs | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 51 deletions(-) delete mode 100644 tests/init.rs diff --git a/tests/init.rs b/tests/init.rs deleted file mode 100644 index dc43bd2f..00000000 --- a/tests/init.rs +++ /dev/null @@ -1,51 +0,0 @@ -use mdbook::MDBook; -use pretty_assertions::assert_eq; -use tempfile::Builder as TempFileBuilder; - -#[test] -fn copy_theme() { - let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap(); - MDBook::init(temp.path()).copy_theme(true).build().unwrap(); - let expected = vec![ - "book.js", - "css/chrome.css", - "css/general.css", - "css/print.css", - "css/variables.css", - "favicon.png", - "favicon.svg", - "fonts/OPEN-SANS-LICENSE.txt", - "fonts/SOURCE-CODE-PRO-LICENSE.txt", - "fonts/fonts.css", - "fonts/open-sans-v17-all-charsets-300.woff2", - "fonts/open-sans-v17-all-charsets-300italic.woff2", - "fonts/open-sans-v17-all-charsets-600.woff2", - "fonts/open-sans-v17-all-charsets-600italic.woff2", - "fonts/open-sans-v17-all-charsets-700.woff2", - "fonts/open-sans-v17-all-charsets-700italic.woff2", - "fonts/open-sans-v17-all-charsets-800.woff2", - "fonts/open-sans-v17-all-charsets-800italic.woff2", - "fonts/open-sans-v17-all-charsets-italic.woff2", - "fonts/open-sans-v17-all-charsets-regular.woff2", - "fonts/source-code-pro-v11-all-charsets-500.woff2", - "highlight.css", - "highlight.js", - "index.hbs", - ]; - let theme_dir = temp.path().join("theme"); - let mut actual: Vec<_> = walkdir::WalkDir::new(&theme_dir) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| !e.file_type().is_dir()) - .map(|e| { - e.path() - .strip_prefix(&theme_dir) - .unwrap() - .to_str() - .unwrap() - .replace('\\', "/") - }) - .collect(); - actual.sort(); - assert_eq!(actual, expected); -} diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index b4524a58..e5989eb6 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -207,3 +207,47 @@ use-default-preprocessors = true ); assert!(test.dir.join("out").exists()); } + +// Copies the theme into the initialized directory. +#[test] +fn copy_theme() { + BookTest::empty() + .run("init --theme", |_| {}) + .check_file_list( + ".", + str![[r#" +book +book.toml +src +src/SUMMARY.md +src/chapter_1.md +theme +theme/book.js +theme/css +theme/css/chrome.css +theme/css/general.css +theme/css/print.css +theme/css/variables.css +theme/favicon.png +theme/favicon.svg +theme/fonts +theme/fonts/OPEN-SANS-LICENSE.txt +theme/fonts/SOURCE-CODE-PRO-LICENSE.txt +theme/fonts/fonts.css +theme/fonts/open-sans-v17-all-charsets-300.woff2 +theme/fonts/open-sans-v17-all-charsets-300italic.woff2 +theme/fonts/open-sans-v17-all-charsets-600.woff2 +theme/fonts/open-sans-v17-all-charsets-600italic.woff2 +theme/fonts/open-sans-v17-all-charsets-700.woff2 +theme/fonts/open-sans-v17-all-charsets-700italic.woff2 +theme/fonts/open-sans-v17-all-charsets-800.woff2 +theme/fonts/open-sans-v17-all-charsets-800italic.woff2 +theme/fonts/open-sans-v17-all-charsets-italic.woff2 +theme/fonts/open-sans-v17-all-charsets-regular.woff2 +theme/fonts/source-code-pro-v11-all-charsets-500.woff2 +theme/highlight.css +theme/highlight.js +theme/index.hbs +"#]], + ); +}