diff --git a/tests/init.rs b/tests/init.rs index 4b6ee5fa..7cc93211 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -7,36 +7,6 @@ use std::io::prelude::*; use std::path::PathBuf; use tempfile::Builder as TempFileBuilder; -/// Run `mdbook init` in a directory containing a SUMMARY.md should create the -/// files listed in the summary. -#[test] -fn run_mdbook_init_should_create_content_from_summary() { - let created_files = vec!["intro.md", "first.md", "outro.md"]; - - let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap(); - let src_dir = temp.path().join("src"); - fs::create_dir_all(src_dir.clone()).unwrap(); - static SUMMARY: &str = r#"# Summary - -[intro](intro.md) - -- [First chapter](first.md) - -[outro](outro.md) - -"#; - - let mut summary = File::create(src_dir.join("SUMMARY.md")).unwrap(); - summary.write_all(SUMMARY.as_bytes()).unwrap(); - MDBook::init(temp.path()).build().unwrap(); - - for file in &created_files { - let target = src_dir.join(file); - println!("{}", target.display()); - assert!(target.exists(), "{file} doesn't exist"); - } -} - /// Set some custom arguments for where to place the source and destination /// files, then call `mdbook init`. #[test] diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index b3a79022..9f66719b 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -133,3 +133,32 @@ title = "Example title" ); assert!(!test.dir.join(".gitignore").exists()); } + +// Run `mdbook init` in a directory containing a SUMMARY.md should create the +// files listed in the summary. +#[test] +fn init_from_summary() { + BookTest::from_dir("init/init_from_summary") + .run("init", |_| {}) + .check_file( + "src/intro.md", + str![[r#" +# intro + +"#]], + ) + .check_file( + "src/first.md", + str![[r#" +# First chapter + +"#]], + ) + .check_file( + "src/outro.md", + str![[r#" +# outro + +"#]], + ); +} diff --git a/tests/testsuite/init/init_from_summary/src/SUMMARY.md b/tests/testsuite/init/init_from_summary/src/SUMMARY.md new file mode 100644 index 00000000..93d7b15b --- /dev/null +++ b/tests/testsuite/init/init_from_summary/src/SUMMARY.md @@ -0,0 +1,8 @@ +# Summary + +[intro](intro.md) + +- [First chapter](first.md) + +[outro](outro.md) +