2015-08-27 21:03:45 +00:00
|
|
|
use clap::{App, Arg};
|
|
|
|
|
2019-06-25 23:02:53 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
2020-04-24 20:06:13 +00:00
|
|
|
#[should_panic = "Argument names must be unique, but 'arg1' is in use by more than one argument or group"]
|
2015-08-27 21:03:45 +00:00
|
|
|
fn unique_arg_names() {
|
2018-01-25 02:08:14 +00:00
|
|
|
let _ = App::new("some")
|
|
|
|
.args(&[
|
2019-06-25 23:02:53 +00:00
|
|
|
Arg::with_name("arg1").short('a'),
|
|
|
|
Arg::with_name("arg1").short('b'),
|
2018-01-25 02:08:14 +00:00
|
|
|
])
|
2018-10-19 20:42:13 +00:00
|
|
|
.try_get_matches();
|
2015-08-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:02:53 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
2020-04-24 20:06:13 +00:00
|
|
|
#[should_panic = "Short option names must be unique for each argument, but '-a' is in use by both 'arg1' and 'arg2'"]
|
2015-08-27 21:03:45 +00:00
|
|
|
fn unique_arg_shorts() {
|
2018-01-25 02:08:14 +00:00
|
|
|
let _ = App::new("some")
|
|
|
|
.args(&[
|
2018-07-23 19:09:42 +00:00
|
|
|
Arg::with_name("arg1").short('a'),
|
|
|
|
Arg::with_name("arg2").short('a'),
|
2018-01-25 02:08:14 +00:00
|
|
|
])
|
2018-10-19 20:42:13 +00:00
|
|
|
.try_get_matches();
|
2015-08-27 21:03:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:02:53 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2015-08-27 21:03:45 +00:00
|
|
|
#[test]
|
2020-04-24 20:06:13 +00:00
|
|
|
#[should_panic = "Long option names must be unique for each argument, but '--long' is in use by both 'arg1' and 'arg2'"]
|
2015-08-27 21:03:45 +00:00
|
|
|
fn unique_arg_longs() {
|
2018-01-25 02:08:14 +00:00
|
|
|
let _ = App::new("some")
|
|
|
|
.args(&[
|
|
|
|
Arg::with_name("arg1").long("long"),
|
|
|
|
Arg::with_name("arg2").long("long"),
|
|
|
|
])
|
2018-10-19 20:42:13 +00:00
|
|
|
.try_get_matches();
|
2016-01-21 06:48:30 +00:00
|
|
|
}
|