|
1 | 1 | use std::ffi::OsString;
|
2 | 2 |
|
3 |
| -use super::utils; |
4 |
| - |
5 | 3 | use clap::{arg, error::ErrorKind, Arg, ArgAction, Command};
|
6 | 4 |
|
| 5 | +use super::utils; |
| 6 | + |
7 | 7 | static ALLOW_EXT_SC: &str = "\
|
8 | 8 | Usage: clap-test [COMMAND]
|
9 | 9 |
|
@@ -253,6 +253,51 @@ fn infer_subcommands_pass_exact_match() {
|
253 | 253 | assert_eq!(m.subcommand_name(), Some("test"));
|
254 | 254 | }
|
255 | 255 |
|
| 256 | +#[test] |
| 257 | +fn infer_subcommands_pass_conflicting_aliases() { |
| 258 | + let m = Command::new("prog") |
| 259 | + .infer_subcommands(true) |
| 260 | + .subcommand(Command::new("test").aliases(["testa", "t", "testb"])) |
| 261 | + .try_get_matches_from(vec!["prog", "te"]); |
| 262 | + assert!(m.is_err(), "{:#?}", m.unwrap()); |
| 263 | +} |
| 264 | + |
| 265 | +#[test] |
| 266 | +#[should_panic(expected = "internal error")] |
| 267 | +fn infer_long_flag_pass_conflicting_aliases() { |
| 268 | + let m = Command::new("prog") |
| 269 | + .infer_subcommands(true) |
| 270 | + .subcommand( |
| 271 | + Command::new("c") |
| 272 | + .long_flag("test") |
| 273 | + .long_flag_aliases(["testa", "t", "testb"]), |
| 274 | + ) |
| 275 | + .try_get_matches_from(vec!["prog", "--te"]); |
| 276 | + assert!(m.is_err(), "{:#?}", m.unwrap()); |
| 277 | +} |
| 278 | + |
| 279 | +#[test] |
| 280 | +#[should_panic(expected = "internal error")] |
| 281 | +fn infer_long_flag() { |
| 282 | + let m = Command::new("prog") |
| 283 | + .infer_subcommands(true) |
| 284 | + .subcommand(Command::new("test").long_flag("testa")) |
| 285 | + .try_get_matches_from(vec!["prog", "--te"]) |
| 286 | + .unwrap(); |
| 287 | + assert_eq!(m.subcommand_name(), Some("test")); |
| 288 | +} |
| 289 | + |
| 290 | +#[test] |
| 291 | +fn infer_subcommands_long_flag_fail_with_args2() { |
| 292 | + let m = Command::new("prog") |
| 293 | + .infer_subcommands(true) |
| 294 | + .subcommand(Command::new("a").long_flag("test")) |
| 295 | + .subcommand(Command::new("b").long_flag("temp")) |
| 296 | + .try_get_matches_from(vec!["prog", "--te"]); |
| 297 | + assert!(m.is_err(), "{:#?}", m.unwrap()); |
| 298 | + assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument); |
| 299 | +} |
| 300 | + |
256 | 301 | #[cfg(feature = "suggestions")]
|
257 | 302 | #[test]
|
258 | 303 | fn infer_subcommands_fail_suggestions() {
|
|
0 commit comments