aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorkate.ward <kate.ward@forestent.com>2008-11-12 21:26:05 +0000
committerkate.ward <kate.ward@forestent.com>2008-11-12 21:26:05 +0000
commit1b600c53cdd5ad1b8a487d50ec1d1e9b0992166c (patch)
tree9ff94f0ed14f26ce1d63876e986ac8ccfb2ff6c4 /source
parentcd0bafa6ee2ddd87a13d0eb14219b551cfa31a63 (diff)
downloadshflags-1b600c53cdd5ad1b8a487d50ec1d1e9b0992166c.tar.gz
fixed recursion bug in _flags_getFlagInfo(), and put more common stuff into test helpers
Diffstat (limited to 'source')
-rw-r--r--source/1.0/src/shflags33
-rwxr-xr-xsource/1.0/src/shflags_test_defines.sh9
-rw-r--r--source/1.0/src/shflags_test_helpers13
-rwxr-xr-xsource/1.0/src/shflags_test_parsing.sh9
-rwxr-xr-xsource/1.0/src/shflags_test_private.sh13
-rwxr-xr-xsource/1.0/src/shflags_test_public.sh10
6 files changed, 40 insertions, 47 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags
index bc3a10d..221ba51 100644
--- a/source/1.0/src/shflags
+++ b/source/1.0/src/shflags
@@ -376,27 +376,36 @@ _flags_genOptStr()
# integer: one of FLAGS_{TRUE|FALSE|ERROR}
_flags_getFlagInfo()
{
- _flags__name=$1
- _flags__info=$2
+ _flags_name_=$1
+ _flags_info_=$2
- _flags__var="__flags_${_flags__name}_${_flags__info}"
- _flags__strToEval="_flags__value=\"\${${_flags__var}:-}\""
- eval "${_flags__strToEval}"
- if [ -n "${_flags__value}" ]; then
+ _flags_nameVar_="__flags_${_flags_name_}_${_flags_info_}"
+ _flags_strToEval_="_flags_value_=\"\${${_flags_nameVar_}:-}\""
+ eval "${_flags_strToEval_}"
+ if [ -n "${_flags_value_}" ]; then
flags_return=${FLAGS_TRUE}
else
- _flags__type=`_flags_getFlagInfo "${_flags__name}" ${__FLAGS_INFO_TYPE_STR}`
- if [ ${_flags__type} -eq ${__FLAGS_TYPE_STRING} ]; then
+ # see if the _flags_name_ variable is a string as strings can be empty...
+ # note: the DRY principle would say to have this function call itself for
+ # the next three lines, but doing so results in an infinite loop as an
+ # invalid _flags_name_ will also not have the associated _type variable.
+ # Because it doesn't (it will evaluate to an empty string) the logic will
+ # try to find the _type variable of the _type variable, and so on. Not so
+ # good ;-)
+ _flags_typeVar_="__flags_${_flags_name_}_${__FLAGS_INFO_TYPE_STR}"
+ _flags_strToEval_="_flags_type_=\"\${${_flags_typeVar_}:-}\""
+ eval "${_flags_strToEval_}"
+ if [ "${_flags_type_}" = "${__FLAGS_TYPE_STRING}" ]; then
flags_return=${FLAGS_TRUE}
else
flags_return=${FLAGS_ERROR}
- flags_error="invalid variable name (${_flags__var})"
+ flags_error="invalid flag name (${_flags_nameVar_})"
fi
fi
- echo "${_flags__value}"
- unset _flags__info _flags__name _flags__strToEval _flags__type _flags__value \
- _flags__var
+ echo "${_flags_value_}"
+ unset _flags_info_ _flags_name_ _flags_strToEval_ _flags_type_ _flags_value_ \
+ _flags_nameVar_ _flags_typeVar_
[ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_error "${flags_error}"
return ${flags_return}
}
diff --git a/source/1.0/src/shflags_test_defines.sh b/source/1.0/src/shflags_test_defines.sh
index 3625d33..569156d 100755
--- a/source/1.0/src/shflags_test_defines.sh
+++ b/source/1.0/src/shflags_test_defines.sh
@@ -186,14 +186,7 @@ testShortNameLength()
oneTimeSetUp()
{
- # load flags
- [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
- . ${TH_SHFLAGS}
-
- tmpDir="${__shunit_tmpDir}/output"
- mkdir "${tmpDir}"
- stdoutF="${tmpDir}/stdout"
- stderrF="${tmpDir}/stderr"
+ th_oneTimeSetUp
}
setUp()
diff --git a/source/1.0/src/shflags_test_helpers b/source/1.0/src/shflags_test_helpers
index 565ca2e..df9db98 100644
--- a/source/1.0/src/shflags_test_helpers
+++ b/source/1.0/src/shflags_test_helpers
@@ -44,6 +44,19 @@ th_warn() { echo "test:WARN $@" >&2; }
th_error() { echo "test:ERROR $@" >&2; }
th_fatal() { echo "test:FATAL $@" >&2; }
+th_oneTimeSetUp()
+{
+ # load shFlags
+ [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
+ . ${TH_SHFLAGS}
+
+ # these files will be cleaned up automatically by shUnit2
+ tmpDir=${shunit_tmpDir}
+ stdoutF="${tmpDir}/stdout"
+ stderrF="${tmpDir}/stderr"
+ expectedF="${tmpDir}/expected"
+}
+
th_showOutput()
{
_th_rtrn=$1
diff --git a/source/1.0/src/shflags_test_parsing.sh b/source/1.0/src/shflags_test_parsing.sh
index 34ae779..40ff4c9 100755
--- a/source/1.0/src/shflags_test_parsing.sh
+++ b/source/1.0/src/shflags_test_parsing.sh
@@ -259,14 +259,7 @@ testMultipleNonFlagStringArgsWithSpaces()
oneTimeSetUp()
{
- # load flags
- [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
- . ${TH_SHFLAGS}
-
- tmpDir="${__shunit_tmpDir}/output"
- mkdir "${tmpDir}"
- stdoutF="${tmpDir}/stdout"
- stderrF="${tmpDir}/stderr"
+ th_oneTimeSetUp
if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} ]; then
th_warn 'Standard version of getopt found. Some tests will be skipped.'
diff --git a/source/1.0/src/shflags_test_private.sh b/source/1.0/src/shflags_test_private.sh
index 0da8fae..9e28c8b 100755
--- a/source/1.0/src/shflags_test_private.sh
+++ b/source/1.0/src/shflags_test_private.sh
@@ -24,9 +24,9 @@ testGetFlagInfo()
assertTrue 'request for valid flag info failed' $?
assertEquals 'invalid flag info returned' "${__flags_blah_foobar}" "${rslt}"
- rslt=`_flags_getFlagInfo 'blah' 'hubbabubba' >${stdoutF} 2>${stderrF}`
+ rslt=`_flags_getFlagInfo 'blah' 'hubbabubba' >"${stdoutF}" 2>"${stderrF}"`
assertEquals 'invalid flag did not result in an error' ${FLAGS_ERROR} $?
- assertErrorMsg 'invalid flag'
+ assertErrorMsg 'invalid flag name'
}
testItemInList()
@@ -100,14 +100,7 @@ testValidateInteger() {
oneTimeSetUp()
{
- # load flags
- [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
- . ${TH_SHFLAGS}
-
- tmpDir="${__shunit_tmpDir}/output"
- mkdir "${tmpDir}"
- stdoutF="${tmpDir}/stdout"
- stderrF="${tmpDir}/stderr"
+ th_oneTimeSetUp
}
setUp()
diff --git a/source/1.0/src/shflags_test_public.sh b/source/1.0/src/shflags_test_public.sh
index affdaa5..ea16bb0 100755
--- a/source/1.0/src/shflags_test_public.sh
+++ b/source/1.0/src/shflags_test_public.sh
@@ -123,15 +123,7 @@ EOF
oneTimeSetUp()
{
- # load flags
- [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
- . ${TH_SHFLAGS}
-
- tmpDir="${__shunit_tmpDir}/output"
- mkdir "${tmpDir}"
- stdoutF="${tmpDir}/stdout"
- stderrF="${tmpDir}/stderr"
- expectedF="${tmpDir}/expected"
+ th_oneTimeSetUp
}
setUp()