2017-07-10 10:17:19 +00:00
|
|
|
extern crate mdbook;
|
|
|
|
extern crate tempdir;
|
|
|
|
|
2017-09-30 14:11:47 +00:00
|
|
|
use std::path::PathBuf;
|
2017-11-18 15:21:59 +00:00
|
|
|
use std::fs;
|
2017-07-10 10:17:19 +00:00
|
|
|
use mdbook::MDBook;
|
2017-11-18 12:41:04 +00:00
|
|
|
use mdbook::config::Config;
|
2017-09-30 14:11:47 +00:00
|
|
|
use tempdir::TempDir;
|
2017-07-10 10:17:19 +00:00
|
|
|
|
|
|
|
|
2017-08-02 14:29:28 +00:00
|
|
|
/// Run `mdbook init` in an empty directory and make sure the default files
|
|
|
|
/// are created.
|
2017-07-10 10:17:19 +00:00
|
|
|
#[test]
|
2017-08-02 14:29:28 +00:00
|
|
|
fn base_mdbook_init_should_create_default_content() {
|
2017-07-10 10:17:19 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2017-11-18 14:07:08 +00:00
|
|
|
MDBook::init(temp.path()).build().unwrap();
|
2017-07-10 10:17:19 +00:00
|
|
|
|
|
|
|
for file in &created_files {
|
2017-09-30 14:11:47 +00:00
|
|
|
let target = temp.path().join(file);
|
|
|
|
println!("{}", target.display());
|
|
|
|
assert!(target.exists(), "{} doesn't exist", file);
|
2017-07-10 10:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-10 10:23:51 +00:00
|
|
|
|
2017-08-02 14:29:28 +00:00
|
|
|
/// Set some custom arguments for where to place the source and destination
|
|
|
|
/// files, then call `mdbook init`.
|
2017-07-10 10:23:51 +00:00
|
|
|
#[test]
|
2017-08-02 14:29:28 +00:00
|
|
|
fn run_mdbook_init_with_custom_book_and_src_locations() {
|
2017-07-10 10:23:51 +00: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 {
|
2017-11-18 12:41:04 +00:00
|
|
|
assert!(
|
|
|
|
!temp.path().join(file).exists(),
|
|
|
|
"{} shouldn't exist yet!",
|
|
|
|
file
|
|
|
|
);
|
2017-07-10 10:23:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 12:41:04 +00:00
|
|
|
let mut cfg = Config::default();
|
|
|
|
cfg.book.src = PathBuf::from("in");
|
|
|
|
cfg.build.build_dir = PathBuf::from("out");
|
2017-07-10 10:23:51 +00:00
|
|
|
|
2017-11-18 14:16:35 +00:00
|
|
|
MDBook::init(temp.path()).with_config(cfg).build().unwrap();
|
2017-07-10 10:23:51 +00:00
|
|
|
|
|
|
|
for file in &created_files {
|
2017-09-30 14:11:47 +00:00
|
|
|
let target = temp.path().join(file);
|
2017-11-18 12:41:04 +00:00
|
|
|
assert!(
|
|
|
|
target.exists(),
|
|
|
|
"{} should have been created by `mdbook init`",
|
|
|
|
file
|
|
|
|
);
|
2017-07-10 10:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-09 09:46:39 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn book_toml_isnt_required() {
|
|
|
|
let temp = TempDir::new("mdbook").unwrap();
|
2017-12-10 12:13:46 +00:00
|
|
|
let mut md = MDBook::init(temp.path()).build().unwrap();
|
2017-12-09 09:46:39 +00:00
|
|
|
|
2017-11-18 15:21:59 +00:00
|
|
|
let _ = fs::remove_file(temp.path().join("book.toml"));
|
2017-12-09 09:46:39 +00:00
|
|
|
|
2017-12-10 12:13:46 +00:00
|
|
|
md.build().unwrap();
|
2017-12-09 09:46:39 +00:00
|
|
|
}
|