Migrate no_git_config_with_title to BookTest

This commit is contained in:
Eric Huss 2025-04-21 18:59:25 -07:00
parent 41bfbc69e6
commit 3e1d750efa
3 changed files with 34 additions and 28 deletions

View file

@ -1,27 +0,0 @@
use crate::cli::cmd::mdbook_cmd;
use crate::dummy_book::DummyBook;
use mdbook::config::Config;
/// Run `mdbook init` with `--title` without git config.
///
/// Regression test for https://github.com/rust-lang/mdBook/issues/2485
#[test]
fn no_git_config_with_title() {
let temp = DummyBook::new().build().unwrap();
// doesn't exist before
assert!(!temp.path().join("book").exists());
let mut cmd = mdbook_cmd();
cmd.args(["init", "--title", "Example title"])
.current_dir(temp.path())
.env("GIT_CONFIG_GLOBAL", "")
.env("GIT_CONFIG_NOSYSTEM", "1");
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.as_deref(), Some("Example title"));
}

View file

@ -1,4 +1,3 @@
mod build;
mod cmd;
mod init;
mod test;

View file

@ -99,3 +99,37 @@ src = "src"
);
assert!(!test.dir.join(".gitignore").exists());
}
// Run `mdbook init` with `--title` without git config.
//
// Regression test for https://github.com/rust-lang/mdBook/issues/2485
#[test]
fn no_git_config_with_title() {
let mut test = BookTest::empty();
test.run("init", |cmd| {
cmd.expect_stdout(str![[r#"
Do you want a .gitignore to be created? (y/n)
All done, no errors...
"#]])
.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book::init): Creating a new book with stub content
"#]])
.args(&["--title", "Example title"]);
})
.check_file(
"book.toml",
str![[r#"
[book]
authors = []
language = "en"
src = "src"
title = "Example title"
"#]],
);
assert!(!test.dir.join(".gitignore").exists());
}