Migrate run_mdbook_init_should_create_content_from_summary to BookTest
This commit is contained in:
parent
3e1d750efa
commit
4019060ef4
3 changed files with 37 additions and 30 deletions
|
|
@ -7,36 +7,6 @@ use std::io::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tempfile::Builder as TempFileBuilder;
|
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
|
/// Set some custom arguments for where to place the source and destination
|
||||||
/// files, then call `mdbook init`.
|
/// files, then call `mdbook init`.
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -133,3 +133,32 @@ title = "Example title"
|
||||||
);
|
);
|
||||||
assert!(!test.dir.join(".gitignore").exists());
|
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
|
||||||
|
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
8
tests/testsuite/init/init_from_summary/src/SUMMARY.md
Normal file
8
tests/testsuite/init/init_from_summary/src/SUMMARY.md
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
[intro](intro.md)
|
||||||
|
|
||||||
|
- [First chapter](first.md)
|
||||||
|
|
||||||
|
[outro](outro.md)
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue