Merge pull request #340 from messense/feature/mdbook-test-library-path

Add library path argument for `mdbook test`
This commit is contained in:
Mathieu David 2017-07-08 23:27:28 +02:00 committed by GitHub
commit 55e7e82e5c
2 changed files with 11 additions and 4 deletions

View File

@ -5,15 +5,18 @@ use get_book_dir;
// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("test").about("Test that code samples compile")
SubCommand::with_name("test")
.about("Test that code samples compile")
.arg_from_usage("-L, --library-path [DIR]... 'directory to add to crate search path'")
}
// test command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let library_paths: Vec<&str> = args.values_of("library-path").map(|v| v.collect()).unwrap_or_default();
let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir).read_config()?;
book.test()?;
book.test(library_paths)?;
Ok(())
}

View File

@ -351,9 +351,13 @@ impl MDBook {
self
}
pub fn test(&mut self) -> Result<()> {
pub fn test(&mut self, library_paths: Vec<&str>) -> Result<()> {
// read in the chapters
self.parse_summary().chain_err(|| "Couldn't parse summary")?;
let library_args: Vec<&str> = (0..library_paths.len()).map(|_| "-L")
.zip(library_paths.into_iter())
.flat_map(|x| vec![x.0, x.1])
.collect();
for item in self.iter() {
if let BookItem::Chapter(_, ref ch) = *item {
@ -363,7 +367,7 @@ impl MDBook {
println!("[*]: Testing file: {:?}", path);
let output = Command::new("rustdoc").arg(&path).arg("--test").output()?;
let output = Command::new("rustdoc").arg(&path).arg("--test").args(&library_args).output()?;
if !output.status.success() {
bail!(ErrorKind::Subprocess("Rustdoc returned an error".to_string(), output));