Merge pull request #56 from kbknapp/tests

test(claptests): add more comprehensive tests
This commit is contained in:
Kevin K. 2015-04-02 19:20:13 -04:00
commit 2abebcd0b6
3 changed files with 144 additions and 79 deletions

3
.gitignore vendored
View file

@ -12,3 +12,6 @@
# Cargo files # Cargo files
Cargo.lock Cargo.lock
# Temp files
*~

View file

@ -5,81 +5,144 @@ import subprocess
failed = False failed = False
_bin = './target/release/claptests' _bin = './target/release/claptests'
cmds = {'help short: ': ['{} -h | wc -l'.format(_bin), ['21']], cmds = {'help short: ': ['{} -h | wc -l'.format(_bin), ['26']],
'help long: ': ['{} --help | wc -l'.format(_bin), ['21']], 'help long: ': ['{} --help | wc -l'.format(_bin), ['26']],
'help subcmd: ': ['{} help | wc -l'.format(_bin), ['21']], 'help subcmd: ': ['{} help | wc -l'.format(_bin), ['26']],
'flag short: ': ['{} -f'.format(_bin), ['flag present 1 times', 'excluded first: ': ['{} -f -F'.format(_bin), ['The argument -F is mutually exclusive with one or more other arguments',
'option NOT present', 'USAGE:',
'positional NOT present', ' claptests [FLAGS] [OPTIONS] --long-option-2=option2 [POSITIONAL] [SUBCOMMANDS]',
'subcmd NOT present']], 'For more information try --help']],
'flags short: ': ['{} -ff'.format(_bin), ['flag present 2 times', 'excluded last: ': ['{} -F -f'.format(_bin), ['The argument -f is mutually exclusive with one or more other arguments',
'option NOT present', 'USAGE:',
'positional NOT present', ' claptests [FLAGS] [OPTIONS] --long-option-2=option2 [POSITIONAL] [SUBCOMMANDS]',
'subcmd NOT present']], 'For more information try --help']],
'flags short: ': ['{} -f -f'.format(_bin), ['flag present 2 times', 'missing required: ': ['{} -F'.format(_bin), ['One or more required arguments were not supplied',
'option NOT present', 'USAGE:',
'positional NOT present', ' claptests [FLAGS] [OPTIONS] --long-option-2=option2 [POSITIONAL] [SUBCOMMANDS]',
'subcmd NOT present']], 'For more information try --help']],
'flag long: ': ['{} --flag'.format(_bin), ['flag present 1 times', 'F2(ll),O(s),P: ': ['{} --flag --flag -o some value'.format(_bin), ['flag present 2 times',
'option NOT present', 'option present 1 times with value: some',
'positional NOT present', 'An option: some',
'subcmd NOT present']], 'positional present with value: value',
'flags long: ': ['{} --flag --flag'.format(_bin), ['flag present 2 times', 'flag2 NOT present',
'option NOT present', 'option2 maybe present with value of: Nothing',
'positional NOT present', 'positional2 maybe present with value of: Nothing',
'subcmd NOT present']], 'option3 NOT present',
'flags both: ': ['{} -f --flag'.format(_bin), ['flag present 2 times', 'positional3 NOT present',
'option NOT present', 'option present 1 times with value: some',
'positional NOT present', 'An option: some',
'subcmd NOT present']], 'positional present with value: value',
'flags s/l(cmb):': ['{} -ff --flag'.format(_bin), ['flag present 3 times', 'subcmd NOT present']],
'option NOT present', 'F2(ss),O(s),P: ': ['{} -f -f -o some value'.format(_bin), ['flag present 2 times',
'positional NOT present', 'option present 1 times with value: some',
'subcmd NOT present']], 'An option: some',
'positional: ': ['{} some'.format(_bin), ['flag NOT present', 'positional present with value: value',
'option NOT present', 'flag2 NOT present',
'positional present with value: some', 'option2 maybe present with value of: Nothing',
'subcmd NOT present']], 'positional2 maybe present with value of: Nothing',
'option short: ': ['{} -o some'.format(_bin), ['flag NOT present', 'option3 NOT present',
'option present 1 times with value: some', 'positional3 NOT present',
'An option: some', 'option present 1 times with value: some',
'positional NOT present', 'An option: some',
'subcmd NOT present']], 'positional present with value: value',
'options short:': ['{} -o some -o other'.format(_bin), ['flag NOT present', 'subcmd NOT present']],
'option present 2 times with value: some', 'O2(ll)P: ': ['{} --option some --option other value'.format(_bin), ['flag NOT present',
'An option: some', 'option present 2 times with value: some',
'An option: other', 'An option: some',
'positional NOT present', 'An option: other',
'subcmd NOT present']], 'positional present with value: value',
'option long: ': ['{} --option some'.format(_bin), ['flag NOT present', 'flag2 NOT present',
'option present 1 times with value: some', 'option2 maybe present with value of: Nothing',
'An option: some', 'positional2 maybe present with value of: Nothing',
'positional NOT present', 'option3 NOT present',
'subcmd NOT present']], 'positional3 NOT present',
'options long: ': ['{} --option some --option other'.format(_bin), ['flag NOT present', 'option present 2 times with value: some',
'option present 2 times with value: some', 'An option: some',
'An option: some', 'An option: other',
'An option: other', 'positional present with value: value',
'positional NOT present', 'subcmd NOT present']],
'subcmd NOT present']], 'O2(l=l=)P: ': ['{} --option=some --option=other value'.format(_bin), ['flag NOT present',
'options long=:': ['{} --option=some --option=other'.format(_bin), ['flag NOT present', 'option present 2 times with value: some',
'option present 2 times with value: some', 'An option: some',
'An option: some', 'An option: other',
'An option: other', 'positional present with value: value',
'positional NOT present', 'flag2 NOT present',
'subcmd NOT present']], 'option2 maybe present with value of: Nothing',
'options 3: ': ['{} --option=some --option=other -o opt'.format(_bin), ['flag NOT present', 'positional2 maybe present with value of: Nothing',
'option present 3 times with value: some', 'option3 NOT present',
'An option: some', 'positional3 NOT present',
'An option: other', 'option present 2 times with value: some',
'An option: opt', 'An option: some',
'positional NOT present', 'An option: other',
'subcmd NOT present']], 'positional present with value: value',
'option long=: ': ['{} --option=some'.format(_bin), ['flag NOT present', 'subcmd NOT present']],
'option present 1 times with value: some', 'O2(ss)P: ': ['{} -o some -o other value'.format(_bin), ['flag NOT present',
'An option: some', 'option present 2 times with value: some',
'positional NOT present', 'An option: some',
'subcmd NOT present']]} 'An option: other',
'positional present with value: value',
'flag2 NOT present',
'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',
'An option: some',
'An option: other',
'positional present with value: value',
'subcmd NOT present']],
'F2(s2),O(s),P: ': ['{} -ff -o some value'.format(_bin), ['flag present 2 times',
'option present 1 times with value: some',
'An option: some',
'positional present with value: value',
'flag2 NOT present',
'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',
'An option: some',
'positional present with value: value',
'subcmd NOT present']],
'F(s),O(s),P: ': ['{} -f -o some value'.format(_bin), ['flag present 1 times',
'option present 1 times with value: some',
'An option: some',
'positional present with value: value',
'flag2 NOT present',
'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',
'An option: some',
'positional present with value: value',
'subcmd NOT present']],
'F(l),O(l),P: ': ['{} --flag --option some value'.format(_bin), ['flag present 1 times',
'option present 1 times with value: some',
'An option: some',
'positional present with value: value',
'flag2 NOT present',
'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',
'An option: some',
'positional present with value: value',
'subcmd NOT present']],
'F(l),O(l=),P: ': ['{} --flag --option=some value'.format(_bin), ['flag present 1 times',
'option present 1 times with value: some',
'An option: some',
'positional present with value: value',
'flag2 NOT present',
'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',
'An option: some',
'positional present with value: value',
'subcmd NOT present']]}
def pass_fail(name, check, good): def pass_fail(name, check, good):
global failed global failed

View file

@ -21,7 +21,6 @@ fn main() {
.arg(Arg::new("option") .arg(Arg::new("option")
.short("o") .short("o")
.long("option") .long("option")
.required(true)
.help("tests options") .help("tests options")
.takes_value(true) .takes_value(true)
.multiple(true)) .multiple(true))
@ -30,9 +29,9 @@ fn main() {
.help("tests positionals")) .help("tests positionals"))
.args(vec![ .args(vec![
Arg::new("flag2").short("F").mutually_excludes("flag").help("tests flags with exclusions").requires("option2"), Arg::new("flag2").short("F").mutually_excludes("flag").help("tests flags with exclusions").requires("option2"),
Arg::new("option2").takes_value(true).long("long-option-2").mutually_excludes("option").help("tests long options with exclusions and requirements").requires_all(vec!["positional", "positional2"]), Arg::new("option2").takes_value(true).long("long-option-2").mutually_excludes("option").help("tests long options with exclusions and requirements").requires("positional2"),
Arg::new("positional2").index(2).help("tests positionals with exclusions and multiple"), Arg::new("positional2").index(2).help("tests positionals with exclusions and multiple"),
Arg::new("option3").takes_value(true).short("O").possible_values(vec!["fast", "slow"]).help("test options with specific value sets").requires("positional3"), Arg::new("option3").takes_value(true).short("O").possible_values(vec!["fast", "slow"]).help("test options with specific value sets"),
Arg::new("positional3").index(3).multiple(true).possible_values(vec!["vi", "emacs"]).help("tests positionals with specific value sets") Arg::new("positional3").index(3).multiple(true).possible_values(vec!["vi", "emacs"]).help("tests positionals with specific value sets")
]) ])
.subcommand(SubCommand::new("subcmd") .subcommand(SubCommand::new("subcmd")