test(Options): adds a test against issue 665

This commit is contained in:
Kevin K 2016-12-30 16:25:48 -05:00
parent 5a5f2b1e9f
commit 327c514d7a
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A

View file

@ -19,10 +19,8 @@ fn stdin_char() {
#[test]
fn opts_using_short() {
let r = App::new("opts")
.args(&[
Arg::from_usage("-f [flag] 'some flag'"),
Arg::from_usage("-c [color] 'some other flag'")
])
.args(&[Arg::from_usage("-f [flag] 'some flag'"),
Arg::from_usage("-c [color] 'some other flag'")])
.get_matches_from_safe(vec!["", "-f", "some", "-c", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -35,38 +33,50 @@ fn opts_using_short() {
#[test]
fn lots_o_vals() {
let r = App::new("opts")
.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",
]);
.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"]);
assert!(r.is_ok());
let m = r.unwrap();
assert!(m.is_present("o"));
@ -76,10 +86,8 @@ fn lots_o_vals() {
#[test]
fn opts_using_long_space() {
let r = App::new("opts")
.args(&[
Arg::from_usage("--flag [flag] 'some flag'"),
Arg::from_usage("--color [color] 'some other flag'")
])
.args(&[Arg::from_usage("--flag [flag] 'some flag'"),
Arg::from_usage("--color [color] 'some other flag'")])
.get_matches_from_safe(vec!["", "--flag", "some", "--color", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -97,16 +105,15 @@ fn opts_with_empty_values() {
assert!(r.is_ok());
let m = r.unwrap();
assert!(m.is_present("flag"));
assert_eq!(m.values_of("flag").unwrap().collect::<Vec<_>>(), ["", "test"]);
assert_eq!(m.values_of("flag").unwrap().collect::<Vec<_>>(),
["", "test"]);
}
#[test]
fn opts_using_long_equals() {
let r = App::new("opts")
.args(&[
Arg::from_usage("--flag [flag] 'some flag'"),
Arg::from_usage("--color [color] 'some other flag'")
])
.args(&[Arg::from_usage("--flag [flag] 'some flag'"),
Arg::from_usage("--color [color] 'some other flag'")])
.get_matches_from_safe(vec!["", "--flag=some", "--color=other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -119,10 +126,8 @@ fn opts_using_long_equals() {
#[test]
fn opts_using_mixed() {
let r = App::new("opts")
.args(&[
Arg::from_usage("-f, --flag [flag] 'some flag'"),
Arg::from_usage("-c, --color [color] 'some other flag'")
])
.args(&[Arg::from_usage("-f, --flag [flag] 'some flag'"),
Arg::from_usage("-c, --color [color] 'some other flag'")])
.get_matches_from_safe(vec!["", "-f", "some", "--color", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -135,10 +140,8 @@ fn opts_using_mixed() {
#[test]
fn opts_using_mixed2() {
let r = App::new("opts")
.args(&[
Arg::from_usage("-f, --flag [flag] 'some flag'"),
Arg::from_usage("-c, --color [color] 'some other flag'")
])
.args(&[Arg::from_usage("-f, --flag [flag] 'some flag'"),
Arg::from_usage("-c, --color [color] 'some other flag'")])
.get_matches_from_safe(vec!["", "--flag=some", "-c", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -151,8 +154,7 @@ fn opts_using_mixed2() {
#[test]
fn default_values_user_value() {
let r = App::new("df")
.arg( Arg::from_usage("-o [opt] 'some opt'")
.default_value("default"))
.arg(Arg::from_usage("-o [opt] 'some opt'").default_value("default"))
.get_matches_from_safe(vec!["", "-o", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -276,12 +278,27 @@ fn leading_hyphen_with_only_pos_follows() {
#[test]
#[cfg(feature="suggestions")]
fn did_you_mean() {
test::check_err_output(test::complex_app(), "clap-test --optio=foo",
test::check_err_output(test::complex_app(),
"clap-test --optio=foo",
"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", true);
For more information try --help",
true);
}
#[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);
}