From 3a8d2a579bce8e3a1555a7e905fdd796fee591d2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 27 Sep 2022 09:19:27 -0500 Subject: [PATCH] test(parser): Verify existing --flag=bad-value case --- tests/builder/flags.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/builder/flags.rs b/tests/builder/flags.rs index e86adcdf..48c54843 100644 --- a/tests/builder/flags.rs +++ b/tests/builder/flags.rs @@ -136,6 +136,24 @@ fn multiple_flags_in_single() { assert!(*m.get_one::("debug").expect("defaulted by clap")); } +#[test] +#[cfg(feature = "error-context")] +fn unexpected_value_error() { + const USE_FLAG_AS_ARGUMENT: &str = "\ +error: The value 'foo' was provided to '--a-flag' but it wasn't expecting any more values + +mycat [OPTIONS] [filename] + +For more information try '--help' +"; + + let cmd = Command::new("mycat") + .arg(Arg::new("filename")) + .arg(Arg::new("a-flag").long("a-flag").action(ArgAction::SetTrue)); + + utils::assert_output(cmd, "mycat --a-flag=foo", USE_FLAG_AS_ARGUMENT, true); +} + #[test] #[cfg(feature = "error-context")] fn issue_1284_argument_in_flag_style() {