Skip to content

Commit 6424815

Browse files
committed
use empty folder; check more details in result #1568
1 parent a3c0ecd commit 6424815

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tests/cli/init.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use std::fs::read_to_string;
2+
use std::path::PathBuf;
3+
14
use crate::cli::cmd::mdbook_cmd;
25
use crate::dummy_book::DummyBook;
36

@@ -6,21 +9,32 @@ use mdbook::config::Config;
69
/// Run `mdbook init` with `--force` to skip the confirmation prompts
710
#[test]
811
fn base_mdbook_init_can_skip_confirmation_prompts() {
9-
let temp = DummyBook::new().build().unwrap();
12+
let temp = DummyBook::new().empty().unwrap();
1013

11-
// doesn't exist before
12-
assert!(!temp.path().join("book").exists());
14+
// empty folder
15+
assert_eq!(temp.path().read_dir().unwrap().count(), 0);
1316

1417
let mut cmd = mdbook_cmd();
1518
cmd.args(["init", "--force"]).current_dir(temp.path());
1619
cmd.assert()
1720
.success()
18-
.stdout(predicates::str::contains("\nAll done, no errors...\n"));
21+
.stdout(predicates::str::contains("\nAll done, no errors...\n"))
22+
.stderr(predicates::str::contains(
23+
"Creating a new book with stub content",
24+
));
1925

2026
let config = Config::from_disk(temp.path().join("book.toml")).unwrap();
2127
assert_eq!(config.book.title, None);
28+
assert_eq!(config.book.language, Some(String::from("en")));
29+
assert_eq!(config.book.multilingual, false);
30+
assert_eq!(config.book.src, PathBuf::from("src"));
2231

2332
assert!(!temp.path().join(".gitignore").exists());
33+
let summary = read_to_string(temp.path().join("src").join("SUMMARY.md")).unwrap();
34+
assert_eq!(summary, "# Summary\n\n- [Chapter 1](./chapter_1.md)\n");
35+
let chapter_1 = read_to_string(temp.path().join("src").join("chapter_1.md")).unwrap();
36+
assert_eq!(chapter_1, "# Chapter 1\n");
37+
assert!(temp.path().join("book").exists());
2438
}
2539

2640
/// Run `mdbook init` with `--title` without git config.

tests/dummy_book/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ impl DummyBook {
3838
self
3939
}
4040

41-
/// Write a book to a temporary directory using the provided settings.
42-
pub fn build(&self) -> Result<TempDir> {
43-
let temp = TempFileBuilder::new()
41+
pub fn empty(&self) -> Result<TempDir> {
42+
TempFileBuilder::new()
4443
.prefix("dummy_book-")
4544
.tempdir()
46-
.with_context(|| "Unable to create temp directory")?;
45+
.with_context(|| "Unable to create temp directory")
46+
}
47+
48+
/// Write a book to a temporary directory using the provided settings.
49+
pub fn build(&self) -> Result<TempDir> {
50+
let temp = self.empty()?;
4751

4852
let dummy_book_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/dummy_book");
4953
recursive_copy(&dummy_book_root, temp.path()).with_context(|| {

0 commit comments

Comments
 (0)