2015-08-27 21:03:45 +00:00
|
|
|
extern crate clap;
|
2016-05-10 02:46:09 +00:00
|
|
|
extern crate regex;
|
|
|
|
|
|
|
|
include!("../clap-test.rs");
|
2015-08-27 21:03:45 +00:00
|
|
|
|
2016-06-30 03:01:41 +00:00
|
|
|
use clap::{App, Arg, ErrorKind};
|
2015-08-27 21:03:45 +00:00
|
|
|
|
2017-01-03 04:05:23 +00:00
|
|
|
#[cfg(feature = "suggestions")]
|
|
|
|
static DYM: &'static str = "error: Found argument '--optio' which wasn't expected, or isn't valid in this context
|
|
|
|
\tDid you mean --option?
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
clap-test --option <opt>...
|
|
|
|
|
|
|
|
For more information try --help";
|
|
|
|
|
2017-02-18 02:56:34 +00:00
|
|
|
#[test]
|
|
|
|
fn require_equals_fail() {
|
|
|
|
let res = App::new("prog")
|
|
|
|
.arg(Arg::with_name("cfg")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.long("config"))
|
|
|
|
.get_matches_from_safe(vec![
|
|
|
|
"prog", "--config", "file.conf"
|
|
|
|
]);
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:27:19 +00:00
|
|
|
#[test]
|
|
|
|
fn require_equals_min_values_zero() {
|
|
|
|
let res = App::new("prog")
|
|
|
|
.arg(Arg::with_name("cfg")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.min_values(0)
|
|
|
|
.long("config"))
|
|
|
|
.arg(Arg::with_name("cmd"))
|
|
|
|
.get_matches_from_safe(vec![
|
|
|
|
"prog", "--config", "cmd"
|
|
|
|
]);
|
|
|
|
assert!(res.is_ok());
|
|
|
|
let m = res.unwrap();
|
|
|
|
assert!(m.is_present("cfg"));
|
|
|
|
assert_eq!(m.value_of("cmd"), Some("cmd"));
|
|
|
|
}
|
|
|
|
|
2017-05-15 22:08:33 +00:00
|
|
|
#[test]
|
|
|
|
fn double_hyphen_as_value() {
|
|
|
|
let res = App::new("prog")
|
|
|
|
.arg(Arg::with_name("cfg")
|
|
|
|
.takes_value(true)
|
|
|
|
.allow_hyphen_values(true)
|
|
|
|
.long("config"))
|
|
|
|
.get_matches_from_safe(vec![
|
|
|
|
"prog", "--config", "--"
|
|
|
|
]);
|
|
|
|
assert!(res.is_ok(), "{:?}", res);
|
|
|
|
assert_eq!(res.unwrap().value_of("cfg"), Some("--"));
|
|
|
|
}
|
|
|
|
|
2017-02-18 02:56:34 +00:00
|
|
|
#[test]
|
|
|
|
fn require_equals_no_empty_values_fail() {
|
|
|
|
let res = App::new("prog")
|
|
|
|
.arg(Arg::with_name("cfg")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.long("config"))
|
|
|
|
.arg(Arg::with_name("some"))
|
|
|
|
.get_matches_from_safe(vec![
|
|
|
|
"prog", "--config=", "file.conf"
|
|
|
|
]);
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn require_equals_empty_vals_pass() {
|
|
|
|
let res = App::new("prog")
|
|
|
|
.arg(Arg::with_name("cfg")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.empty_values(true)
|
|
|
|
.long("config"))
|
|
|
|
.get_matches_from_safe(vec![
|
|
|
|
"prog", "--config="
|
|
|
|
]);
|
|
|
|
assert!(res.is_ok());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn require_equals_pass() {
|
|
|
|
let res = App::new("prog")
|
|
|
|
.arg(Arg::with_name("cfg")
|
|
|
|
.require_equals(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.long("config"))
|
|
|
|
.get_matches_from_safe(vec![
|
|
|
|
"prog", "--config=file.conf"
|
|
|
|
]);
|
|
|
|
assert!(res.is_ok());
|
|
|
|
}
|
|
|
|
|
2016-02-04 06:34:46 +00:00
|
|
|
#[test]
|
|
|
|
fn stdin_char() {
|
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-f [flag] 'some flag'"))
|
2016-02-04 06:34:46 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-f", "-"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("f"));
|
|
|
|
assert_eq!(m.value_of("f").unwrap(), "-");
|
|
|
|
}
|
|
|
|
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_using_short() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.args(&[Arg::from_usage("-f [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("-c [color] 'some other flag'")])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-f", "some", "-c", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2016-01-25 20:56:37 +00:00
|
|
|
assert!(m.is_present("f"));
|
|
|
|
assert_eq!(m.value_of("f").unwrap(), "some");
|
|
|
|
assert!(m.is_present("c"));
|
|
|
|
assert_eq!(m.value_of("c").unwrap(), "other");
|
2015-08-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 12:43:53 +00:00
|
|
|
#[test]
|
|
|
|
fn lots_o_vals() {
|
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'"))
|
|
|
|
.get_matches_from_safe(vec!["", "-o", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some", "some", "some", "some",
|
|
|
|
"some", "some", "some", "some"]);
|
2016-02-02 12:43:53 +00:00
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>().len(), 297); // i.e. more than u8
|
|
|
|
}
|
|
|
|
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_using_long_space() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.args(&[Arg::from_usage("--flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("--color [color] 'some other flag'")])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "--flag", "some", "--color", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
|
|
|
}
|
|
|
|
|
2016-03-30 02:31:40 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_with_empty_values() {
|
|
|
|
let r = App::new("opts")
|
|
|
|
.arg_from_usage("--flag [flag]... 'some flag'")
|
|
|
|
.get_matches_from_safe(vec!["", "--flag", "", "test"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("flag"));
|
2016-12-30 21:25:48 +00:00
|
|
|
assert_eq!(m.values_of("flag").unwrap().collect::<Vec<_>>(),
|
|
|
|
["", "test"]);
|
2016-03-30 02:31:40 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_using_long_equals() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.args(&[Arg::from_usage("--flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("--color [color] 'some other flag'")])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "--flag=some", "--color=other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn opts_using_mixed() {
|
2016-01-26 07:05:32 +00:00
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.args(&[Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-f", "some", "--color", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
2016-01-26 07:05:32 +00:00
|
|
|
}
|
2015-08-27 21:03:45 +00:00
|
|
|
|
2016-01-26 07:05:32 +00:00
|
|
|
#[test]
|
|
|
|
fn opts_using_mixed2() {
|
|
|
|
let r = App::new("opts")
|
2016-12-30 21:25:48 +00:00
|
|
|
.args(&[Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
|
|
|
Arg::from_usage("-c, --color [color] 'some other flag'")])
|
2016-01-26 07:05:32 +00:00
|
|
|
.get_matches_from_safe(vec!["", "--flag=some", "-c", "other"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
2015-08-27 21:03:45 +00:00
|
|
|
assert!(m.is_present("flag"));
|
|
|
|
assert_eq!(m.value_of("flag").unwrap(), "some");
|
|
|
|
assert!(m.is_present("color"));
|
|
|
|
assert_eq!(m.value_of("color").unwrap(), "other");
|
2016-01-21 05:18:53 +00:00
|
|
|
}
|
2016-02-09 14:05:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_values_user_value() {
|
|
|
|
let r = App::new("df")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt] 'some opt'").default_value("default"))
|
2016-02-09 14:05:19 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-o", "value"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.value_of("o").unwrap(), "value");
|
|
|
|
}
|
2016-05-09 03:20:50 +00:00
|
|
|
|
2016-06-29 17:30:30 +00:00
|
|
|
#[test]
|
|
|
|
fn multiple_vals_pos_arg_equals() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'"))
|
|
|
|
.arg(Arg::from_usage("[file] 'some file'"))
|
2016-06-29 17:30:30 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-o=1", "some"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.value_of("o").unwrap(), "1");
|
|
|
|
assert!(m.is_present("file"));
|
|
|
|
assert_eq!(m.value_of("file").unwrap(), "some");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_vals_pos_arg_delim() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'"))
|
|
|
|
.arg(Arg::from_usage("[file] 'some file'"))
|
2016-06-29 17:30:30 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-o", "1,2", "some"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["1", "2"]);
|
|
|
|
assert!(m.is_present("file"));
|
|
|
|
assert_eq!(m.value_of("file").unwrap(), "some");
|
|
|
|
}
|
|
|
|
|
2016-06-30 03:01:41 +00:00
|
|
|
#[test]
|
|
|
|
fn require_delims_no_delim() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").require_delimiter(true))
|
|
|
|
.arg(Arg::from_usage("[file] 'some file'"))
|
2016-06-30 03:01:41 +00:00
|
|
|
.get_matches_from_safe(vec!["mvae", "-o", "1", "2", "some"]);
|
|
|
|
assert!(r.is_err());
|
|
|
|
let err = r.unwrap_err();
|
|
|
|
assert_eq!(err.kind, ErrorKind::UnknownArgument);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn require_delims() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").require_delimiter(true))
|
|
|
|
.arg(Arg::from_usage("[file] 'some file'"))
|
2016-06-30 03:01:41 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-o", "1,2", "some"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["1", "2"]);
|
|
|
|
assert!(m.is_present("file"));
|
|
|
|
assert_eq!(m.value_of("file").unwrap(), "some");
|
|
|
|
}
|
|
|
|
|
2016-11-20 01:40:53 +00:00
|
|
|
#[test]
|
|
|
|
fn leading_hyphen_pass() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").allow_hyphen_values(true))
|
2016-11-20 01:40:53 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-o", "-2", "3"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["-2", "3"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn leading_hyphen_fail() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt] 'some opt'"))
|
2016-11-20 01:40:53 +00:00
|
|
|
.get_matches_from_safe(vec!["", "-o", "-2"]);
|
|
|
|
assert!(r.is_err());
|
|
|
|
let m = r.unwrap_err();
|
|
|
|
assert_eq!(m.kind, ErrorKind::UnknownArgument);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn leading_hyphen_with_flag_after() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").allow_hyphen_values(true))
|
2016-11-20 01:40:53 +00:00
|
|
|
.arg_from_usage("-f 'some flag'")
|
|
|
|
.get_matches_from_safe(vec!["", "-o", "-2", "-f"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["-2", "-f"]);
|
|
|
|
assert!(!m.is_present("f"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn leading_hyphen_with_flag_before() {
|
|
|
|
let r = App::new("mvae")
|
2016-12-30 21:25:48 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").allow_hyphen_values(true))
|
2016-11-20 01:40:53 +00:00
|
|
|
.arg_from_usage("-f 'some flag'")
|
|
|
|
.get_matches_from_safe(vec!["", "-f", "-o", "-2"]);
|
|
|
|
assert!(r.is_ok());
|
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["-2"]);
|
|
|
|
assert!(m.is_present("f"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn leading_hyphen_with_only_pos_follows() {
|
|
|
|
let r = App::new("mvae")
|
2017-05-15 22:08:33 +00:00
|
|
|
.arg(Arg::from_usage("-o [opt]... 'some opt'").number_of_values(1).allow_hyphen_values(true))
|
2016-11-20 01:40:53 +00:00
|
|
|
.arg_from_usage("[arg] 'some arg'")
|
|
|
|
.get_matches_from_safe(vec!["", "-o", "-2", "--", "val"]);
|
2017-05-15 22:08:33 +00:00
|
|
|
assert!(r.is_ok(), "{:?}", r);
|
2016-11-20 01:40:53 +00:00
|
|
|
let m = r.unwrap();
|
|
|
|
assert!(m.is_present("o"));
|
|
|
|
assert_eq!(m.values_of("o").unwrap().collect::<Vec<_>>(), &["-2"]);
|
|
|
|
assert_eq!(m.value_of("arg"), Some("val"));
|
|
|
|
}
|
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
#[test]
|
2016-10-05 18:06:32 +00:00
|
|
|
#[cfg(feature="suggestions")]
|
2016-05-09 03:20:50 +00:00
|
|
|
fn did_you_mean() {
|
2017-01-03 04:05:23 +00:00
|
|
|
assert!(test::compare_output(test::complex_app(),
|
2016-12-30 21:25:48 +00:00
|
|
|
"clap-test --optio=foo",
|
2017-01-03 04:05:23 +00:00
|
|
|
DYM,
|
|
|
|
true));
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
2016-12-30 21:25:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_665() {
|
|
|
|
let res = App::new("tester")
|
|
|
|
.arg_from_usage("-v, --reroll-count=[N] 'Mark the patch series as PATCH vN'")
|
|
|
|
.arg(Arg::from_usage(
|
|
|
|
"--subject-prefix [Subject-Prefix] 'Use [Subject-Prefix] instead of the standard [PATCH] prefix'")
|
|
|
|
.empty_values(false))
|
|
|
|
.get_matches_from_safe(vec!["test", "--subject-prefix", "-v", "2"]);
|
|
|
|
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
2017-09-14 17:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_1047_min_zero_vals_default_val() {
|
|
|
|
let m = App::new("foo")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("del")
|
|
|
|
.short("d")
|
|
|
|
.long("del")
|
|
|
|
.takes_value(true)
|
|
|
|
.require_equals(true)
|
|
|
|
.min_values(0)
|
|
|
|
.default_value("default"),
|
|
|
|
)
|
|
|
|
.get_matches_from(vec!["foo", "-d"]);
|
|
|
|
assert_eq!(m.occurrences_of("del"), 1);
|
|
|
|
assert_eq!(m.value_of("del"), Some("default"));
|
2016-12-30 21:25:48 +00:00
|
|
|
}
|