Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #99 as well as other misc fixes #101

Merged
merged 5 commits into from
May 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 66 additions & 6 deletions clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
tests clap library

USAGE:
\tclaptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS]
claptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS]

FLAGS:
-f, --flag tests flags
Expand All @@ -18,9 +18,13 @@
-v, --version Prints version information

OPTIONS:
-o, --option <opt>... tests options
--long-option-2 <option2> tests long options with exclusions
-O <option3> tests options with specific value sets [values: fast slow]
--maxvals3 <maxvals>... Tests 3 max vals
--minvals2 <minvals>... Tests 2 min vals
--multvals <one> <two> Tests mutliple values, not mult occs
--multvalsmo <one> <two> Tests mutliple values, not mult occs
-o, --option <opt>... tests options
--long-option-2 <option2> tests long options with exclusions
-O <option3> tests options with specific value sets [values: fast slow]

POSITIONAL ARGUMENTS:
positional tests positionals
Expand Down Expand Up @@ -98,15 +102,15 @@
tests subcommands

USAGE:
\tclaptests subcmd [POSITIONAL] [FLAGS] [OPTIONS]
claptests subcmd [POSITIONAL] [FLAGS] [OPTIONS]

FLAGS:
-h, --help Prints help information
-f, --flag tests flags
-v, --version Prints version information

OPTIONS:
-o, --option <scoption>... tests options
-o, --option <scoption>... tests options

POSITIONAL ARGUMENTS:
scpositional tests positionals'''
Expand Down Expand Up @@ -143,6 +147,50 @@
An scoption: some
scpositional present with value: value'''

_min_vals_few = '''The argument '--minvals2 <minvals>...' requires at least 2 values, but 1 was provided
USAGE:
\tclaptests --minvals2 <minvals>...
For more information try --help'''

_exact = '''flag NOT present
option NOT present
positional NOT present
flag2 NOT present
option2 maybe present with value of: Nothing
positional2 maybe present with value of: Nothing
option3 NOT present
positional3 NOT present
option NOT present
positional NOT present
subcmd NOT present'''

_max_vals_more = '''flag NOT present
option NOT present
positional present with value: too
flag2 NOT present
option2 maybe present with value of: Nothing
positional2 maybe present with value of: Nothing
option3 NOT present
positional3 NOT present
option NOT present
positional present with value: too
subcmd NOT present'''

_mult_vals_more = '''Argument --multvals was supplied more than once, but does not support multiple values
USAGE:
\tclaptests --multvals <one> <two>
For more information try --help'''

_mult_vals_few = '''Argument '--multvals <one> <two>' requires a value but none was supplied
USAGE:
\tclaptests --multvals <one> <two>
For more information try --help'''

_mult_vals_2m1 = '''The argument '--multvalsmo <one> <two>' requires 2 values, but 1 was provided
USAGE:
\tclaptests --multvalsmo <one> <two>
For more information try --help'''

_bin = './target/release/claptests'

cmds = {'help short: ': ['{} -h'.format(_bin), _help],
Expand All @@ -152,6 +200,18 @@
'excluded last: ': ['{} -F -f'.format(_bin), _excluded_l],
'missing required: ': ['{} -F'.format(_bin), _required],
'F2(ll),O(s),P: ': ['{} value --flag --flag -o some'.format(_bin), _f2op],
'max_vals too many: ': ['{} --maxvals3 some other value too'.format(_bin), _max_vals_more],
'max_vals exact: ': ['{} --maxvals3 some other value'.format(_bin), _exact],
'max_vals less: ': ['{} --maxvals3 some other'.format(_bin), _exact],
'min_vals more: ': ['{} --minvals2 some other value too'.format(_bin), _exact],
'min_vals exact: ': ['{} --minvals2 some value'.format(_bin), _exact],
'min_vals too few: ': ['{} --minvals2 some'.format(_bin), _min_vals_few],
'mult_vals too many: ': ['{} --multvals some other --multvals some other'.format(_bin), _mult_vals_more],
'mult_vals too few: ': ['{} --multvals some'.format(_bin), _mult_vals_few],
'mult_vals exact: ': ['{} --multvals some other'.format(_bin), _exact],
'mult_valsmo x2: ': ['{} --multvalsmo some other --multvalsmo some other'.format(_bin), _exact],
'mult_valsmo x2-1: ': ['{} --multvalsmo some other --multvalsmo some'.format(_bin), _mult_vals_2m1],
'mult_valsmo x1: ': ['{} --multvalsmo some other'.format(_bin), _exact],
'F2(ss),O(s),P: ': ['{} value -f -f -o some'.format(_bin), _f2op],
'O2(ll)P: ': ['{} value --option some --option other'.format(_bin), _o2p],
'O2(l=l=)P: ': ['{} value --option=some --option=other'.format(_bin), _o2p],
Expand Down
7 changes: 6 additions & 1 deletion clap-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::{App, Arg, SubCommand};


fn main() {
let m_val_names = ["one", "two"];
let args = "-f --flag... 'tests flags'
-o --option=[opt]... 'tests options'
[positional] 'tests positionals'";
Expand All @@ -21,7 +22,11 @@ fn main() {
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").mutually_excludes("option").requires("positional2"),
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
Arg::from_usage("-O [option3] 'tests options with specific value sets'").possible_values(&opt3_vals),
Arg::from_usage("[positional3]... 'tests positionals with specific values'").possible_values(&pos3_vals)
Arg::from_usage("[positional3]... 'tests positionals with specific values'").possible_values(&pos3_vals),
Arg::from_usage("--multvals [multvals] 'Tests mutliple values, not mult occs'").value_names(&m_val_names),
Arg::from_usage("--multvalsmo [multvalsmo]... 'Tests mutliple values, not mult occs'").value_names(&m_val_names),
Arg::from_usage("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
Arg::from_usage("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
])
.subcommand(SubCommand::new("subcmd")
.about("tests subcommands")
Expand Down
Loading