mdBook/tests/init.rs

65 lines
1.8 KiB
Rust
Raw Permalink Normal View History

extern crate mdbook;
extern crate tempdir;
2017-09-30 22:11:47 +08:00
use std::path::PathBuf;
use mdbook::MDBook;
2017-09-30 22:11:47 +08:00
use tempdir::TempDir;
/// Run `mdbook init` in an empty directory and make sure the default files
/// are created.
#[test]
fn base_mdbook_init_should_create_default_content() {
let created_files = vec!["book", "src", "src/SUMMARY.md", "src/chapter_1.md"];
let temp = TempDir::new("mdbook").unwrap();
for file in &created_files {
assert!(!temp.path().join(file).exists());
}
let mut md = MDBook::new(temp.path());
md.init().unwrap();
for file in &created_files {
2017-09-30 22:11:47 +08:00
let target = temp.path().join(file);
println!("{}", target.display());
assert!(target.exists(), "{} doesn't exist", file);
}
}
2017-07-10 18:23:51 +08:00
/// Set some custom arguments for where to place the source and destination
/// files, then call `mdbook init`.
2017-07-10 18:23:51 +08:00
#[test]
fn run_mdbook_init_with_custom_book_and_src_locations() {
2017-07-10 18:23:51 +08:00
let created_files = vec!["out", "in", "in/SUMMARY.md", "in/chapter_1.md"];
let temp = TempDir::new("mdbook").unwrap();
for file in &created_files {
assert!(!temp.path().join(file).exists(),
"{} shouldn't exist yet!",
file);
2017-07-10 18:23:51 +08:00
}
2017-09-30 22:11:47 +08:00
let mut md = MDBook::new(temp.path());
md.config.book.src = PathBuf::from("in");
md.config.build.build_dir = PathBuf::from("out");
2017-07-10 18:23:51 +08:00
md.init().unwrap();
for file in &created_files {
2017-09-30 22:11:47 +08:00
let target = temp.path().join(file);
assert!(target.exists(), "{} should have been created by `mdbook init`", file);
2017-07-10 18:23:51 +08:00
}
}
#[test]
fn book_toml_isnt_required() {
let temp = TempDir::new("mdbook").unwrap();
let mut md = MDBook::new(temp.path());
md.init().unwrap();
assert!(!temp.path().join("book.toml").exists());
md.read_config().unwrap().build().unwrap();
}