Migrate mdbook_test_chapter to BookTest

This commit is contained in:
Eric Huss 2025-04-22 10:58:27 -07:00
parent 5a84d641cd
commit f324aebdec
2 changed files with 21 additions and 13 deletions

View file

@ -4,19 +4,6 @@ use crate::dummy_book::DummyBook;
use mdbook::MDBook;
#[test]
fn mdbook_test_chapter() {
let temp = DummyBook::new().with_passing_test(true).build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
let result = md.test_chapter(vec![], Some("Introduction"));
assert!(
result.is_ok(),
"test_chapter failed with {}",
result.err().unwrap()
);
}
#[test]
fn mdbook_test_chapter_not_found() {
let temp = DummyBook::new().with_passing_test(true).build().unwrap();

View file

@ -53,3 +53,24 @@ failing!
"#]]);
});
}
// Test with a specific chapter.
#[test]
fn test_individual_chapter() {
let mut test = BookTest::from_dir("test/passing_tests");
test.run("test -c", |cmd| {
cmd.args(&["Passing 1"])
.expect_stdout(str![[""]])
.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Testing chapter 'Passing 1': "passing1.md"
"#]]);
})
// Can also be a source path.
.run("test -c passing2.md", |cmd| {
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Testing chapter 'Passing 2': "passing2.md"
"#]]);
});
}