Added test to cover the case when cmdarg_purge erases or otherwise makes the cmdarg_cfg internals unusable, also changed the purge method to something much simpler

This commit is contained in:
2013-11-01 14:16:59 -04:00
parent f9e71bffe3
commit 16548e463b
2 changed files with 27 additions and 7 deletions

View File

@@ -1,5 +1,30 @@
source $(dirname ${BASH_SOURCE})/../cmdarg.sh
function shunittest_clean_state_usable()
{
function parse1()
{
cmdarg 'a:' 'a' 'some arg'
cmdarg 'b' 'b' 'some arg'
cmdarg_parse "$@"
}
function parse2()
{
cmdarg_purge
cmdarg 'c:' 'c' 'some arg'
cmdarg 'd' 'd' 'some arg'
cmdarg_parse "$@"
}
parse1 -a 3 -b
parse2 -c 5 -d
[[ "${cmdarg_cfg['c']}" == "5" ]] || return 1
[[ "${cmdarg_cfg['d']}" == "true" ]] || return 1
[[ "${cmdarg_cfg['a']}" == "" ]] || return 1
[[ "${cmdarg_cfg['b']}" == "" ]] || return 1
return 0
}
function shunittest_clean_state()
{
# Tests that cmdarg_purge ensures an empty config state
@@ -55,4 +80,4 @@ function shunittest_clean_state_subshells()
cmdarg_dump
return 1
fi
}
}