mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Merge pull request #56 from kbknapp/tests
test(claptests): add more comprehensive tests
This commit is contained in:
commit
2abebcd0b6
3 changed files with 144 additions and 79 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,3 +12,6 @@
|
|||
|
||||
# Cargo files
|
||||
Cargo.lock
|
||||
|
||||
# Temp files
|
||||
*~
|
||||
|
|
|
@ -5,81 +5,144 @@ import subprocess
|
|||
failed = False
|
||||
|
||||
_bin = './target/release/claptests'
|
||||
cmds = {'help short: ': ['{} -h | wc -l'.format(_bin), ['21']],
|
||||
'help long: ': ['{} --help | wc -l'.format(_bin), ['21']],
|
||||
'help subcmd: ': ['{} help | wc -l'.format(_bin), ['21']],
|
||||
'flag short: ': ['{} -f'.format(_bin), ['flag present 1 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'flags short: ': ['{} -ff'.format(_bin), ['flag present 2 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'flags short: ': ['{} -f -f'.format(_bin), ['flag present 2 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'flag long: ': ['{} --flag'.format(_bin), ['flag present 1 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'flags long: ': ['{} --flag --flag'.format(_bin), ['flag present 2 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'flags both: ': ['{} -f --flag'.format(_bin), ['flag present 2 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'flags s/l(cmb):': ['{} -ff --flag'.format(_bin), ['flag present 3 times',
|
||||
'option NOT present',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'positional: ': ['{} some'.format(_bin), ['flag NOT present',
|
||||
'option NOT present',
|
||||
'positional present with value: some',
|
||||
'subcmd NOT present']],
|
||||
'option short: ': ['{} -o some'.format(_bin), ['flag NOT present',
|
||||
'option present 1 times with value: some',
|
||||
'An option: some',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'options short:': ['{} -o some -o other'.format(_bin), ['flag NOT present',
|
||||
'option present 2 times with value: some',
|
||||
'An option: some',
|
||||
'An option: other',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'option long: ': ['{} --option some'.format(_bin), ['flag NOT present',
|
||||
'option present 1 times with value: some',
|
||||
'An option: some',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'options long: ': ['{} --option some --option other'.format(_bin), ['flag NOT present',
|
||||
'option present 2 times with value: some',
|
||||
'An option: some',
|
||||
'An option: other',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'options long=:': ['{} --option=some --option=other'.format(_bin), ['flag NOT present',
|
||||
'option present 2 times with value: some',
|
||||
'An option: some',
|
||||
'An option: other',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'options 3: ': ['{} --option=some --option=other -o opt'.format(_bin), ['flag NOT present',
|
||||
'option present 3 times with value: some',
|
||||
'An option: some',
|
||||
'An option: other',
|
||||
'An option: opt',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']],
|
||||
'option long=: ': ['{} --option=some'.format(_bin), ['flag NOT present',
|
||||
'option present 1 times with value: some',
|
||||
'An option: some',
|
||||
'positional NOT present',
|
||||
'subcmd NOT present']]}
|
||||
cmds = {'help short: ': ['{} -h | wc -l'.format(_bin), ['26']],
|
||||
'help long: ': ['{} --help | wc -l'.format(_bin), ['26']],
|
||||
'help subcmd: ': ['{} help | wc -l'.format(_bin), ['26']],
|
||||
'excluded first: ': ['{} -f -F'.format(_bin), ['The argument -F is mutually exclusive with one or more other arguments',
|
||||
'USAGE:',
|
||||
' claptests [FLAGS] [OPTIONS] --long-option-2=option2 [POSITIONAL] [SUBCOMMANDS]',
|
||||
'For more information try --help']],
|
||||
'excluded last: ': ['{} -F -f'.format(_bin), ['The argument -f is mutually exclusive with one or more other arguments',
|
||||
'USAGE:',
|
||||
' claptests [FLAGS] [OPTIONS] --long-option-2=option2 [POSITIONAL] [SUBCOMMANDS]',
|
||||
'For more information try --help']],
|
||||
'missing required: ': ['{} -F'.format(_bin), ['One or more required arguments were not supplied',
|
||||
'USAGE:',
|
||||
' claptests [FLAGS] [OPTIONS] --long-option-2=option2 [POSITIONAL] [SUBCOMMANDS]',
|
||||
'For more information try --help']],
|
||||
'F2(ll),O(s),P: ': ['{} --flag --flag -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']],
|
||||
'F2(ss),O(s),P: ': ['{} -f -f -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']],
|
||||
'O2(ll)P: ': ['{} --option some --option other value'.format(_bin), ['flag NOT present',
|
||||
'option present 2 times with value: some',
|
||||
'An option: some',
|
||||
'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']],
|
||||
'O2(l=l=)P: ': ['{} --option=some --option=other value'.format(_bin), ['flag NOT present',
|
||||
'option present 2 times with value: some',
|
||||
'An option: some',
|
||||
'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']],
|
||||
'O2(ss)P: ': ['{} -o some -o other value'.format(_bin), ['flag NOT present',
|
||||
'option present 2 times with value: some',
|
||||
'An option: some',
|
||||
'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):
|
||||
global failed
|
||||
|
@ -115,4 +178,4 @@ def main():
|
|||
print('All tests passed!')
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main())
|
||||
|
|
|
@ -21,7 +21,6 @@ fn main() {
|
|||
.arg(Arg::new("option")
|
||||
.short("o")
|
||||
.long("option")
|
||||
.required(true)
|
||||
.help("tests options")
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
|
@ -30,9 +29,9 @@ fn main() {
|
|||
.help("tests positionals"))
|
||||
.args(vec![
|
||||
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("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")
|
||||
])
|
||||
.subcommand(SubCommand::new("subcmd")
|
||||
|
|
Loading…
Reference in a new issue