clap/tests/builder/unique_args.rs

33 lines
1 KiB
Rust
Raw Normal View History

2019-06-25 23:02:53 +00:00
#[cfg(debug_assertions)]
#[test]
#[should_panic = "Argument names must be unique, but 'arg1' is in use by more than one argument or group"]
fn unique_arg_names() {
2022-02-12 03:48:29 +00:00
use clap::{Arg, Command};
2020-05-31 14:53:24 +00:00
2022-02-12 03:48:29 +00:00
let _ = Command::new("some")
.args(&[Arg::new("arg1").short('a'), Arg::new("arg1").short('b')])
.try_get_matches();
}
2019-06-25 23:02:53 +00:00
#[cfg(debug_assertions)]
#[test]
#[should_panic = "Short option names must be unique for each argument, but '-a' is in use by both 'arg1' and 'arg2'"]
fn unique_arg_shorts() {
2022-02-12 03:48:29 +00:00
use clap::{Arg, Command};
2020-05-31 14:53:24 +00:00
2022-02-12 03:48:29 +00:00
let _ = Command::new("some")
.args(&[Arg::new("arg1").short('a'), Arg::new("arg2").short('a')])
.try_get_matches();
}
2019-06-25 23:02:53 +00:00
#[cfg(debug_assertions)]
#[test]
#[should_panic = "Long option names must be unique for each argument, but '--long' is in use by both 'arg1' and 'arg2'"]
fn unique_arg_longs() {
2022-02-12 03:48:29 +00:00
use clap::{Arg, Command};
2020-05-31 14:53:24 +00:00
2022-02-12 03:48:29 +00:00
let _ = Command::new("some")
.args(&[Arg::new("arg1").long("long"), Arg::new("arg2").long("long")])
.try_get_matches();
}