mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
Fixup tests
This commit is contained in:
parent
b5af579c0b
commit
83b0ab5064
5 changed files with 70 additions and 18 deletions
|
@ -45,8 +45,13 @@ fn required_group_missing_arg() {
|
|||
assert_eq!(err.kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
// #[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
// This used to provide a nice, programmer-friendly error.
|
||||
// Now the error directs the programmer to file a bug report with clap.
|
||||
// #[should_panic(expected = "The group 'req' contains the arg 'flg' that doesn't actually exist.")]
|
||||
#[should_panic(expected = "internal error")]
|
||||
fn non_existing_arg() {
|
||||
let _ = App::new("group")
|
||||
.arg("-f, --flag 'some flag'")
|
||||
|
|
|
@ -4,7 +4,7 @@ extern crate regex;
|
|||
|
||||
include!("../clap-test.rs");
|
||||
|
||||
use clap::{App, AppSettings, Arg, ArgSettings, ErrorKind};
|
||||
use clap::{App, AppSettings, Arg, ArgGroup, ArgSettings, ErrorKind};
|
||||
|
||||
static REQUIRE_DELIM_HELP: &'static str = "test 1.3
|
||||
Kevin K.
|
||||
|
@ -532,6 +532,22 @@ OPTIONS:
|
|||
NETWORKING:
|
||||
-n, --no-proxy Do not use system proxy settings";
|
||||
|
||||
static ISSUE_1487: &'static str = "test
|
||||
|
||||
USAGE:
|
||||
ctest <arg1|arg2>
|
||||
|
||||
ARGS:
|
||||
<arg1>
|
||||
<arg2>
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Prints version information
|
||||
";
|
||||
|
||||
|
||||
|
||||
fn setup() -> App<'static> {
|
||||
App::new("test")
|
||||
.author("Kevin K.")
|
||||
|
@ -1505,3 +1521,16 @@ fn show_short_about_issue_897() {
|
|||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1487() {
|
||||
let app = App::new("test")
|
||||
.arg(Arg::with_name("arg1")
|
||||
.group("group1"))
|
||||
.arg(Arg::with_name("arg2")
|
||||
.group("group1"))
|
||||
.group(ArgGroup::with_name("group1")
|
||||
.args(&["arg1", "arg2"])
|
||||
.required(true));
|
||||
assert!(test::compare_output(app, "ctest -h", ISSUE_1487, false));
|
||||
}
|
||||
|
|
|
@ -963,8 +963,13 @@ fn req_delimiter_complex() {
|
|||
);
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "When using a positional argument with \
|
||||
.multiple(true) that is *not the last* positional argument, the last \
|
||||
positional argument (i.e the one with the highest index) *must* have \
|
||||
.required(true) or .last(true) set.")]
|
||||
fn low_index_positional_not_required() {
|
||||
let _ = App::new("lip")
|
||||
.arg(
|
||||
|
@ -974,11 +979,14 @@ fn low_index_positional_not_required() {
|
|||
.multiple(true),
|
||||
)
|
||||
.arg(Arg::with_name("target").index(2))
|
||||
.try_get_matches_from(vec!["lip", "file1", "file2", "file3", "target"]);
|
||||
.try_get_matches_from(vec![""]);
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "Only one positional argument with .multiple(true) \
|
||||
set is allowed per command, unless the second one also has .last(true) set")]
|
||||
fn low_index_positional_last_multiple_too() {
|
||||
let _ = App::new("lip")
|
||||
.arg(
|
||||
|
@ -993,11 +1001,14 @@ fn low_index_positional_last_multiple_too() {
|
|||
.required(true)
|
||||
.multiple(true),
|
||||
)
|
||||
.try_get_matches_from(vec!["lip", "file1", "file2", "file3", "target"]);
|
||||
.try_get_matches_from(vec![""]);
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "Only the last positional argument, or second to \
|
||||
last positional argument may be set to .multiple(true)")]
|
||||
fn low_index_positional_too_far_back() {
|
||||
let _ = App::new("lip")
|
||||
.arg(
|
||||
|
@ -1008,7 +1019,7 @@ fn low_index_positional_too_far_back() {
|
|||
)
|
||||
.arg(Arg::with_name("target").required(true).index(2))
|
||||
.arg(Arg::with_name("target2").required(true).index(3))
|
||||
.try_get_matches_from(vec!["lip", "file1", "file2", "file3", "target"]);
|
||||
.try_get_matches_from(vec![""]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -218,15 +218,16 @@ fn single_positional_required_usage_string() {
|
|||
assert_eq!(app.generate_usage(), "USAGE:\n test <FILE>");
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "Found positional argument which is not required \
|
||||
with a lower index than a required positional argument")]
|
||||
fn missing_required() {
|
||||
let r = App::new("test")
|
||||
let _ = App::new("test")
|
||||
.arg("[FILE1] 'some file'")
|
||||
.arg("<FILE2> 'some file'")
|
||||
.try_get_matches_from(vec!["test", "file"]);
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
.try_get_matches_from(vec![""]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -2,19 +2,23 @@ extern crate clap;
|
|||
|
||||
use clap::{App, Arg};
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "Arg names must be unique")]
|
||||
fn unique_arg_names() {
|
||||
let _ = App::new("some")
|
||||
.args(&[
|
||||
Arg::with_name("arg").short('a'),
|
||||
Arg::with_name("arg").short('b'),
|
||||
Arg::with_name("arg1").short('a'),
|
||||
Arg::with_name("arg1").short('b'),
|
||||
])
|
||||
.try_get_matches();
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "Argument short must be unique")]
|
||||
fn unique_arg_shorts() {
|
||||
let _ = App::new("some")
|
||||
.args(&[
|
||||
|
@ -24,8 +28,10 @@ fn unique_arg_shorts() {
|
|||
.try_get_matches();
|
||||
}
|
||||
|
||||
// This tests a programmer error and will only succeed with debug_assertions
|
||||
#[cfg(debug_assertions)]
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[should_panic(expected = "Argument long must be unique")]
|
||||
fn unique_arg_longs() {
|
||||
let _ = App::new("some")
|
||||
.args(&[
|
||||
|
|
Loading…
Reference in a new issue