Migrate book_with_a_reserved_filename_does_not_build to BookTest

This commit is contained in:
Eric Huss 2025-04-21 18:34:40 -07:00
parent adcea9b3b9
commit 3706ddc5cc
5 changed files with 20 additions and 18 deletions

View file

@ -405,24 +405,6 @@ fn example_book_can_build() {
md.build().unwrap();
}
#[test]
fn book_with_a_reserved_filename_does_not_build() {
let tmp_dir = TempFileBuilder::new().prefix("mdBook").tempdir().unwrap();
let src_path = tmp_dir.path().join("src");
fs::create_dir(&src_path).unwrap();
let summary_path = src_path.join("SUMMARY.md");
let print_path = src_path.join("print.md");
fs::File::create(print_path).unwrap();
let mut summary_file = fs::File::create(summary_path).unwrap();
writeln!(summary_file, "[print](print.md)").unwrap();
let md = MDBook::load(tmp_dir.path()).unwrap();
let got = md.build();
assert!(got.is_err());
}
#[test]
fn by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index() {
let temp = DummyBook::new().build().unwrap();

View file

@ -39,3 +39,17 @@ fn create_missing() {
test.load_book();
assert!(test.dir.join("src/chapter_1.md").exists());
}
// Checks that it fails if the summary has a reserved filename.
#[test]
fn no_reserved_filename() {
BookTest::from_dir("build/no_reserved_filename").run("build", |cmd| {
cmd.expect_failure().expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [ERROR] (mdbook::utils): Error: Rendering failed
[TIMESTAMP] [ERROR] (mdbook::utils): [TAB]Caused By: print.md is reserved for internal use
"#]]);
});
}

View file

@ -0,0 +1,2 @@
[book]
title = "no_reserved_filename"

View file

@ -0,0 +1,3 @@
# Summary
- [Print](print.md)

View file

@ -0,0 +1 @@
# Print