diff --git a/src/app/mod.rs b/src/app/mod.rs index 9c2d852b74b..908e17170be 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,6 +1,4 @@ mod settings; -#[macro_use] -mod macros; pub mod parser; mod meta; mod help; diff --git a/tests/global_args.rs b/tests/global_args.rs index 6bcf11c5a3f..28eaac1124f 100644 --- a/tests/global_args.rs +++ b/tests/global_args.rs @@ -4,7 +4,7 @@ extern crate regex; #[cfg(test)] mod tests { include!("../clap-test.rs"); - use clap::{App, Arg, SubCommand, ArgMatches}; + use clap::{App, Arg, SubCommand}; fn get_app() -> App<'static, 'static> { App::new("myprog") diff --git a/tests/groups.rs b/tests/groups.rs index fa497bfb643..fde3f32c264 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -55,36 +55,45 @@ fn non_existing_arg() { #[test] fn group_single_value() { - let m = App::new("group") + let res = App::new("group") .args_from_usage("-f, --flag 'some flag' -c, --color [color] 'some option'") .group(ArgGroup::with_name("grp") .args(&["flag", "color"])) - .get_matches_from(vec!["", "-c", "blue"]); + .get_matches_from_safe(vec!["", "-c", "blue"]); + assert!(res.is_ok()); + + let m = res.unwrap(); assert!(m.is_present("grp")); assert_eq!(m.value_of("grp").unwrap(), "blue"); } #[test] fn group_single_flag() { - let m = App::new("group") + let res = App::new("group") .args_from_usage("-f, --flag 'some flag' -c, --color [color] 'some option'") .group(ArgGroup::with_name("grp") .args(&["flag", "color"])) - .get_matches_from(vec!["", "-f"]); + .get_matches_from_safe(vec!["", "-f"]); + assert!(res.is_ok()); + + let m = res.unwrap(); assert!(m.is_present("grp")); assert!(m.value_of("grp").is_none()); } #[test] fn group_empty() { - let m = App::new("group") + let res = App::new("group") .args_from_usage("-f, --flag 'some flag' -c, --color [color] 'some option'") .group(ArgGroup::with_name("grp") .args(&["flag", "color"])) - .get_matches_from(vec![""]); + .get_matches_from_safe(vec![""]); + assert!(res.is_ok()); + + let m = res.unwrap(); assert!(!m.is_present("grp")); assert!(m.value_of("grp").is_none()); } @@ -105,12 +114,15 @@ fn group_reqired_flags_empty() { #[test] fn group_multi_value_single_arg() { - let m = App::new("group") + let res = App::new("group") .args_from_usage("-f, --flag 'some flag' -c, --color [color]... 'some option'") .group(ArgGroup::with_name("grp") .args(&["flag", "color"])) - .get_matches_from(vec!["", "-c", "blue", "red", "green"]); + .get_matches_from_safe(vec!["", "-c", "blue", "red", "green"]); + assert!(res.is_ok(), "{:?}", res.unwrap_err().kind); + + let m = res.unwrap(); assert!(m.is_present("grp")); assert_eq!(&*m.values_of("grp").unwrap().collect::>(), &["blue", "red", "green"]); } @@ -148,19 +160,7 @@ fn req_group_with_conflict_usage_string() { .args(&["base", "delete"]) .required(true)); - assert!(test::compare_output(app, "clap-test --delete base", REQ_GROUP_CONFLICT_REV, true)); -} - -#[test] -fn req_group_with_conflict_rev_usage_string() { - let app = App::new("req_group") - .arg(Arg::from_usage("[base] 'Base commit'").conflicts_with("delete")) - .arg(Arg::from_usage("-d, --delete 'Remove the base commit information'")) - .group(ArgGroup::with_name("base_or_delete") - .args(&["base", "delete"]) - .required(true)); - - assert!(test::compare_output(app, "clap-test base --delete", REQ_GROUP_CONFLICT_USAGE, true)); + assert!(test::compare_output2(app, "clap-test --delete base", REQ_GROUP_CONFLICT_REV, REQ_GROUP_CONFLICT_USAGE, true)); } #[test] diff --git a/tests/multiple_values.rs b/tests/multiple_values.rs index 32f8a08e71a..7f35e06a82b 100644 --- a/tests/multiple_values.rs +++ b/tests/multiple_values.rs @@ -1106,13 +1106,16 @@ fn multiple_value_terminator_option_other_arg() { #[test] fn multiple_vals_with_hyphen() { - let m = App::new("do") + let res = App::new("do") .arg(Arg::with_name("cmds") .multiple(true) .allow_hyphen_values(true) .value_terminator(";")) .arg(Arg::with_name("location")) - .get_matches_from(vec!["do", "find", "-type", "f", "-name", "special", ";", "/home/clap"]); + .get_matches_from_safe(vec!["do", "find", "-type", "f", "-name", "special", ";", "/home/clap"]); + assert!(res.is_ok(), "{:?}", res.unwrap_err().kind); + + let m = res.unwrap(); let cmds: Vec<_> = m.values_of("cmds").unwrap().collect(); assert_eq!(&cmds, &["find", "-type", "f", "-name", "special"]); assert_eq!(m.value_of("location"), Some("/home/clap")); diff --git a/tests/posix_compatible.rs b/tests/posix_compatible.rs index 060bc5f7431..83f14481239 100644 --- a/tests/posix_compatible.rs +++ b/tests/posix_compatible.rs @@ -166,14 +166,13 @@ fn pos_required_overridden_by_flag() { #[test] fn require_overriden_2() { let m = App::new("require_overriden") - .arg(Arg::with_name("flag") - .index(1) + .arg(Arg::with_name("req_pos") .required(true)) .arg(Arg::from_usage("-c, --color 'other flag'") - .overrides_with("flag")) - .get_matches_from(vec!["", "-c", "flag"]); + .overrides_with("req_pos")) + .get_matches_from(vec!["", "-c", "req_pos"]); assert!(!m.is_present("color")); - assert!(m.is_present("flag")); + assert!(m.is_present("req_pos")); } #[test] diff --git a/tests/possible_values.rs b/tests/possible_values.rs index 0085c9e9e83..4939a7d7d8c 100644 --- a/tests/possible_values.rs +++ b/tests/possible_values.rs @@ -3,7 +3,7 @@ extern crate regex; include!("../clap-test.rs"); -#[allow(unsused_imports)] +#[allow(unused_imports)] use std::ascii::AsciiExt; use clap::{App, Arg, ErrorKind}; diff --git a/tests/subcommands.rs b/tests/subcommands.rs index e15de696974..de2f8b56117 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -32,22 +32,22 @@ SUBCOMMANDS: test Some help"; #[cfg(feature = "suggestions")] -static DYM: &'static str = "error: The subcommand 'subcm' wasn't recognized -\tDid you mean 'subcmd'? +static DYM_SUBCMD: &'static str = "error: The subcommand 'subcm' wasn't recognized + Did you mean 'subcmd'? -If you believe you received this message in error, try re-running with 'clap-test -- subcm' +If you believe you received this message in error, try re-running with 'dym -- subcm' USAGE: - clap-test [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND] + dym [SUBCOMMAND] For more information try --help"; #[cfg(feature = "suggestions")] -static DYM2: &'static str = "error: Found argument '--subcm' which wasn't expected, or isn't valid in this context +static DYM_ARG: &'static str = "error: Found argument '--subcm' which wasn't expected, or isn't valid in this context \tDid you mean to put '--subcmdarg' after the subcommand 'subcmd'? USAGE: - clap-test [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND] + dym [SUBCOMMAND] For more information try --help"; @@ -129,8 +129,18 @@ fn multiple_aliases() { #[test] #[cfg(feature="suggestions")] fn subcmd_did_you_mean_output() { - assert!(test::compare_output(test::complex_app(), "clap-test subcm", DYM, true)); - assert!(test::compare_output(test::complex_app(), "clap-test --subcm foo", DYM2, true)); + let app = App::new("dym") + .subcommand(SubCommand::with_name("subcmd")); + assert!(test::compare_output(app, "dym subcm", DYM_SUBCMD, true)); +} + +#[test] +#[cfg(feature="suggestions")] +fn subcmd_did_you_mean_output_arg() { + let app = App::new("dym") + .subcommand(SubCommand::with_name("subcmd") + .arg_from_usage("-s --subcmdarg [subcmdarg] 'tests'") ); + assert!(test::compare_output(app, "dym --subcm foo", DYM_ARG, true)); } #[test]