-
Couldn't load subscription status.
- Fork 1.8k
add a --chapter option to mdbook test. #1741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
f0189cd
4d78119
bf6d452
71e490d
6e3d275
99a8c0d
f1c07b0
ed0ee85
96245d2
7c55869
0926c52
05ed667
601b6df
20cca38
5ec488c
9172005
c1004f7
e979012
d383ae0
4ead38f
1747094
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,6 +246,11 @@ impl MDBook { | |
|
|
||
| /// Run `rustdoc` tests on the book, linking against the provided libraries. | ||
| pub fn test(&mut self, library_paths: Vec<&str>) -> Result<()> { | ||
| self.test_chapter(library_paths, None) | ||
| } | ||
|
|
||
| /// Run `rustdoc` tests on a specific chapter of the book, linking against the provided libraries. | ||
| pub fn test_chapter(&mut self, library_paths: Vec<&str>, chapter: Option<&str>) -> Result<()> { | ||
| let library_args: Vec<&str> = (0..library_paths.len()) | ||
| .map(|_| "-L") | ||
| .zip(library_paths.into_iter()) | ||
|
|
@@ -254,6 +259,13 @@ impl MDBook { | |
|
|
||
| let temp_dir = TempFileBuilder::new().prefix("mdbook-").tempdir()?; | ||
|
|
||
| let chapter_name: &str = match chapter { | ||
| Some(p) => p, | ||
| None => "", | ||
| }; | ||
|
|
||
| let mut chapter_found = false; | ||
|
|
||
| // FIXME: Is "test" the proper renderer name to use here? | ||
| let preprocess_context = | ||
| PreprocessorContext::new(self.root.clone(), self.config.clone(), "test".to_string()); | ||
|
|
@@ -270,8 +282,18 @@ impl MDBook { | |
| _ => continue, | ||
| }; | ||
|
|
||
| let path = self.source_dir().join(&chapter_path); | ||
| info!("Testing file: {:?}", path); | ||
| let cp = match chapter_path.to_str() { | ||
| Some(s) => s, | ||
| None => "", | ||
| }; | ||
|
|
||
| if chapter_name != "" && ch.name != chapter_name && cp != chapter_name { | ||
| info!("Skipping chapter '{}'...", ch.name); | ||
clovett marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| continue; | ||
| }; | ||
|
|
||
| chapter_found = true; | ||
| info!("Testing chapter '{}': {:?}", ch.name, chapter_path); | ||
|
|
||
| // write preprocessed file to tempdir | ||
| let path = temp_dir.path().join(&chapter_path); | ||
|
|
@@ -311,6 +333,9 @@ impl MDBook { | |
| if failed { | ||
| bail!("One or more tests failed"); | ||
| } | ||
| if chapter_name != "" && !chapter_found { | ||
| bail!(format!("Chapter not found: {}", chapter_name)); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,11 +67,11 @@ | |
| var theme = localStorage.getItem('mdbook-theme'); | ||
| var sidebar = localStorage.getItem('mdbook-sidebar'); | ||
|
|
||
| if (theme.startsWith('"') && theme.endsWith('"')) { | ||
| if (theme && theme.startsWith('"') && theme.endsWith('"')) { | ||
| localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1)); | ||
| } | ||
|
|
||
| if (sidebar.startsWith('"') && sidebar.endsWith('"')) { | ||
| if (sidebar && sidebar.startsWith('"') && sidebar.endsWith('"')) { | ||
|
||
| localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1)); | ||
| } | ||
| } catch (e) { } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little unclear to me on what happens if
chapteris None. Can it include a little more explanation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, I added clarifying comments
// test_chapter with chapter:None will run all tests.and on thetest_chapterfunction itself the doc comment:/// IfchapterisNone, all tests will be run.