Introduces CMDARG_ERROR_BEHAVIOR. Adds some more tests. Introduces new behavior for hash validators (see README). Fixes a few odds and ends.
This commit is contained in:
54
tests/test_validators.sh
Normal file
54
tests/test_validators.sh
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/bash4
|
||||
|
||||
source $(dirname ${BASH_SOURCE[0]})/../cmdarg.sh
|
||||
|
||||
function shunittest_validator_for_hash
|
||||
{
|
||||
function my_hash_validator
|
||||
{
|
||||
value=${1:-$OPTARG}
|
||||
echo "my_hash_validator $value" >&2
|
||||
[[ "$value" == "value" ]]
|
||||
}
|
||||
|
||||
declare -A something
|
||||
|
||||
cmdarg_purge
|
||||
cmdarg 'x:{}' 'something' 'something' '' my_hash_validator || return 1
|
||||
set -x
|
||||
cmdarg_parse --something key=notavalue && return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function shunittest_validator_for_array
|
||||
{
|
||||
function my_array_validator
|
||||
{
|
||||
value=${1:-$OPTARG}
|
||||
echo "my_array_validator $value" >&2
|
||||
[[ "$value" == "value" ]]
|
||||
}
|
||||
|
||||
declare -a something
|
||||
|
||||
cmdarg_purge
|
||||
cmdarg 'x:[]' 'something' 'something' '' my_array_validator || return 1
|
||||
cmdarg_parse --something notavalue && return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
function shunittest_validator_failure_recognized
|
||||
{
|
||||
|
||||
function my_validator
|
||||
{
|
||||
value=${1:-$OPTARG}
|
||||
echo "my_validator $value" >&2
|
||||
[[ "$value" == "value" ]]
|
||||
}
|
||||
|
||||
cmdarg_purge
|
||||
cmdarg 'x:' 'something' 'something' '' my_validator
|
||||
cmdarg_parse --something notavalue || return 0
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user