Migrate failure_on_missing_file to BookTest

This commit is contained in:
Eric Huss 2025-04-21 18:32:40 -07:00
parent b9e433710d
commit ba8107120c
4 changed files with 21 additions and 14 deletions

View file

@ -348,20 +348,6 @@ fn check_link_target_fallback() {
);
}
/// Ensure building fails if `create-missing` is false and one of the files does
/// not exist.
#[test]
fn failure_on_missing_file() {
let temp = DummyBook::new().build().unwrap();
fs::remove_file(temp.path().join("src").join("intro.md")).unwrap();
let mut cfg = Config::default();
cfg.build.create_missing = false;
let got = MDBook::load_with_config(temp.path(), cfg);
assert!(got.is_err());
}
/// Ensure a missing file is created if `create-missing` is true.
#[test]
fn create_missing_file_with_config() {

View file

@ -16,3 +16,16 @@ fn basic_build() {
"#]]);
});
}
// Ensure building fails if `create-missing` is false and one of the files does
// not exist.
#[test]
fn failure_on_missing_file() {
BookTest::from_dir("build/missing_file").run("build", |cmd| {
cmd.expect_failure().expect_stderr(str![[r#"
[TIMESTAMP] [ERROR] (mdbook::utils): Error: Chapter file not found, ./chapter_1.md
[TIMESTAMP] [ERROR] (mdbook::utils): [TAB]Caused By: [NOT_FOUND]
"#]]);
});
}

View file

@ -0,0 +1,5 @@
[book]
title = "missing_file"
[build]
create-missing = false

View file

@ -0,0 +1,3 @@
# Summary
- [Chapter 1](./chapter_1.md)