summaryrefslogtreecommitdiffstats
path: root/vendor/mdbook/src/cmd/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/mdbook/src/cmd/test.rs')
-rw-r--r--vendor/mdbook/src/cmd/test.rs66
1 files changed, 35 insertions, 31 deletions
diff --git a/vendor/mdbook/src/cmd/test.rs b/vendor/mdbook/src/cmd/test.rs
index 02f982a49..3efe130b1 100644
--- a/vendor/mdbook/src/cmd/test.rs
+++ b/vendor/mdbook/src/cmd/test.rs
@@ -1,54 +1,58 @@
+use super::command_prelude::*;
use crate::get_book_dir;
-use clap::{arg, App, Arg, ArgMatches};
+use clap::builder::NonEmptyStringValueParser;
+use clap::{Arg, ArgAction, ArgMatches, Command};
use mdbook::errors::Result;
use mdbook::MDBook;
+use std::path::PathBuf;
// Create clap subcommand arguments
-pub fn make_subcommand<'help>() -> App<'help> {
- App::new("test")
+pub fn make_subcommand() -> Command {
+ Command::new("test")
.about("Tests that a book's Rust code samples compile")
+ // FIXME: --dest-dir is unused by the test command, it should be removed
+ .arg_dest_dir()
+ .arg_root_dir()
.arg(
- Arg::new("dest-dir")
- .short('d')
- .long("dest-dir")
- .value_name("dest-dir")
+ Arg::new("chapter")
+ .short('c')
+ .long("chapter")
+ .value_name("chapter"),
+ )
+ .arg(
+ Arg::new("library-path")
+ .short('L')
+ .long("library-path")
+ .value_name("dir")
+ .value_delimiter(',')
+ .value_parser(NonEmptyStringValueParser::new())
+ .action(ArgAction::Append)
.help(
- "Output directory for the book{n}\
- Relative paths are interpreted relative to the book's root directory.{n}\
- If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
+ "A comma-separated list of directories to add to the crate \
+ search path when building tests",
),
)
- .arg(arg!([dir]
- "Root directory for the book{n}\
- (Defaults to the Current Directory when omitted)"
- ))
- .arg(Arg::new("library-path")
- .short('L')
- .long("library-path")
- .value_name("dir")
- .takes_value(true)
- .use_delimiter(true)
- .require_delimiter(true)
- .multiple_values(true)
- .multiple_occurrences(true)
- .forbid_empty_values(true)
- .help("A comma-separated list of directories to add to {n}the crate search path when building tests"))
}
// test command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {
let library_paths: Vec<&str> = args
- .values_of("library-path")
- .map(std::iter::Iterator::collect)
+ .get_many("library-path")
+ .map(|it| it.map(String::as_str).collect())
.unwrap_or_default();
+
+ let chapter: Option<&str> = args.get_one::<String>("chapter").map(|s| s.as_str());
+
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;
- if let Some(dest_dir) = args.value_of("dest-dir") {
- book.config.build.build_dir = dest_dir.into();
+ if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
+ book.config.build.build_dir = dest_dir.to_path_buf();
}
-
- book.test(library_paths)?;
+ match chapter {
+ Some(_) => book.test_chapter(library_paths, chapter),
+ None => book.test(library_paths),
+ }?;
Ok(())
}