From 86a162d1bb5e531e48faf6f84de0bf99cd479382 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Jun 2022 12:35:00 -0500 Subject: [PATCH] fix(parser): Deprecate occurrences_of This mostly exist for - Knowing of the value came from the command-line but we now have `ArgMatches::source` - Counting the number of flags but we now have `ArgAction::Count` --- clap_complete/src/dynamic.rs | 18 +- examples/multicall-busybox.rs | 2 +- examples/tutorial_builder/01_quick.rs | 16 +- examples/tutorial_builder/03_01_flag_count.rs | 13 +- src/parser/arg_matcher.rs | 3 + src/parser/matches/arg_matches.rs | 51 +--- src/parser/matches/matched_arg.rs | 3 + src/parser/parser.rs | 1 + src/parser/validator.rs | 1 + tests/builder/action.rs | 105 ++++++-- tests/builder/default_missing_vals.rs | 55 +++- tests/builder/delimiters.rs | 35 ++- tests/builder/env.rs | 70 ++++-- tests/builder/flags.rs | 10 +- tests/builder/grouped_values.rs | 20 +- tests/builder/multiple_occurrences.rs | 135 ++++++++-- tests/builder/multiple_values.rs | 237 ++++++++++++++---- tests/builder/opts.rs | 5 +- tests/builder/posix_compatible.rs | 35 ++- tests/builder/propagate_globals.rs | 15 +- tests/builder/tests.rs | 54 ++-- tests/builder/utils.rs | 8 +- 22 files changed, 654 insertions(+), 238 deletions(-) diff --git a/clap_complete/src/dynamic.rs b/clap_complete/src/dynamic.rs index 9112ac5e..8902ab20 100644 --- a/clap_complete/src/dynamic.rs +++ b/clap_complete/src/dynamic.rs @@ -22,7 +22,7 @@ pub mod bash { #[derive(Clone, Debug)] pub struct CompleteArgs { /// Path to write completion-registration to - #[clap(long, required = true, parse(from_os_str))] + #[clap(long, required = true, value_parser)] register: Option, #[clap( @@ -30,34 +30,36 @@ pub mod bash { required = true, value_name = "COMP_CWORD", hide_short_help = true, - group = "complete" + group = "complete", + value_parser )] index: Option, - #[clap(long, hide_short_help = true, group = "complete")] + #[clap(long, hide_short_help = true, group = "complete", value_parser)] ifs: Option, #[clap( long = "type", required = true, - arg_enum, hide_short_help = true, - group = "complete" + group = "complete", + value_parser )] comp_type: Option, - #[clap(long, hide_short_help = true, group = "complete")] + #[clap(long, hide_short_help = true, group = "complete", action)] space: bool, #[clap( long, conflicts_with = "space", hide_short_help = true, - group = "complete" + group = "complete", + action )] no_space: bool, - #[clap(raw = true, hide_short_help = true, group = "complete")] + #[clap(raw = true, hide_short_help = true, group = "complete", value_parser)] comp_words: Vec, } diff --git a/examples/multicall-busybox.rs b/examples/multicall-busybox.rs index ec0d7600..ec6a5802 100644 --- a/examples/multicall-busybox.rs +++ b/examples/multicall-busybox.rs @@ -35,7 +35,7 @@ fn main() { let matches = cmd.get_matches(); let mut subcommand = matches.subcommand(); if let Some(("busybox", cmd)) = subcommand { - if cmd.occurrences_of("install") > 0 { + if cmd.is_present("install") { unimplemented!("Make hardlinks to the executable here"); } subcommand = cmd.subcommand(); diff --git a/examples/tutorial_builder/01_quick.rs b/examples/tutorial_builder/01_quick.rs index 417f7380..d30b433f 100644 --- a/examples/tutorial_builder/01_quick.rs +++ b/examples/tutorial_builder/01_quick.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; -use clap::{arg, command, value_parser, Command}; +use clap::{arg, command, value_parser, ArgAction, Command}; fn main() { let matches = command!() @@ -15,9 +15,12 @@ fn main() { .required(false) .value_parser(value_parser!(PathBuf)), ) - .arg(arg!( - -d --debug ... "Turn debugging information on" - )) + .arg( + arg!( + -d --debug "Turn debugging information on" + ) + .action(ArgAction::Count), + ) .subcommand( Command::new("test") .about("does testing things") @@ -36,7 +39,10 @@ fn main() { // You can see how many times a particular flag or argument occurred // Note, only flags can have multiple occurrences - match matches.occurrences_of("debug") { + match matches + .get_one::("debug") + .expect("Count's are defaulted") + { 0 => println!("Debug mode is off"), 1 => println!("Debug mode is kind of on"), 2 => println!("Debug mode is on"), diff --git a/examples/tutorial_builder/03_01_flag_count.rs b/examples/tutorial_builder/03_01_flag_count.rs index c5532c07..387ab7ac 100644 --- a/examples/tutorial_builder/03_01_flag_count.rs +++ b/examples/tutorial_builder/03_01_flag_count.rs @@ -1,9 +1,16 @@ // Note: this requires the `cargo` feature -use clap::{arg, command}; +use clap::{arg, command, ArgAction}; fn main() { - let matches = command!().arg(arg!(-v --verbose ...)).get_matches(); + let matches = command!() + .arg(arg!(-v - -verbose).action(ArgAction::Count)) + .get_matches(); - println!("verbose: {:?}", matches.occurrences_of("verbose")); + println!( + "verbose: {:?}", + matches + .get_one::("verbose") + .expect("Count always defaulted") + ); } diff --git a/src/parser/arg_matcher.rs b/src/parser/arg_matcher.rs index b424863e..2c94484a 100644 --- a/src/parser/arg_matcher.rs +++ b/src/parser/arg_matcher.rs @@ -171,6 +171,7 @@ impl ArgMatcher { let ma = self.entry(id).or_insert(MatchedArg::new_arg(arg)); debug_assert_eq!(ma.type_id(), Some(arg.get_value_parser().type_id())); ma.set_source(ValueSource::CommandLine); + #[allow(deprecated)] ma.inc_occurrences(); ma.new_val_group(); } @@ -180,6 +181,7 @@ impl ArgMatcher { let ma = self.entry(id).or_insert(MatchedArg::new_group()); debug_assert_eq!(ma.type_id(), None); ma.set_source(ValueSource::CommandLine); + #[allow(deprecated)] ma.inc_occurrences(); ma.new_val_group(); } @@ -197,6 +199,7 @@ impl ArgMatcher { ) ); ma.set_source(ValueSource::CommandLine); + #[allow(deprecated)] ma.inc_occurrences(); ma.new_val_group(); } diff --git a/src/parser/matches/arg_matches.rs b/src/parser/matches/arg_matches.rs index 6b27174f..b0b1bd6a 100644 --- a/src/parser/matches/arg_matches.rs +++ b/src/parser/matches/arg_matches.rs @@ -561,51 +561,14 @@ impl ArgMatches { value.and_then(MatchedArg::source) } - /// The number of times an argument was used at runtime. - /// - /// If an argument isn't present it will return `0`. - /// - /// **NOTE:** This returns the number of times the argument was used, *not* the number of - /// values. For example, `-o val1 val2 val3 -o val4` would return `2` (2 occurrences, but 4 - /// values). See [Arg::multiple_occurrences][crate::Arg::multiple_occurrences]. - /// - /// # Panics - /// - /// If `id` is is not a valid argument or group name. - /// - /// # Examples - /// - /// ```rust - /// # use clap::{Command, Arg}; - /// let m = Command::new("myprog") - /// .arg(Arg::new("debug") - /// .short('d') - /// .multiple_occurrences(true)) - /// .get_matches_from(vec![ - /// "myprog", "-d", "-d", "-d" - /// ]); - /// - /// assert_eq!(m.occurrences_of("debug"), 3); - /// ``` - /// - /// This next example shows that counts actual uses of the argument, not just `-`'s - /// - /// ```rust - /// # use clap::{Command, Arg}; - /// let m = Command::new("myprog") - /// .arg(Arg::new("debug") - /// .short('d') - /// .multiple_occurrences(true)) - /// .arg(Arg::new("flag") - /// .short('f')) - /// .get_matches_from(vec![ - /// "myprog", "-ddfd" - /// ]); - /// - /// assert_eq!(m.occurrences_of("debug"), 3); - /// assert_eq!(m.occurrences_of("flag"), 1); - /// ``` + /// Deprecated, replaced with [`ArgMatches::get_many`]`.len()` or + /// [`ArgAction::Count`][crate::ArgAction]. + #[deprecated( + since = "3.2.0", + note = "Replaced with either `ArgMatches::get_many(...).len()` or `ArgAction::Count`" + )] pub fn occurrences_of(&self, id: T) -> u64 { + #![allow(deprecated)] self.get_arg(&Id::from(id)) .map_or(0, |a| a.get_occurrences()) } diff --git a/src/parser/matches/matched_arg.rs b/src/parser/matches/matched_arg.rs index 558e3098..9de738f8 100644 --- a/src/parser/matches/matched_arg.rs +++ b/src/parser/matches/matched_arg.rs @@ -67,14 +67,17 @@ impl MatchedArg { } } + #[deprecated(since = "3.2.0")] pub(crate) fn inc_occurrences(&mut self) { self.occurs += 1; } + #[deprecated(since = "3.2.0")] pub(crate) fn set_occurrences(&mut self, occurs: u64) { self.occurs = occurs } + #[deprecated(since = "3.2.0")] pub(crate) fn get_occurrences(&self) -> u64 { self.occurs } diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 100efcb8..bdda730e 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1197,6 +1197,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { if ident == Some(Identifier::Index) && arg.is_multiple_values_set() { // HACK: Maintain existing occurrence behavior let matched = matcher.get_mut(&arg.id).unwrap(); + #[allow(deprecated)] matched.set_occurrences(matched.num_vals() as u64); } if cfg!(debug_assertions) && matcher.needs_more_vals(arg) { diff --git a/src/parser/validator.rs b/src/parser/validator.rs index a7456f91..f075d1a7 100644 --- a/src/parser/validator.rs +++ b/src/parser/validator.rs @@ -330,6 +330,7 @@ impl<'help, 'cmd> Validator<'help, 'cmd> { } fn validate_arg_num_occurs(&self, a: &Arg, ma: &MatchedArg) -> ClapResult<()> { + #![allow(deprecated)] debug!( "Validator::validate_arg_num_occurs: {:?}={}", a.name, diff --git a/tests/builder/action.rs b/tests/builder/action.rs index 5c08590f..e6d426d4 100644 --- a/tests/builder/action.rs +++ b/tests/builder/action.rs @@ -11,7 +11,10 @@ fn set() { let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(matches.get_one::("mammal"), None); assert_eq!(matches.is_present("mammal"), false); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), None); let matches = cmd @@ -20,7 +23,10 @@ fn set() { .unwrap(); assert_eq!(matches.get_one::("mammal").unwrap(), "dog"); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(2)); let matches = cmd @@ -29,7 +35,10 @@ fn set() { .unwrap(); assert_eq!(matches.get_one::("mammal").unwrap(), "cat"); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(4)); } @@ -40,7 +49,10 @@ fn append() { let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(matches.get_one::("mammal"), None); assert_eq!(matches.is_present("mammal"), false); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), None); let matches = cmd @@ -49,7 +61,10 @@ fn append() { .unwrap(); assert_eq!(matches.get_one::("mammal").unwrap(), "dog"); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!( matches.indices_of("mammal").unwrap().collect::>(), vec![2] @@ -68,7 +83,10 @@ fn append() { vec!["dog", "cat"] ); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!( matches.indices_of("mammal").unwrap().collect::>(), vec![2, 4] @@ -83,7 +101,10 @@ fn set_true() { let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), false); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd @@ -92,7 +113,10 @@ fn set_true() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), true); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd @@ -101,7 +125,10 @@ fn set_true() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), true); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(2)); } @@ -120,13 +147,19 @@ fn set_true_with_explicit_default_value() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), true); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), false); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); } @@ -225,7 +258,10 @@ fn set_false() { let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), true); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd @@ -234,7 +270,10 @@ fn set_false() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), false); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd @@ -243,7 +282,10 @@ fn set_false() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), false); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(2)); } @@ -262,13 +304,19 @@ fn set_false_with_explicit_default_value() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), false); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), true); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); } @@ -333,7 +381,10 @@ fn count() { let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), 0); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd @@ -342,7 +393,10 @@ fn count() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), 1); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd @@ -351,7 +405,10 @@ fn count() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), 2); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(2)); } @@ -370,13 +427,19 @@ fn count_with_explicit_default_value() { .unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), 1); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); let matches = cmd.clone().try_get_matches_from(["test"]).unwrap(); assert_eq!(*matches.get_one::("mammal").unwrap(), 10); assert_eq!(matches.is_present("mammal"), true); - assert_eq!(matches.occurrences_of("mammal"), 0); + #[allow(deprecated)] + { + assert_eq!(matches.occurrences_of("mammal"), 0); + } assert_eq!(matches.index_of("mammal"), Some(1)); } diff --git a/tests/builder/default_missing_vals.rs b/tests/builder/default_missing_vals.rs index 1d2913e4..ecab4b82 100644 --- a/tests/builder/default_missing_vals.rs +++ b/tests/builder/default_missing_vals.rs @@ -19,7 +19,10 @@ fn opt_missing() { m.get_one::("color").map(|v| v.as_str()).unwrap(), "auto" ); - assert_eq!(m.occurrences_of("color"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("color"), 0); + } assert_eq!( m.value_source("color").unwrap(), clap::ValueSource::DefaultValue @@ -46,7 +49,10 @@ fn opt_present_with_missing_value() { m.get_one::("color").map(|v| v.as_str()).unwrap(), "always" ); - assert_eq!(m.occurrences_of("color"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("color"), 1); + } assert_eq!( m.value_source("color").unwrap(), clap::ValueSource::CommandLine @@ -73,7 +79,10 @@ fn opt_present_with_value() { m.get_one::("color").map(|v| v.as_str()).unwrap(), "never" ); - assert_eq!(m.occurrences_of("color"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("color"), 1); + } assert_eq!( m.value_source("color").unwrap(), clap::ValueSource::CommandLine @@ -99,7 +108,10 @@ fn opt_present_with_empty_value() { m.get_one::("color").map(|v| v.as_str()).unwrap(), "" ); - assert_eq!(m.occurrences_of("color"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("color"), 1); + } assert_eq!( m.value_source("color").unwrap(), clap::ValueSource::CommandLine @@ -164,7 +176,10 @@ fn default_missing_value_flag_value() { m.get_one::("flag").map(|v| v.as_str()), Some("false") ); - assert_eq!(m.occurrences_of("flag"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 0); + } assert_eq!( m.value_source("flag").unwrap(), clap::ValueSource::DefaultValue @@ -179,7 +194,10 @@ fn default_missing_value_flag_value() { m.get_one::("flag").map(|v| v.as_str()), Some("true") ); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } assert_eq!( m.value_source("flag").unwrap(), clap::ValueSource::CommandLine @@ -194,7 +212,10 @@ fn default_missing_value_flag_value() { m.get_one::("flag").map(|v| v.as_str()), Some("true") ); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } assert_eq!( m.value_source("flag").unwrap(), clap::ValueSource::CommandLine @@ -206,7 +227,10 @@ fn default_missing_value_flag_value() { m.get_one::("flag").map(|v| v.as_str()), Some("false") ); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } assert_eq!( m.value_source("flag").unwrap(), clap::ValueSource::CommandLine @@ -233,7 +257,10 @@ fn delimited_missing_value() { .collect::>(), vec!["one", "two"] ); - assert_eq!(m.occurrences_of("flag"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 0); + } let m = cmd.try_get_matches_from(["test", "--flag"]).unwrap(); assert_eq!( @@ -243,7 +270,10 @@ fn delimited_missing_value() { .collect::>(), vec!["three", "four"] ); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } } #[cfg(debug_assertions)] @@ -295,7 +325,10 @@ fn valid_index() { m.get_one::("color").map(|v| v.as_str()).unwrap(), "always" ); - assert_eq!(m.occurrences_of("color"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("color"), 1); + } assert_eq!( m.value_source("color").unwrap(), clap::ValueSource::CommandLine diff --git a/tests/builder/delimiters.rs b/tests/builder/delimiters.rs index 81f5dac8..fbbc1b66 100644 --- a/tests/builder/delimiters.rs +++ b/tests/builder/delimiters.rs @@ -10,7 +10,10 @@ fn opt_default_no_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -27,7 +30,10 @@ fn opt_eq_no_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -44,7 +50,10 @@ fn opt_s_eq_no_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -61,7 +70,10 @@ fn opt_s_default_no_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -78,7 +90,10 @@ fn opt_s_no_space_no_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -100,7 +115,10 @@ fn opt_s_no_space_mult_no_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -123,7 +141,10 @@ fn opt_eq_mult_def_delim() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() diff --git a/tests/builder/env.rs b/tests/builder/env.rs index 28129df3..9b4538cd 100644 --- a/tests/builder/env.rs +++ b/tests/builder/env.rs @@ -16,7 +16,10 @@ fn env() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "env" @@ -37,7 +40,10 @@ fn env_bool_literal() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("present")); - assert_eq!(m.occurrences_of("present"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("present"), 0); + } assert_eq!(m.get_one::("present").map(|v| v.as_str()), None); assert!(!m.is_present("negated")); assert!(!m.is_present("absent")); @@ -58,7 +64,10 @@ fn env_os() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "env" @@ -82,7 +91,10 @@ fn no_env() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(!m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!(m.get_one::("arg").map(|v| v.as_str()), None); } @@ -99,7 +111,10 @@ fn no_env_no_takes_value() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(!m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!(m.get_one::("arg").map(|v| v.as_str()), None); } @@ -119,7 +134,10 @@ fn with_default() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "env" @@ -141,7 +159,10 @@ fn opt_user_override() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 1); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "opt" @@ -171,7 +192,10 @@ fn positionals() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "env" @@ -193,7 +217,10 @@ fn positionals_user_override() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 1); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "opt" @@ -225,7 +252,10 @@ fn multiple_one() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_many::("arg") .unwrap() @@ -252,7 +282,10 @@ fn multiple_three() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_many::("arg") .unwrap() @@ -278,7 +311,10 @@ fn multiple_no_delimiter() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_many::("arg") .unwrap() @@ -304,7 +340,10 @@ fn possible_value() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "env" @@ -349,7 +388,10 @@ fn value_parser() { assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("arg"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("arg"), 0); + } assert_eq!( m.get_one::("arg").map(|v| v.as_str()).unwrap(), "env" diff --git a/tests/builder/flags.rs b/tests/builder/flags.rs index eb14a6e5..fcd3a2e0 100644 --- a/tests/builder/flags.rs +++ b/tests/builder/flags.rs @@ -56,7 +56,10 @@ fn lots_o_flags_sep() { assert!(r.is_ok(), "{:?}", r.unwrap_err().kind()); let m = r.unwrap(); assert!(m.is_present("o")); - assert_eq!(m.occurrences_of("o"), 297); // i.e. more than u8 + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("o"), 297); + } // i.e. more than u8 } #[test] @@ -74,7 +77,10 @@ fn lots_o_flags_combined() { assert!(r.is_ok(), "{:?}", r.unwrap_err().kind()); let m = r.unwrap(); assert!(m.is_present("o")); - assert_eq!(m.occurrences_of("o"), 297); // i.e. more than u8 + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("o"), 297); + } // i.e. more than u8 } #[test] diff --git a/tests/builder/grouped_values.rs b/tests/builder/grouped_values.rs index 9bf2de0d..4b5706c8 100644 --- a/tests/builder/grouped_values.rs +++ b/tests/builder/grouped_values.rs @@ -191,10 +191,16 @@ fn grouped_interleaved_positional_values() { .unwrap(); let pos: Vec<_> = m.grouped_values_of("pos").unwrap().collect(); assert_eq!(pos, vec![vec!["1", "2", "3", "4"]]); - assert_eq!(m.occurrences_of("pos"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 4); + } let flag: Vec<_> = m.grouped_values_of("flag").unwrap().collect(); assert_eq!(flag, vec![vec!["a"], vec!["b"]]); - assert_eq!(m.occurrences_of("flag"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 2); + } } #[test] @@ -214,10 +220,16 @@ fn grouped_interleaved_positional_occurrences() { .unwrap(); let pos: Vec<_> = m.grouped_values_of("pos").unwrap().collect(); assert_eq!(pos, vec![vec!["1"], vec!["2"], vec!["3"], vec!["4"]]); - assert_eq!(m.occurrences_of("pos"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 4); + } let flag: Vec<_> = m.grouped_values_of("flag").unwrap().collect(); assert_eq!(flag, vec![vec!["a"], vec!["b"]]); - assert_eq!(m.occurrences_of("flag"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 2); + } } #[test] diff --git a/tests/builder/multiple_occurrences.rs b/tests/builder/multiple_occurrences.rs index d0414919..fac64d0a 100644 --- a/tests/builder/multiple_occurrences.rs +++ b/tests/builder/multiple_occurrences.rs @@ -8,9 +8,15 @@ fn multiple_occurrences_of_flags_long() { .try_get_matches_from(vec!["", "--multflag", "--flag", "--multflag"]) .unwrap(); assert!(m.is_present("multflag")); - assert_eq!(m.occurrences_of("multflag"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multflag"), 2); + } assert!(m.is_present("flag")); - assert_eq!(m.occurrences_of("flag"), 1) + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } } #[test] @@ -21,9 +27,15 @@ fn multiple_occurrences_of_flags_short() { .try_get_matches_from(vec!["", "-m", "-f", "-m"]) .unwrap(); assert!(m.is_present("multflag")); - assert_eq!(m.occurrences_of("multflag"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multflag"), 2); + } assert!(m.is_present("flag")); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } } #[test] @@ -43,11 +55,20 @@ fn multiple_occurrences_of_flags_mixed() { ]) .unwrap(); assert!(m.is_present("multflag1")); - assert_eq!(m.occurrences_of("multflag1"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multflag1"), 3); + } assert!(m.is_present("multflag2")); - assert_eq!(m.occurrences_of("multflag2"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multflag2"), 2); + } assert!(m.is_present("flag")); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } } #[test] @@ -59,7 +80,10 @@ fn multiple_occurrences_of_positional() { .try_get_matches_from(&["test"]) .expect("zero occurrences work"); assert!(!m.is_present("multi")); - assert_eq!(m.occurrences_of("multi"), 0); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multi"), 0); + } assert!(m.get_many::("multi").is_none()); let m = cmd @@ -67,7 +91,10 @@ fn multiple_occurrences_of_positional() { .try_get_matches_from(&["test", "one"]) .expect("single occurrence work"); assert!(m.is_present("multi")); - assert_eq!(m.occurrences_of("multi"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multi"), 1); + } assert_eq!( m.get_many::("multi") .unwrap() @@ -81,7 +108,10 @@ fn multiple_occurrences_of_positional() { .try_get_matches_from(&["test", "one", "two", "three", "four"]) .expect("many occurrences work"); assert!(m.is_present("multi")); - assert_eq!(m.occurrences_of("multi"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multi"), 4); + } assert_eq!( m.get_many::("multi") .unwrap() @@ -102,7 +132,10 @@ fn multiple_occurrences_of_flags_large_quantity() { .try_get_matches_from(args) .unwrap(); assert!(m.is_present("multflag")); - assert_eq!(m.occurrences_of("multflag"), 1024); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("multflag"), 1024); + } } #[cfg(feature = "env")] @@ -119,18 +152,30 @@ fn multiple_occurrences_of_before_env() { let m = cmd.clone().try_get_matches_from(vec![""]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 0); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 0); + } let m = cmd.clone().try_get_matches_from(vec!["", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + } let m = cmd.clone().try_get_matches_from(vec!["", "-vv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + } let m = cmd.clone().try_get_matches_from(vec!["", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + } } #[cfg(feature = "env")] @@ -147,18 +192,30 @@ fn multiple_occurrences_of_after_env() { let m = cmd.clone().try_get_matches_from(vec![""]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 0); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 0); + } let m = cmd.clone().try_get_matches_from(vec!["", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + } let m = cmd.clone().try_get_matches_from(vec!["", "-vv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + } let m = cmd.clone().try_get_matches_from(vec!["", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + } } #[test] @@ -173,7 +230,10 @@ fn max_occurrences_implies_multiple_occurrences() { let m = cmd.try_get_matches_from(vec!["prog", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + } // One max should not imply multiple occurrences let cmd = Command::new("prog").arg( @@ -200,15 +260,24 @@ fn max_occurrences_try_inputs() { ); let m = cmd.clone().try_get_matches_from(vec!["prog", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + } let m = cmd.clone().try_get_matches_from(vec!["prog", "-vv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + } let m = cmd.clone().try_get_matches_from(vec!["prog", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + } let m = cmd.clone().try_get_matches_from(vec!["prog", "-vvvv"]); assert!(m.is_err()); @@ -218,7 +287,10 @@ fn max_occurrences_try_inputs() { .clone() .try_get_matches_from(vec!["prog", "-v", "-v", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + } let m = cmd .clone() @@ -233,17 +305,26 @@ fn max_occurrences_positional() { let cmd = Command::new("prog").arg(Arg::new("verbose").max_occurrences(3)); let m = cmd.clone().try_get_matches_from(vec!["prog", "v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 1); + } let m = cmd.clone().try_get_matches_from(vec!["prog", "v", "v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 2); + } let m = cmd .clone() .try_get_matches_from(vec!["prog", "v", "v", "v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); - assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + #[allow(deprecated)] + { + assert_eq!(m.unwrap().occurrences_of("verbose"), 3); + } let m = cmd .clone() diff --git a/tests/builder/multiple_values.rs b/tests/builder/multiple_values.rs index 6f33b65f..84d2cd41 100644 --- a/tests/builder/multiple_values.rs +++ b/tests/builder/multiple_values.rs @@ -19,7 +19,10 @@ fn option_long() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 3); + } assert_eq!( m.get_many::("option") .unwrap() @@ -46,7 +49,10 @@ fn option_short() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 3); + } assert_eq!( m.get_many::("option") .unwrap() @@ -76,7 +82,10 @@ fn option_mixed() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 4); + } assert_eq!( m.get_many::("option") .unwrap() @@ -102,7 +111,10 @@ fn option_exact_exact() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 3); + } assert_eq!( m.get_many::("option") .unwrap() @@ -127,7 +139,10 @@ fn option_exact_exact_not_mult() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -155,7 +170,10 @@ fn option_exact_exact_mult() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 2); + } assert_eq!( m.get_many::("option") .unwrap() @@ -215,7 +233,10 @@ fn option_min_exact() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 3); + } assert_eq!( m.get_many::("option") .unwrap() @@ -261,7 +282,10 @@ fn option_short_min_more_mult_occurs() { assert!(m.is_present("option")); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("option"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 4); + } assert_eq!( m.get_many::("option") .unwrap() @@ -289,7 +313,10 @@ fn option_short_min_more_single_occur() { assert!(m.is_present("option")); assert!(m.is_present("arg")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -316,7 +343,10 @@ fn option_max_exact() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 3); + } assert_eq!( m.get_many::("option") .unwrap() @@ -342,7 +372,10 @@ fn option_max_less() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 2); + } assert_eq!( m.get_many::("option") .unwrap() @@ -385,7 +418,10 @@ fn positional() { let m = m.unwrap(); assert!(m.is_present("pos")); - assert_eq!(m.occurrences_of("pos"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 3); + } assert_eq!( m.get_many::("pos") .unwrap() @@ -409,7 +445,10 @@ fn positional_exact_exact() { let m = m.unwrap(); assert!(m.is_present("pos")); - assert_eq!(m.occurrences_of("pos"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 3); + } assert_eq!( m.get_many::("pos") .unwrap() @@ -457,7 +496,10 @@ fn positional_min_exact() { let m = m.unwrap(); assert!(m.is_present("pos")); - assert_eq!(m.occurrences_of("pos"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 3); + } assert_eq!( m.get_many::("pos") .unwrap() @@ -487,7 +529,10 @@ fn positional_min_more() { let m = m.unwrap(); assert!(m.is_present("pos")); - assert_eq!(m.occurrences_of("pos"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 4); + } assert_eq!( m.get_many::("pos") .unwrap() @@ -507,7 +552,10 @@ fn positional_max_exact() { let m = m.unwrap(); assert!(m.is_present("pos")); - assert_eq!(m.occurrences_of("pos"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 3); + } assert_eq!( m.get_many::("pos") .unwrap() @@ -527,7 +575,10 @@ fn positional_max_less() { let m = m.unwrap(); assert!(m.is_present("pos")); - assert_eq!(m.occurrences_of("pos"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 2); + } assert_eq!( m.get_many::("pos") .unwrap() @@ -562,7 +613,10 @@ fn sep_long_equals() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -587,7 +641,10 @@ fn sep_long_space() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -612,7 +669,10 @@ fn sep_short_equals() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -637,7 +697,10 @@ fn sep_short_space() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -662,7 +725,10 @@ fn sep_short_no_space() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -686,7 +752,10 @@ fn sep_positional() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -711,7 +780,10 @@ fn different_sep() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -735,7 +807,10 @@ fn different_sep_positional() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -761,7 +836,10 @@ fn no_sep() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -783,7 +861,10 @@ fn no_sep_positional() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_one::("option").map(|v| v.as_str()).unwrap(), "val1,val2,val3" @@ -812,7 +893,10 @@ fn req_delimiter_long() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -851,7 +935,10 @@ fn req_delimiter_long_with_equal() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -890,7 +977,10 @@ fn req_delimiter_short_with_space() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -929,7 +1019,10 @@ fn req_delimiter_short_with_no_space() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -968,7 +1061,10 @@ fn req_delimiter_short_with_equal() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 1); + } assert_eq!( m.get_many::("option") .unwrap() @@ -1036,7 +1132,10 @@ fn req_delimiter_complex() { let m = m.unwrap(); assert!(m.is_present("option")); - assert_eq!(m.occurrences_of("option"), 10); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("option"), 10); + } assert_eq!( m.get_many::("option") .unwrap() @@ -1139,9 +1238,15 @@ fn low_index_positional() { let m = m.unwrap(); assert!(m.is_present("files")); - assert_eq!(m.occurrences_of("files"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("files"), 3); + } assert!(m.is_present("target")); - assert_eq!(m.occurrences_of("target"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("target"), 1); + } assert_eq!( m.get_many::("files") .unwrap() @@ -1176,9 +1281,15 @@ fn low_index_positional_in_subcmd() { let sm = m.subcommand_matches("test").unwrap(); assert!(sm.is_present("files")); - assert_eq!(sm.occurrences_of("files"), 3); + #[allow(deprecated)] + { + assert_eq!(sm.occurrences_of("files"), 3); + } assert!(sm.is_present("target")); - assert_eq!(sm.occurrences_of("target"), 1); + #[allow(deprecated)] + { + assert_eq!(sm.occurrences_of("target"), 1); + } assert_eq!( sm.get_many::("files") .unwrap() @@ -1212,9 +1323,15 @@ fn low_index_positional_with_option() { let m = m.unwrap(); assert!(m.is_present("files")); - assert_eq!(m.occurrences_of("files"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("files"), 3); + } assert!(m.is_present("target")); - assert_eq!(m.occurrences_of("target"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("target"), 1); + } assert_eq!( m.get_many::("files") .unwrap() @@ -1250,9 +1367,15 @@ fn low_index_positional_with_flag() { let m = m.unwrap(); assert!(m.is_present("files")); - assert_eq!(m.occurrences_of("files"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("files"), 3); + } assert!(m.is_present("target")); - assert_eq!(m.occurrences_of("target"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("target"), 1); + } assert_eq!( m.get_many::("files") .unwrap() @@ -1284,7 +1407,10 @@ fn multiple_value_terminator_option() { let m = m.unwrap(); assert!(m.is_present("other")); - assert_eq!(m.occurrences_of("other"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("other"), 1); + } assert!(m.is_present("files")); assert_eq!( m.get_many::("files") @@ -1498,7 +1624,10 @@ fn values_per_occurrence_named() { .collect::>(), ["val1", "val2"] ); - assert_eq!(m.occurrences_of("pos"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 1); + } let m = a.try_get_matches_from_mut(vec![ "myprog", "--pos", "val1", "val2", "--pos", "val3", "val4", @@ -1514,7 +1643,10 @@ fn values_per_occurrence_named() { .collect::>(), ["val1", "val2", "val3", "val4"] ); - assert_eq!(m.occurrences_of("pos"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 2); + } } #[test] @@ -1537,7 +1669,10 @@ fn values_per_occurrence_positional() { .collect::>(), ["val1", "val2"] ); - assert_eq!(m.occurrences_of("pos"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos"), 2); + } let m = a.try_get_matches_from_mut(vec!["myprog", "val1", "val2", "val3", "val4"]); let m = match m { @@ -1551,7 +1686,7 @@ fn values_per_occurrence_positional() { .collect::>(), ["val1", "val2", "val3", "val4"] ); - //assert_eq!(m.occurrences_of("pos"), 2); // Fails, we don't recognize this as two occurrences + //#[allow(deprecated)]{assert_eq!(m.occurrences_of("pos"), 2);} // Fails, we don't recognize this as two occurrences } // Theoretically we could support this but we aren't tracking occurrence boundaries for positionals @@ -1566,7 +1701,10 @@ fn positional_parser_advances() { assert!(m.is_ok(), "{}", m.unwrap_err()); let m = m.unwrap(); - assert_eq!(m.occurrences_of("pos1"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos1"), 1); + } assert_eq!( m.get_many::("pos1") .unwrap() @@ -1575,7 +1713,10 @@ fn positional_parser_advances() { ["val1", "val2"] ); - assert_eq!(m.occurrences_of("pos2"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("pos2"), 1); + } assert_eq!( m.get_many::("pos2") .unwrap() diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs index 53fd6fa6..858892f0 100644 --- a/tests/builder/opts.rs +++ b/tests/builder/opts.rs @@ -520,7 +520,10 @@ fn issue_1047_min_zero_vals_default_val() { ) .try_get_matches_from(vec!["foo", "-d"]) .unwrap(); - assert_eq!(m.occurrences_of("del"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("del"), 1); + } assert_eq!( m.get_one::("del").map(|v| v.as_str()), Some("default") diff --git a/tests/builder/posix_compatible.rs b/tests/builder/posix_compatible.rs index 7cdd10ec..db1c8f89 100644 --- a/tests/builder/posix_compatible.rs +++ b/tests/builder/posix_compatible.rs @@ -12,7 +12,10 @@ fn flag_overrides_itself() { assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); assert!(m.is_present("flag")); - assert_eq!(m.occurrences_of("flag"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 1); + } } #[test] @@ -23,7 +26,10 @@ fn mult_flag_overrides_itself() { assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); assert!(m.is_present("flag")); - assert_eq!(m.occurrences_of("flag"), 4); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("flag"), 4); + } } #[test] @@ -38,7 +44,10 @@ fn option_overrides_itself() { assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); assert!(m.is_present("opt")); - assert_eq!(m.occurrences_of("opt"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("opt"), 1); + } assert_eq!( m.get_one::("opt").map(|v| v.as_str()), Some("other") @@ -61,7 +70,10 @@ fn mult_option_require_delim_overrides_itself() { assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); assert!(m.is_present("opt")); - assert_eq!(m.occurrences_of("opt"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("opt"), 3); + } assert_eq!( m.get_many::("opt") .unwrap() @@ -93,7 +105,10 @@ fn mult_option_overrides_itself() { assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); assert!(m.is_present("opt")); - assert_eq!(m.occurrences_of("opt"), 2); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("opt"), 2); + } assert_eq!( m.get_many::("opt") .unwrap() @@ -114,7 +129,10 @@ fn option_use_delim_false_override_itself() { .try_get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]) .unwrap(); assert!(m.is_present("opt")); - assert_eq!(m.occurrences_of("opt"), 1); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("opt"), 1); + } assert_eq!( m.get_many::("opt") .unwrap() @@ -133,7 +151,10 @@ fn pos_mult_overrides_itself() { assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); assert!(m.is_present("val")); - assert_eq!(m.occurrences_of("val"), 3); + #[allow(deprecated)] + { + assert_eq!(m.occurrences_of("val"), 3); + } assert_eq!( m.get_many::("val") .unwrap() diff --git a/tests/builder/propagate_globals.rs b/tests/builder/propagate_globals.rs index 68ec2a1d..b47f022a 100644 --- a/tests/builder/propagate_globals.rs +++ b/tests/builder/propagate_globals.rs @@ -55,17 +55,26 @@ fn outer_can_access_arg>>(m: &ArgMatches, val: T) - } fn top_can_access_flag(m: &ArgMatches, present: bool, occurrences: u64) -> bool { - (m.is_present("GLOBAL_FLAG") == present) && (m.occurrences_of("GLOBAL_FLAG") == occurrences) + #[allow(deprecated)] + { + (m.is_present("GLOBAL_FLAG") == present) && (m.occurrences_of("GLOBAL_FLAG") == occurrences) + } } fn inner_can_access_flag(m: &ArgMatches, present: bool, occurrences: u64) -> bool { let m = get_inner_matches(m); - (m.is_present("GLOBAL_FLAG") == present) && (m.occurrences_of("GLOBAL_FLAG") == occurrences) + #[allow(deprecated)] + { + (m.is_present("GLOBAL_FLAG") == present) && (m.occurrences_of("GLOBAL_FLAG") == occurrences) + } } fn outer_can_access_flag(m: &ArgMatches, present: bool, occurrences: u64) -> bool { let m = get_outer_matches(m); - (m.is_present("GLOBAL_FLAG") == present) && (m.occurrences_of("GLOBAL_FLAG") == occurrences) + #[allow(deprecated)] + { + (m.is_present("GLOBAL_FLAG") == present) && (m.occurrences_of("GLOBAL_FLAG") == occurrences) + } } #[test] diff --git a/tests/builder/tests.rs b/tests/builder/tests.rs index 0e6ac25e..d8b6d69a 100644 --- a/tests/builder/tests.rs +++ b/tests/builder/tests.rs @@ -40,7 +40,7 @@ scpositional present with value: value "; static O2P: &str = "flag NOT present -option present 2 times with value: some +option present with value: some An option: some An option: other positional present with value: value @@ -49,7 +49,7 @@ option2 maybe present with value of: Nothing positional2 maybe present with value of: Nothing option3 NOT present positional3 NOT present -option present 2 times with value: some +option present with value: some An option: some An option: other positional present with value: value @@ -57,7 +57,7 @@ subcmd NOT present "; static F2OP: &str = "flag present 2 times -option present 1 times with value: some +option present with value: some An option: some positional present with value: value flag2 NOT present @@ -65,14 +65,14 @@ option2 maybe present with value of: Nothing positional2 maybe present with value of: Nothing option3 NOT present positional3 NOT present -option present 1 times with value: some +option present with value: some An option: some positional present with value: value subcmd NOT present "; static FOP: &str = "flag present 1 times -option present 1 times with value: some +option present with value: some An option: some positional present with value: value flag2 NOT present @@ -80,7 +80,7 @@ option2 maybe present with value of: Nothing positional2 maybe present with value of: Nothing option3 NOT present positional3 NOT present -option present 1 times with value: some +option present with value: some An option: some positional present with value: value subcmd NOT present @@ -91,21 +91,18 @@ pub fn check_complex_output(args: &str, out: &str) { let matches = utils::complex_app() .try_get_matches_from(args.split(' ').collect::>()) .unwrap(); - if matches.is_present("flag") { - writeln!(w, "flag present {} times", matches.occurrences_of("flag")).unwrap(); - } else { - writeln!(w, "flag NOT present").unwrap(); + match matches.get_one::("flag").unwrap() { + 0 => { + writeln!(w, "flag NOT present").unwrap(); + } + n => { + writeln!(w, "flag present {} times", n).unwrap(); + } } if matches.is_present("option") { if let Some(v) = matches.get_one::("option").map(|v| v.as_str()) { - writeln!( - w, - "option present {} times with value: {}", - matches.occurrences_of("option"), - v - ) - .unwrap(); + writeln!(w, "option present with value: {}", v).unwrap(); } if let Some(ov) = matches.get_many::("option") { for o in ov { @@ -186,13 +183,7 @@ pub fn check_complex_output(args: &str, out: &str) { if matches.is_present("option") { if let Some(v) = matches.get_one::("option").map(|v| v.as_str()) { - writeln!( - w, - "option present {} times with value: {}", - matches.occurrences_of("option"), - v - ) - .unwrap(); + writeln!(w, "option present with value: {}", v).unwrap(); } if let Some(ov) = matches.get_many::("option") { for o in ov { @@ -211,10 +202,13 @@ pub fn check_complex_output(args: &str, out: &str) { if let Some("subcmd") = matches.subcommand_name() { writeln!(w, "subcmd present").unwrap(); if let Some(matches) = matches.subcommand_matches("subcmd") { - if matches.is_present("flag") { - writeln!(w, "flag present {} times", matches.occurrences_of("flag")).unwrap(); - } else { - writeln!(w, "flag NOT present").unwrap(); + match matches.get_one::("flag").unwrap() { + 0 => { + writeln!(w, "flag NOT present").unwrap(); + } + n => { + writeln!(w, "flag present {} times", n).unwrap(); + } } if matches.is_present("option") { @@ -267,7 +261,7 @@ fn flag_x2_opt() { check_complex_output( "clap-test value -f -f -o some", "flag present 2 times -option present 1 times with value: some +option present with value: some An option: some positional present with value: value flag2 NOT present @@ -275,7 +269,7 @@ option2 maybe present with value of: Nothing positional2 maybe present with value of: Nothing option3 NOT present positional3 NOT present -option present 1 times with value: some +option present with value: some An option: some positional present with value: value subcmd NOT present diff --git a/tests/builder/utils.rs b/tests/builder/utils.rs index 16e73817..c3254d2c 100644 --- a/tests/builder/utils.rs +++ b/tests/builder/utils.rs @@ -5,7 +5,7 @@ use std::str; use regex::Regex; -use clap::{arg, Arg, ArgGroup, Command}; +use clap::{arg, Arg, ArgAction, ArgGroup, Command}; #[track_caller] pub fn assert_eq(expected: S, actual: S2) @@ -55,7 +55,11 @@ pub fn complex_app() -> Command<'static> { .multiple_occurrences(true), ) .arg(arg!([positional] "tests positionals")) - .arg(arg!(-f --flag ... "tests flags").global(true)) + .arg( + arg!(-f --flag "tests flags") + .action(ArgAction::Count) + .global(true), + ) .args(&[ arg!(flag2: -F "tests flags with exclusions") .conflicts_with("flag")