Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
8 changes: 6 additions & 2 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
Expand Down