mirror of
https://github.com/clap-rs/clap
synced 2024-11-11 07:14:15 +00:00
Correct tests, reveal real problem
This commit is contained in:
parent
d7f6748887
commit
9477a5ffdb
2 changed files with 6 additions and 45 deletions
|
@ -11,15 +11,7 @@ USAGE:
|
|||
For more information try --help";
|
||||
|
||||
static REQ_GROUP_CONFLICT_USAGE: &str =
|
||||
"error: The argument '<base>' cannot be used with '--delete'
|
||||
|
||||
USAGE:
|
||||
clap-test <base|--delete>
|
||||
|
||||
For more information try --help";
|
||||
|
||||
#[allow(unused)]
|
||||
static REQ_GROUP_CONFLICT_REV: &str = "error: The argument '--delete' cannot be used with '<base>'
|
||||
"error: The argument '--delete' cannot be used with '<base>'
|
||||
|
||||
USAGE:
|
||||
clap-test <base|--delete>
|
||||
|
@ -27,22 +19,10 @@ USAGE:
|
|||
For more information try --help";
|
||||
|
||||
static REQ_GROUP_CONFLICT_ONLY_OPTIONS: &str =
|
||||
"error: Found argument '--all' which wasn't expected, or isn't valid in this context
|
||||
|
||||
\tIf you tried to supply `--all` as a value rather than a flag, use `-- --all`
|
||||
"error: The argument '--delete' cannot be used with '--all'
|
||||
|
||||
USAGE:
|
||||
clap-test <-a|--delete>
|
||||
|
||||
For more information try --help";
|
||||
|
||||
// FIXME: This message has regressed after https://github.com/clap-rs/clap/pull/1856
|
||||
// Need to roll back somehow.
|
||||
static REQ_GROUP_CONFLICT_REV_DEGRADED: &str =
|
||||
"error: Found argument 'base' which wasn't expected, or isn't valid in this context
|
||||
|
||||
USAGE:
|
||||
clap-test <base|--delete>
|
||||
clap-test <--all|--delete>
|
||||
|
||||
For more information try --help";
|
||||
|
||||
|
@ -214,10 +194,9 @@ fn req_group_with_conflict_usage_string() {
|
|||
.required(true),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output2(
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"clap-test --delete base",
|
||||
REQ_GROUP_CONFLICT_REV_DEGRADED,
|
||||
REQ_GROUP_CONFLICT_USAGE,
|
||||
true
|
||||
));
|
||||
|
@ -226,7 +205,7 @@ fn req_group_with_conflict_usage_string() {
|
|||
#[test]
|
||||
fn req_group_with_conflict_usage_string_only_options() {
|
||||
let app = App::new("req_group")
|
||||
.arg(Arg::from("<all> -a, -all 'All'").conflicts_with("delete"))
|
||||
.arg(Arg::from("<all> -a --all 'All'").conflicts_with("delete"))
|
||||
.arg(Arg::from(
|
||||
"<delete> -d, --delete 'Remove the base commit information'",
|
||||
))
|
||||
|
@ -235,11 +214,10 @@ fn req_group_with_conflict_usage_string_only_options() {
|
|||
.args(&["all", "delete"])
|
||||
.required(true),
|
||||
);
|
||||
assert!(utils::compare_output2(
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"clap-test --delete --all",
|
||||
REQ_GROUP_CONFLICT_ONLY_OPTIONS,
|
||||
REQ_GROUP_CONFLICT_USAGE,
|
||||
true
|
||||
));
|
||||
}
|
||||
|
|
|
@ -47,23 +47,6 @@ pub fn compare_output(l: App, args: &str, right: &str, stderr: bool) -> bool {
|
|||
compare(left, right)
|
||||
}
|
||||
|
||||
pub fn compare_output2(l: App, args: &str, right1: &str, right2: &str, stderr: bool) -> bool {
|
||||
let mut buf = Cursor::new(Vec::with_capacity(50));
|
||||
let res = l.try_get_matches_from(args.split(' ').collect::<Vec<_>>());
|
||||
let err = res.unwrap_err();
|
||||
write!(&mut buf, "{}", err).unwrap();
|
||||
let content = buf.into_inner();
|
||||
let left = String::from_utf8(content).unwrap();
|
||||
assert_eq!(
|
||||
stderr,
|
||||
err.use_stderr(),
|
||||
"Should Use STDERR failed. Should be {} but is {}",
|
||||
stderr,
|
||||
err.use_stderr()
|
||||
);
|
||||
compare(&*left, right1) || compare(&*left, right2)
|
||||
}
|
||||
|
||||
// Legacy tests from the python script days
|
||||
|
||||
pub fn complex_app() -> App<'static> {
|
||||
|
|
Loading…
Reference in a new issue