Skip to content

Commit 53c3a92

Browse files
committed
Add test for a chapter with no source path
1 parent 132ca0d commit 53c3a92

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/rendered_output.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ mod dummy_book;
33
use crate::dummy_book::{assert_contains_strings, assert_doesnt_contain_strings, DummyBook};
44

55
use anyhow::Context;
6+
use mdbook::book::Chapter;
67
use mdbook::config::Config;
78
use mdbook::errors::*;
89
use mdbook::utils::fs::write_file;
9-
use mdbook::MDBook;
10+
use mdbook::{BookItem, MDBook};
1011
use pretty_assertions::assert_eq;
1112
use select::document::Document;
1213
use select::predicate::{Attr, Class, Name, Predicate};
@@ -1031,3 +1032,22 @@ fn custom_header_attributes() {
10311032
];
10321033
assert_contains_strings(&contents, summary_strings);
10331034
}
1035+
1036+
#[test]
1037+
#[should_panic]
1038+
fn with_no_source_path() {
1039+
// Test for a regression where search would fail if source_path is None.
1040+
let temp = DummyBook::new().build().unwrap();
1041+
let mut md = MDBook::load(temp.path()).unwrap();
1042+
let chapter = Chapter {
1043+
name: "Sample chapter".to_string(),
1044+
content: "".to_string(),
1045+
number: None,
1046+
sub_items: Vec::new(),
1047+
path: Some(PathBuf::from("sample.html")),
1048+
source_path: None,
1049+
parent_names: Vec::new(),
1050+
};
1051+
md.book.sections.push(BookItem::Chapter(chapter));
1052+
md.build().unwrap();
1053+
}

0 commit comments

Comments
 (0)