Skip to content

Commit b4e15e5

Browse files
authored
Merge pull request #741 from mattico/fix-mdbook-test
Fix `mdbook test`
2 parents 35c2d1f + 1d1d4d7 commit b4e15e5

File tree

10 files changed

+600
-166
lines changed

10 files changed

+600
-166
lines changed

src/book/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@ impl MDBook {
213213
.flat_map(|x| vec![x.0, x.1])
214214
.collect();
215215

216-
let temp_dir = TempFileBuilder::new().prefix("mdbook").tempdir()?;
216+
let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir()?;
217217

218218
let preprocess_context = PreprocessorContext::new(self.root.clone(), self.config.clone());
219219

220220
LinkPreprocessor::new().run(&preprocess_context, &mut self.book)?;
221-
IndexPreprocessor::new().run(&preprocess_context, &mut self.book)?;
221+
// Index Preprocessor is disabled so that chapter paths continue to point to the
222+
// actual markdown files.
222223

223224
for item in self.iter() {
224225
if let BookItem::Chapter(ref ch) = *item {

src/cmd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Subcommand modules for the `mdbook` binary.
1+
//! Subcommand modules for the `mdbook` binary.
22
33
pub mod build;
44
pub mod clean;

src/cmd/serve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ extern crate ws;
55
use self::iron::{
66
status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set,
77
};
8+
#[cfg(feature = "watch")]
9+
use super::watch;
810
use clap::{App, ArgMatches, SubCommand};
911
use mdbook::errors::*;
1012
use mdbook::utils;
1113
use mdbook::MDBook;
1214
use std;
13-
#[cfg(feature = "watch")]
14-
use super::watch;
1515
use {get_book_dir, open};
1616

1717
struct ErrorRecover;

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ impl Renderer for HtmlHandlebars {
370370
.chain_err(|| "Unable to copy across additional CSS and JS")?;
371371

372372
// Render search index
373-
#[cfg(feature = "search")] {
373+
#[cfg(feature = "search")]
374+
{
374375
let search = html_config.search.unwrap_or_default();
375376
if search.enable {
376377
super::search::create_files(&search, &destination, &book)?;

tests/dummy_book/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl DummyBook {
4747
/// Write a book to a temporary directory using the provided settings.
4848
pub fn build(&self) -> Result<TempDir> {
4949
let temp = TempFileBuilder::new()
50-
.prefix("dummy_book")
50+
.prefix("dummy_book-")
5151
.tempdir()
5252
.chain_err(|| "Unable to create temp directory")?;
5353

tests/dummy_book/src/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dummy Book
2+
3+
This file is just here to cause the index preprocessor to run.
4+
5+
Does a pretty good job, too.

tests/dummy_book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Summary
22

3+
[Dummy Book](README.md)
34
[Introduction](intro.md)
45

56
- [First Chapter](first/index.md)

tests/rendered_output.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const TOC_TOP_LEVEL: &[&'static str] = &[
2727
"1. First Chapter",
2828
"2. Second Chapter",
2929
"Conclusion",
30+
"Dummy Book",
3031
"Introduction",
3132
];
3233
const TOC_SECOND_LEVEL: &[&'static str] =
@@ -126,7 +127,8 @@ fn rendered_code_has_playpen_stuff() {
126127
#[test]
127128
fn chapter_content_appears_in_rendered_document() {
128129
let content = vec![
129-
("index.html", "Here's some interesting text"),
130+
("index.html", "This file is just here to cause the"),
131+
("intro.html", "Here's some interesting text"),
130132
("second.html", "Second Chapter"),
131133
("first/nested.html", "testable code"),
132134
("first/index.html", "more text"),
@@ -437,7 +439,7 @@ mod search {
437439
assert_eq!(docs[&some_section]["body"], "");
438440
assert_eq!(
439441
docs[&summary]["body"],
440-
"Introduction First Chapter Nested Chapter Includes Recursive Second Chapter Conclusion"
442+
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Second Chapter Conclusion"
441443
);
442444
assert_eq!(docs[&summary]["breadcrumbs"], "First Chapter » Summary");
443445
assert_eq!(docs[&conclusion]["body"], "I put &lt;HTML&gt; in here!");

0 commit comments

Comments
 (0)