From 41bfbc69e6b36604e57347ec74da257d204c8e54 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 18:57:26 -0700 Subject: [PATCH] Migrate base_mdbook_init_can_skip_confirmation_prompts to BookTest --- tests/cli/init.rs | 20 -------------------- tests/testsuite/init.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/cli/init.rs b/tests/cli/init.rs index 51c2bfa3..2bdc6943 100644 --- a/tests/cli/init.rs +++ b/tests/cli/init.rs @@ -3,26 +3,6 @@ use crate::dummy_book::DummyBook; use mdbook::config::Config; -/// Run `mdbook init` with `--force` to skip the confirmation prompts -#[test] -fn base_mdbook_init_can_skip_confirmation_prompts() { - let temp = DummyBook::new().build().unwrap(); - - // doesn't exist before - assert!(!temp.path().join("book").exists()); - - let mut cmd = mdbook_cmd(); - cmd.args(["init", "--force"]).current_dir(temp.path()); - cmd.assert() - .success() - .stdout(predicates::str::contains("\nAll done, no errors...\n")); - - let config = Config::from_disk(temp.path().join("book.toml")).unwrap(); - assert_eq!(config.book.title, None); - - assert!(!temp.path().join(".gitignore").exists()); -} - /// Run `mdbook init` with `--title` without git config. /// /// Regression test for https://github.com/rust-lang/mdBook/issues/2485 diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index 9e185184..120a3037 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -71,3 +71,31 @@ src/chapter_1.md "#]], ); } + +// Run `mdbook init` with `--force` to skip the confirmation prompts +#[test] +fn init_force() { + let mut test = BookTest::empty(); + test.run("init --force", |cmd| { + cmd.expect_stdout(str![[r#" + +All done, no errors... + +"#]]) + .expect_stderr(str![[r#" +[TIMESTAMP] [INFO] (mdbook::book::init): Creating a new book with stub content + +"#]]); + }) + .check_file( + "book.toml", + str![[r#" +[book] +authors = [] +language = "en" +src = "src" + +"#]], + ); + assert!(!test.dir.join(".gitignore").exists()); +}