From adcea9b3b9a1acc78e8ebab3c891047edb7d314d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 18:33:35 -0700 Subject: [PATCH] Migrate create_missing_file_with_config to BookTest --- tests/rendered_output.rs | 14 -------------- tests/testsuite/build.rs | 10 ++++++++++ tests/testsuite/build/create_missing/book.toml | 2 ++ .../testsuite/build/create_missing/src/SUMMARY.md | 3 +++ 4 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 tests/testsuite/build/create_missing/book.toml create mode 100644 tests/testsuite/build/create_missing/src/SUMMARY.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index ec5b1ecf..49f2c6f4 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -348,20 +348,6 @@ fn check_link_target_fallback() { ); } -/// Ensure a missing file is created if `create-missing` is true. -#[test] -fn create_missing_file_with_config() { - let temp = DummyBook::new().build().unwrap(); - fs::remove_file(temp.path().join("src").join("intro.md")).unwrap(); - - let mut cfg = Config::default(); - cfg.build.create_missing = true; - - assert!(!temp.path().join("src").join("intro.md").exists()); - let _md = MDBook::load_with_config(temp.path(), cfg).unwrap(); - assert!(temp.path().join("src").join("intro.md").exists()); -} - /// This makes sure you can include a Rust file with `{{#playground example.rs}}`. /// Specification is in `guide/src/format/rust.md` #[test] diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 9c5d9d65..34532d62 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -29,3 +29,13 @@ fn failure_on_missing_file() { "#]]); }); } + +// Ensure a missing file is created if `create-missing` is true. +#[test] +fn create_missing() { + let test = BookTest::from_dir("build/create_missing"); + assert!(test.dir.join("src/SUMMARY.md").exists()); + assert!(!test.dir.join("src/chapter_1.md").exists()); + test.load_book(); + assert!(test.dir.join("src/chapter_1.md").exists()); +} diff --git a/tests/testsuite/build/create_missing/book.toml b/tests/testsuite/build/create_missing/book.toml new file mode 100644 index 00000000..d347afe8 --- /dev/null +++ b/tests/testsuite/build/create_missing/book.toml @@ -0,0 +1,2 @@ +[book] +title = "create_missing" diff --git a/tests/testsuite/build/create_missing/src/SUMMARY.md b/tests/testsuite/build/create_missing/src/SUMMARY.md new file mode 100644 index 00000000..7390c828 --- /dev/null +++ b/tests/testsuite/build/create_missing/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Chapter 1](./chapter_1.md)