1 #[allow(unused_imports, dead_code)]
4 use std
::io
::{Cursor, Write}
;
8 use clap
::{App, Arg, SubCommand, ArgGroup}
;
10 fn compare
<S
, S2
>(l
: S
, r
: S2
) -> bool
14 let re
= Regex
::new("\x1b[^m]*m").unwrap();
15 // Strip out any mismatching \r character on windows that might sneak in on either side
16 let ls
= l
.as_ref().trim().replace("\r", "");
17 let rs
= r
.as_ref().trim().replace("\r", "");
18 let left
= re
.replace_all(&*ls
, "");
19 let right
= re
.replace_all(&*rs
, "");
20 let b
= left
== right
;
25 println
!("--> right");
26 println
!("{}", right
);
32 pub fn compare_output(l
: App
, args
: &str, right
: &str, stderr
: bool
) -> bool
{
33 let mut buf
= Cursor
::new(Vec
::with_capacity(50));
34 let res
= l
.get_matches_from_safe(args
.split(' '
).collect
::<Vec
<_
>>());
35 let err
= res
.unwrap_err();
36 err
.write_to(&mut buf
).unwrap();
37 let content
= buf
.into_inner();
38 let left
= String
::from_utf8(content
).unwrap();
39 assert_eq
!(stderr
, err
.use_stderr());
43 // Legacy tests from the pyhton script days
45 pub fn complex_app() -> App
<'
static, '
static> {
46 let args
= "-o --option=[opt]... 'tests options'
47 [positional] 'tests positionals'";
48 let opt3_vals
= ["fast", "slow"];
49 let pos3_vals
= ["vi", "emacs"];
52 .about("tests clap library")
53 .author("Kevin K. <kbknapp@gmail.com>")
54 .args_from_usage(args
)
55 .arg(Arg
::from_usage("-f --flag... 'tests flags'")
58 Arg
::from_usage("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("long-option-2"),
59 Arg
::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
60 Arg
::from_usage("[positional2] 'tests positionals with exclusions'"),
61 Arg
::from_usage("-O --Option [option3] 'specific vals'").possible_values(&opt3_vals
),
62 Arg
::from_usage("[positional3]... 'tests specific values'").possible_values(&pos3_vals
),
63 Arg
::from_usage("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
64 Arg
::from_usage("--multvalsmo... [one] [two] 'Tests mutliple values, and mult occs'"),
65 Arg
::from_usage("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
66 Arg
::from_usage("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
68 .subcommand(SubCommand
::with_name("subcmd")
69 .about("tests subcommands")
71 .author("Kevin K. <kbknapp@gmail.com>")
72 .arg_from_usage("-o --option [scoption]... 'tests options'")
73 .arg_from_usage("-s --subcmdarg [subcmdarg] 'tests other args'")
74 .arg_from_usage("[scpositional] 'tests positionals'"))