-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: adds tests to protect against panics when using globals and ca…
…lling App::get_matches_from_safe_borrow multiple times
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]); | ||
} | ||
} |