From 2c3f7f605432d47483624f5c4fc6f29a10e0402b Mon Sep 17 00:00:00 2001 From: Kevin K Date: Tue, 24 Oct 2017 10:45:33 -0400 Subject: [PATCH] tests: adds tests to protect against panics when using globals and calling App::get_matches_from_safe_borrow multiple times --- tests/global_args.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/global_args.rs diff --git a/tests/global_args.rs b/tests/global_args.rs new file mode 100644 index 00000000..6bcf11c5 --- /dev/null +++ b/tests/global_args.rs @@ -0,0 +1,37 @@ +extern crate clap; +extern crate regex; + +#[cfg(test)] +mod tests { + include!("../clap-test.rs"); + use clap::{App, Arg, SubCommand, ArgMatches}; + + fn get_app() -> App<'static, 'static> { + App::new("myprog") + .arg(Arg::with_name("GLOBAL_ARG") + .long("global-arg") + .help( + "Specifies something needed by the subcommands", + ) + .global(true) + .takes_value(true) + .default_value("default_value")) + .arg(Arg::with_name("GLOBAL_FLAG") + .long("global-flag") + .help( + "Specifies something needed by the subcommands", + ) + .multiple(true) + .global(true)) + .subcommand(SubCommand::with_name("outer") + .subcommand(SubCommand::with_name("inner"))) + } + + #[test] + fn issue_1076() { + let mut app = get_app(); + app.get_matches_from_safe_borrow(vec!["myprog"]); + app.get_matches_from_safe_borrow(vec!["myprog"]); + app.get_matches_from_safe_borrow(vec!["myprog"]); + } +}