diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 467a4d4a..4f4ccd9a 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -3,17 +3,16 @@ mod dummy_book; use crate::dummy_book::{assert_contains_strings, DummyBook}; use anyhow::Context; -use mdbook::book::Chapter; use mdbook::config::Config; use mdbook::errors::*; use mdbook::utils::fs::write_file; -use mdbook::{BookItem, MDBook}; +use mdbook::MDBook; use pretty_assertions::assert_eq; use select::document::Document; use select::predicate::{Attr, Class, Name, Predicate}; use std::ffi::OsStr; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::str::FromStr; use tempfile::Builder as TempFileBuilder; use walkdir::{DirEntry, WalkDir}; @@ -508,21 +507,3 @@ fn custom_fonts() { &["fonts.css", "myfont.woff"] ); } - -#[test] -fn with_no_source_path() { - // Test for a regression where search would fail if source_path is None. - let temp = DummyBook::new().build().unwrap(); - let mut md = MDBook::load(temp.path()).unwrap(); - let chapter = Chapter { - name: "Sample chapter".to_string(), - content: "".to_string(), - number: None, - sub_items: Vec::new(), - path: Some(PathBuf::from("sample.html")), - source_path: None, - parent_names: Vec::new(), - }; - md.book.sections.push(BookItem::Chapter(chapter)); - md.build().unwrap(); -} diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 4e19f134..b7e31212 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -1,8 +1,10 @@ //! Tests for search support. use crate::prelude::*; +use mdbook::book::Chapter; +use mdbook::BookItem; use snapbox::file; -use std::path::Path; +use std::path::{Path, PathBuf}; fn read_book_index(root: &Path) -> serde_json::Value { let index = root.join("book/searchindex.js"); @@ -104,3 +106,22 @@ fn can_disable_individual_chapters() { assert!(!contains("first/disable_me.html")); assert!(contains("first/keep_me.html")); } + +// Test for a regression where search would fail if source_path is None. +// https://github.com/rust-lang/mdBook/pull/2550 +#[test] +fn with_no_source_path() { + let test = BookTest::from_dir("search/reasonable_search_index"); + let mut book = test.load_book(); + let chapter = Chapter { + name: "Sample chapter".to_string(), + content: "".to_string(), + number: None, + sub_items: Vec::new(), + path: Some(PathBuf::from("sample.html")), + source_path: None, + parent_names: Vec::new(), + }; + book.book.sections.push(BookItem::Chapter(chapter)); + book.build().unwrap(); +}