use new logmsg and set --show in tests

This commit is contained in:
Kurtis Rader 2017-08-04 11:39:43 -07:00
parent 0c69e99d8b
commit 03fa5dad12
3 changed files with 162 additions and 27 deletions

View File

@ -1,39 +1,106 @@
####################
# No args is an error
argparse: No option specs were provided
####################
# Missing -- is an error
argparse: Missing -- separator
####################
# Flags but no option specs is an error
argparse: No option specs were provided
####################
# Invalid option specs
argparse: Invalid option spec 'h-' at char '-'
argparse: Short flag '+' invalid, must be alphanum or '#'
argparse: Invalid option spec 'h/help:' at char ':'
argparse: Invalid option spec 'h-help::' at char ':'
argparse: Invalid option spec 'h-help=x' at char 'x'
####################
# --max-args and --min-args work
min-max: Expected at least 1 args, got only 0
min-max: Expected at most 3 args, got 4
min-max: Expected at most 1 args, got 2
####################
# Invalid "#-val" spec
argparse: Implicit int short flag '#' does not allow modifiers like '='
####################
# Invalid arg in the face of a "#-val" spec
argparse: Unknown option '-x'
Standard input (line 38):
argparse '#-val' -- abc -x def
^
####################
# Defining a short flag more than once
argparse: Short flag 's' already defined
####################
# Defining a long flag more than once
argparse: Long flag 'short' already defined
####################
# Defining an implicit int flag more than once
argparse: Implicit int flag '#' already defined
####################
# Defining an implicit int flag with modifiers
argparse: Implicit int short flag 'v' does not allow modifiers like '='
####################
# No args
####################
# One arg and no matching flags
####################
# Five args with two matching a flag
####################
# Required, optional, and multiple flags
####################
# --stop-nonopt works
####################
# Implicit int flags work
####################
# Should be set to 987
####################
# Should be set to 765
####################
# Bool short flag only
####################
# Value taking short flag only
####################
# Implicit int short flag only
####################
# Implicit int short flag only with custom validation passes
####################
# Implicit int short flag only with custom validation fails
argparse: Value '499' for flag 'x' less than min allowed of '500'
####################
# Implicit int flag validation fails
argparse: Value '765x' for flag 'max' is not an integer
argparse: Value 'a1' for flag 'm' is not an integer
####################
# Check the exit status from argparse validation
####################
# Explicit int flag validation
argparse: Value '2' for flag 'm' greater than max allowed of '1'
argparse: Value '-1' for flag 'max' less than min allowed of '0'

View File

@ -3,23 +3,23 @@
##########
# Start by verifying a bunch of error conditions.
echo '# No args is an error' >&2
logmsg No args is an error
argparse
echo '# Missing -- is an error' >&2
logmsg Missing -- is an error
argparse h/help
echo '# Flags but no option specs is an error' >&2
logmsg Flags but no option specs is an error
argparse -s -- hello
echo '# Invalid option specs' >&2
logmsg Invalid option specs
argparse h-
argparse +help
argparse h/help:
argparse h-help::
argparse h-help=x
echo '# --max-args and --min-args work' >&2
logmsg --max-args and --min-args work
begin
argparse --name min-max --min-args 1 h/help --
argparse --name min-max --min-args 1 --max-args 3 h/help -- arg1
@ -31,55 +31,55 @@ begin
argparse --name min-max --max-args 1 h/help -- arg1 arg2
end
echo '# Invalid "#-val" spec' >&2
logmsg Invalid \"#-val\" spec
argparse '#-val=' -- abc -x def
echo '# Invalid arg in the face of a "#-val" spec' >&2
logmsg Invalid arg in the face of a \"#-val\" spec
argparse '#-val' -- abc -x def
echo '# Defining a short flag more than once' >&2
logmsg Defining a short flag more than once
argparse 's/short' 'x/xray' 's/long' -- -s -x --long
echo '# Defining a long flag more than once' >&2
logmsg Defining a long flag more than once
argparse 's/short' 'x/xray' 'l/short' -- -s -x --long
echo '# Defining an implicit int flag more than once' >&2
logmsg Defining an implicit int flag more than once
argparse '#-val' 'x/xray' 'v#val' -- -s -x --long
echo '# Defining an implicit int flag with modifiers' >&2
logmsg Defining an implicit int flag with modifiers
argparse 'v#val=' --
##########
# Now verify that validly formed invocations work as expected.
echo '# No args'
logmsg No args
argparse h/help --
echo '# One arg and no matching flags'
logmsg One arg and no matching flags
begin
argparse h/help -- help
set -l
end
echo '# Five args with two matching a flag'
logmsg Five args with two matching a flag
begin
argparse h/help -- help --help me -h 'a lot more'
set -l
end
echo '# Required, optional, and multiple flags'
logmsg Required, optional, and multiple flags
begin
argparse 'h/help' 'a/abc=' 'd/def=?' 'g/ghk=+' -- help --help me --ghk=g1 --abc=ABC --ghk g2 --d -g g3
set -l
end
echo '# --stop-nonopt works'
logmsg --stop-nonopt works
begin
argparse --stop-nonopt 'h/help' 'a/abc=' -- -a A1 -h --abc A2 non-opt 'second non-opt' --help
set -l
end
echo '# Implicit int flags work'
logmsg Implicit int flags work
for v in (set -l -n); set -e $v; end
argparse '#-val' -- abc -123 def
set -l
@ -87,37 +87,37 @@ for v in (set -l -n); set -e $v; end
argparse 'v/verbose' '#-val' 't/token=' -- -123 a1 --token woohoo --234 -v a2 --verbose
set -l
echo '# Should be set to 987'
logmsg Should be set to 987
for v in (set -l -n); set -e $v; end
argparse 'm#max' -- argle -987 bargle
set -l
echo '# Should be set to 765'
logmsg Should be set to 765
for v in (set -l -n); set -e $v; end
argparse 'm#max' -- argle -987 bargle --max 765
set -l
echo '# Bool short flag only'
logmsg Bool short flag only
for v in (set -l -n); set -e $v; end
argparse 'C' 'v' -- -C -v arg1 -v arg2
set -l
echo '# Value taking short flag only'
logmsg Value taking short flag only
for v in (set -l -n); set -e $v; end
argparse 'x=' 'v/verbose' -- --verbose arg1 -v -x arg2
set -l
echo '# Implicit int short flag only'
logmsg Implicit int short flag only
for v in (set -l -n); set -e $v; end
argparse 'x#' 'v/verbose' -- -v -v argle -v -x 321 bargle
set -l
echo '# Implicit int short flag only with custom validation passes'
logmsg Implicit int short flag only with custom validation passes
for v in (set -l -n); set -e $v; end
argparse 'x#!_validate_int --max 500' 'v/verbose' -- -v -v -x 499 -v
set -l
echo '# Implicit int short flag only with custom validation fails' >&2
logmsg Implicit int short flag only with custom validation fails
for v in (set -l -n); set -e $v; end
argparse 'x#!_validate_int --min 500' 'v/verbose' -- -v -v -x 499 -v
set -l
@ -125,19 +125,19 @@ set -l
##########
# Verify that flag value validation works.
echo '# Implicit int flag validation fails' >&2
logmsg Implicit int flag validation fails
argparse 'm#max' -- argle --max 765x bargle
and echo unxpected argparse return status >&2
argparse 'm#max' -- argle -ma1 bargle
and echo unxpected argparse return status >&2
echo '# Check the exit status from argparse validation'
logmsg Check the exit status from argparse validation
argparse 'm#max!set | grep _flag_; function x; return 57; end; x' -- argle --max=83 bargle 2>&1
set -l saved_status $status
test $saved_status -eq 57
and echo expected argparse return status $saved_status
echo '# Explicit int flag validation' >&2
logmsg Explicit int flag validation
# These should fail
argparse 'm#max!_validate_int --min 1 --max 1' -- argle -m2 bargle
and echo unexpected argparse return status $status >&2

View File

@ -1,10 +1,51 @@
####################
# No args is an error
####################
# Missing -- is an error
####################
# Flags but no option specs is an error
####################
# Invalid option specs
####################
# --max-args and --min-args work
####################
# Invalid "#-val" spec
####################
# Invalid arg in the face of a "#-val" spec
####################
# Defining a short flag more than once
####################
# Defining a long flag more than once
####################
# Defining an implicit int flag more than once
####################
# Defining an implicit int flag with modifiers
####################
# No args
####################
# One arg and no matching flags
argv help
####################
# Five args with two matching a flag
_flag_h '--help' '-h'
_flag_help '--help' '-h'
argv 'help' 'me' 'a lot more'
####################
# Required, optional, and multiple flags
_flag_a ABC
_flag_abc ABC
@ -15,12 +56,16 @@ _flag_ghk 'g1' 'g2' 'g3'
_flag_h --help
_flag_help --help
argv 'help' 'me'
####################
# --stop-nonopt works
_flag_a A2
_flag_abc A2
_flag_h -h
_flag_help -h
argv 'non-opt' 'second non-opt' '--help'
####################
# Implicit int flags work
_flag_val 123
argv 'abc' 'def'
@ -30,34 +75,57 @@ _flag_v '-v' '--verbose'
_flag_val -234
_flag_verbose '-v' '--verbose'
argv 'a1' 'a2'
####################
# Should be set to 987
_flag_m 987
_flag_max 987
argv 'argle' 'bargle'
####################
# Should be set to 765
_flag_m 765
_flag_max 765
argv 'argle' 'bargle'
####################
# Bool short flag only
_flag_C -C
_flag_v '-v' '-v'
argv 'arg1' 'arg2'
####################
# Value taking short flag only
_flag_v '--verbose' '-v'
_flag_verbose '--verbose' '-v'
_flag_x arg2
argv arg1
####################
# Implicit int short flag only
_flag_v '-v' '-v' '-v'
_flag_verbose '-v' '-v' '-v'
_flag_x 321
argv 'argle' 'bargle'
####################
# Implicit int short flag only with custom validation passes
_flag_v '-v' '-v' '-v'
_flag_verbose '-v' '-v' '-v'
_flag_x 499
argv
####################
# Implicit int short flag only with custom validation fails
####################
# Implicit int flag validation fails
####################
# Check the exit status from argparse validation
_flag_name max
_flag_value 83
expected argparse return status 57
####################
# Explicit int flag validation