Skip to content

Commit 7bdea7c

Browse files
committed
Don't rebuild preprocessor map during test
This fixes a problem where custom preprocessors were not being registered when running tests. This was caused by the test function rebuilding the preprocessor map. This removes the code that was rebuilding the preprocessors and removing the IndexPreprocessor when running tests. Skipping IndexPreprocessor was added back in #741 to fix #724 which was caused by #685 which added the IndexPreprocessor. Additionally, #1986 added running *all* preprocessors. The IndexPreprocessor was removed because in the past the code was testing against the source directly, and the path from `chapter.path` is the converted `index.md` file, and that filename does not exist in the source. This isn't a problem anymore because due to #891 it is not reading from the `src` directory. Note that this results in a minor change where the chapter path changes from `README.md` to `index.md` in the output and the `--chapter` option. I think I'm ok with that change, though it would be easy to switch it back if that's an issue.
1 parent 2bcae6b commit 7bdea7c

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

crates/mdbook-driver/src/mdbook.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ impl MDBook {
263263
}
264264
}
265265

266-
// Index Preprocessor is disabled so that chapter paths
267-
// continue to point to the actual markdown files.
268-
self.preprocessors = determine_preprocessors(&self.config, &self.root)?;
269-
self.preprocessors
270-
.shift_remove_entry(IndexPreprocessor::NAME);
271266
let (book, _) = self.preprocess_book(&TestRenderer)?;
272267

273268
let color_output = std::io::stderr().is_terminal();

tests/testsuite/preprocessor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn test_with_custom_preprocessor() {
5454
book.test(vec![]).unwrap();
5555

5656
let inner = spy.lock().unwrap();
57-
assert_eq!(inner.run_count, 0);
58-
assert_eq!(inner.rendered_with, Vec::<String>::new());
57+
assert_eq!(inner.run_count, 1);
58+
assert_eq!(inner.rendered_with, ["test"]);
5959
}
6060

6161
// No-op preprocessor works.

0 commit comments

Comments
 (0)