Skip to content

Commit

Permalink
test: Long flags inference
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
  • Loading branch information
Alex Saveau committed Sep 25, 2023
1 parent cb2d2bc commit e5c6993
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions tests/builder/app_settings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::ffi::OsString;

use super::utils;

use clap::{arg, error::ErrorKind, Arg, ArgAction, Command};

use super::utils;

static ALLOW_EXT_SC: &str = "\
Usage: clap-test [COMMAND]
Expand Down Expand Up @@ -253,6 +253,51 @@ fn infer_subcommands_pass_exact_match() {
assert_eq!(m.subcommand_name(), Some("test"));
}

#[test]
fn infer_subcommands_pass_conflicting_aliases() {
let m = Command::new("prog")
.infer_subcommands(true)
.subcommand(Command::new("test").aliases(["testa", "t", "testb"]))
.try_get_matches_from(vec!["prog", "te"]);
assert!(m.is_err(), "{:#?}", m.unwrap());
}

#[test]
#[should_panic(expected = "internal error")]
fn infer_long_flag_pass_conflicting_aliases() {
let m = Command::new("prog")
.infer_subcommands(true)
.subcommand(
Command::new("c")
.long_flag("test")
.long_flag_aliases(["testa", "t", "testb"]),
)
.try_get_matches_from(vec!["prog", "--te"]);
assert!(m.is_err(), "{:#?}", m.unwrap());
}

#[test]
#[should_panic(expected = "internal error")]
fn infer_long_flag() {
let m = Command::new("prog")
.infer_subcommands(true)
.subcommand(Command::new("test").long_flag("testa"))
.try_get_matches_from(vec!["prog", "--te"])
.unwrap();
assert_eq!(m.subcommand_name(), Some("test"));
}

#[test]
fn infer_subcommands_long_flag_fail_with_args2() {
let m = Command::new("prog")
.infer_subcommands(true)
.subcommand(Command::new("a").long_flag("test"))
.subcommand(Command::new("b").long_flag("temp"))
.try_get_matches_from(vec!["prog", "--te"]);
assert!(m.is_err(), "{:#?}", m.unwrap());
assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument);
}

#[cfg(feature = "suggestions")]
#[test]
fn infer_subcommands_fail_suggestions() {
Expand Down

0 comments on commit e5c6993

Please sign in to comment.