aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkate.ward <kate.ward@forestent.com>2013-01-15 00:00:39 +0000
committerkate.ward <kate.ward@forestent.com>2013-01-15 00:00:39 +0000
commita2adce1123a80620da2b670f0fa506f60d6b1dac (patch)
treef757d7d2c8d09c6453b97f9ec8ddc4e35a55ab1b
parent7417827a79ff56de4032a7b170b7a61788a090b8 (diff)
downloadshflags-a2adce1123a80620da2b670f0fa506f60d6b1dac.tar.gz
fixed all remaining failing tests
-rw-r--r--source/1.0/src/shflags2
-rw-r--r--source/1.0/src/shflags_test_helpers14
-rwxr-xr-xsource/1.0/src/shflags_test_parsing.sh106
-rwxr-xr-xsource/1.0/src/shflags_test_public.sh66
4 files changed, 104 insertions, 84 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags
index 06a2ed0..b77a6ab 100644
--- a/source/1.0/src/shflags
+++ b/source/1.0/src/shflags
@@ -599,7 +599,7 @@ _flags_validInt()
;;
esac
- case "${_flags_int_}" in
+ case ${_flags_int_} in
*[!0-9]*) flags_return=${FLAGS_FALSE} ;;
*) flags_return=${FLAGS_TRUE} ;;
esac
diff --git a/source/1.0/src/shflags_test_helpers b/source/1.0/src/shflags_test_helpers
index df9784c..a96219e 100644
--- a/source/1.0/src/shflags_test_helpers
+++ b/source/1.0/src/shflags_test_helpers
@@ -54,6 +54,7 @@ th_oneTimeSetUp()
tmpDir=${SHUNIT_TMPDIR}
stdoutF="${tmpDir}/stdout"
stderrF="${tmpDir}/stderr"
+ returnF="${tmpDir}/return"
expectedF="${tmpDir}/expected"
}
@@ -81,6 +82,19 @@ th_showOutput()
unset _th_rtrn _th_stdout _th_stderr
}
+# Some shells, zsh on Solaris in particular, return immediately from a sub-shell
+# when a non-zero return value is encountered. To properly catch these values,
+# they are either written to disk, or recognized as an error the file is empty.
+th_clearReturn() { cp /dev/null "${returnF}"; }
+th_queryReturn()
+{
+ if [ -s "${returnF}" ]; then
+ th_return=`cat "${returnF}"`
+ else
+ th_return=${SHUNIT_ERROR}
+ fi
+}
+
_th_assertMsg()
{
_th_alert_type_=$1
diff --git a/source/1.0/src/shflags_test_parsing.sh b/source/1.0/src/shflags_test_parsing.sh
index 9f4ba05..664db5b 100755
--- a/source/1.0/src/shflags_test_parsing.sh
+++ b/source/1.0/src/shflags_test_parsing.sh
@@ -54,31 +54,31 @@ testGetoptEnhanced()
testValidBoolsShort()
{
FLAGS -b >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "-b) FLAGS returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "-b) FLAGS returned a non-zero result (${r3turn})" ${r3turn}
value=${FLAGS_bool:-}
assertTrue "-b) boolean was not true (${value})." "${value}"
assertFalse '-b) expected no output to STDERR' "[ -s '${stderrF}' ]"
- test ${rtrn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}"
+ test ${r3turn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}"
th_showOutput $? "${stdoutF}" "${stderrF}"
DEFINE_boolean bool2 true '2nd boolean' B
FLAGS >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "-B) FLAGS returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "-B) FLAGS returned a non-zero result (${r3turn})" ${r3turn}
value=${FLAGS_bool2:-}
assertTrue "-B) boolean was not true (${value})" ${value}
assertFalse '-B) expected no output to STDERR' "[ -s '${stderrF}' ]"
- test ${rtrn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}"
+ test ${r3turn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}"
th_showOutput $? "${stdoutF}" "${stderrF}"
FLAGS -B >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "-B) FLAGS returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "-B) FLAGS returned a non-zero result (${r3turn})" ${r3turn}
value=${FLAGS_bool2:-}
assertFalse "-B) boolean was not false (${value})" ${value}
assertFalse '-B) expected no output to STDERR' "[ -s '${stderrF}' ]"
- test ${rtrn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}"
+ test ${r3turn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}"
th_showOutput $? "${stdoutF}" "${stderrF}"
}
@@ -91,27 +91,27 @@ testValidBoolsLong()
# leave flag false
FLAGS --nobool >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "FLAGS returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "FLAGS returned a non-zero result (${r3turn})" ${r3turn}
assertFalse '--noXX flag resulted in true value.' ${FLAGS_bool:-}
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
# flip flag true
FLAGS --bool >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "FLAGS returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "FLAGS returned a non-zero result (${r3turn})" ${r3turn}
assertTrue '--XX flag resulted in false value.' ${FLAGS_bool:-}
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
# flip flag back false
FLAGS --nobool >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "FLAGS returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "FLAGS returned a non-zero result (${r3turn})" ${r3turn}
assertFalse '--noXX flag resulted in true value.' ${FLAGS_bool:-}
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
}
testValidFloats()
@@ -126,12 +126,12 @@ _testValidFloats()
flag=$1
for value in ${TH_FLOAT_VALID}; do
FLAGS ${flag} ${value} >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "FLAGS ${flag} ${value} returned non-zero result (${rtrn})" \
- ${rtrn}
+ r3turn=$?
+ assertTrue "FLAGS ${flag} ${value} returned non-zero result (${r3turn})" \
+ ${r3turn}
assertEquals "float (${flag} ${value}) test failed." ${value} ${FLAGS_float}
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
done
}
@@ -146,9 +146,13 @@ _testInvalidFloats()
{
flag=$1
for value in ${TH_FLOAT_INVALID}; do
- ( FLAGS ${flag} ${value} >"${stdoutF}" 2>"${stderrF}"; )
- rtrn=$?
- assertFalse "FLAGS (${value}) returned a zero result" ${rtrn}
+ th_clearReturn
+ (
+ FLAGS ${flag} ${value} >"${stdoutF}" 2>"${stderrF}"
+ echo $? >"${returnF}"
+ )
+ th_queryReturn
+ assertFalse "FLAGS (${value}) returned a zero result" ${th_return}
assertFalse 'expected no output to STDOUT' "[ -s '${stdoutF}' ]"
assertTrue 'expected output to STDERR' "[ -s '${stderrF}' ]"
done
@@ -166,11 +170,11 @@ _testValidIntegers()
flag=$1
for value in ${TH_INT_VALID}; do
FLAGS ${flag} ${value} >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "FLAGS (${value}) returned a non-zero result (${rtrn})" ${rtrn}
+ r3turn=$?
+ assertTrue "FLAGS (${value}) returned a non-zero result (${r3turn})" ${r3turn}
assertEquals "integer (${value}) test failed." ${value} ${FLAGS_int}
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
done
}
@@ -185,9 +189,13 @@ _testInvalidIntegers()
{
flag=$1
for value in ${TH_INT_INVALID}; do
- ( FLAGS ${flag} ${value} >"${stdoutF}" 2>"${stderrF}"; )
- rtrn=$?
- assertFalse "invalid integer (${value}) test returned success." ${rtrn}
+ th_clearReturn
+ (
+ FLAGS ${flag} ${value} >"${stdoutF}" 2>"${stderrF}"
+ echo $? >"${returnF}"
+ )
+ th_queryReturn
+ assertFalse "invalid integer (${value}) test returned success." ${th_return}
assertFalse 'expected no output to STDOUT' "[ -s '${stdoutF}' ]"
assertTrue 'expected output to STDERR' "[ -s '${stderrF}' ]"
done
@@ -208,17 +216,17 @@ _testValidStrings()
value=$2
FLAGS ${flag} "${value}" >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "'FLAGS ${flag} ${value}' returned a non-zero result (${rtrn})" \
- ${rtrn}
+ r3turn=$?
+ assertTrue "'FLAGS ${flag} ${value}' returned a non-zero result (${r3turn})" \
+ ${r3turn}
assertEquals "string (${value}) test failed." "${value}" "${FLAGS_str}"
- if [ ${rtrn} -eq ${FLAGS_TRUE} ]; then
+ if [ ${r3turn} -eq ${FLAGS_TRUE} ]; then
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
else
# validate that an error is thrown for unsupported getopt uses
assertFatalMsg '.* spaces in options'
fi
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
}
testMultipleFlags()
@@ -241,14 +249,14 @@ _testMultipleFlags()
${floatFlag} 123.45678 \
${strFlag} 'some_string' \
>"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue "use of multple flags returned a non-zero result" ${rtrn}
+ r3turn=$?
+ assertTrue "use of multple flags returned a non-zero result" ${r3turn}
assertTrue 'boolean test failed.' ${FLAGS_bool}
assertNotSame 'float test failed.' 0 ${FLAGS_float}
assertNotSame 'integer test failed.' 0 ${FLAGS_int}
assertNotSame 'string test failed.' '' ${FLAGS_str}
assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
}
_testNonFlagArgs()
@@ -257,9 +265,9 @@ _testNonFlagArgs()
shift
FLAGS "$@" >"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue 'parse returned non-zero value.' ${rtrn}
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ r3turn=$?
+ assertTrue 'parse returned non-zero value.' ${r3turn}
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
eval set -- "${FLAGS_ARGV}"
assertEquals 'wrong count of argv arguments returned.' ${argc} $#
@@ -289,7 +297,7 @@ testFlagsWithEquals()
FLAGS --str='str_flag' 'non_flag' >"${stdoutF}" 2>"${stderrF}"
assertTrue 'FLAGS returned a non-zero result' $?
assertEquals 'string flag not set properly' 'str_flag' "${FLAGS_str}"
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
eval set -- "${FLAGS_ARGV}"
assertEquals 'wrong count of argv arguments returned.' 1 $#
@@ -304,10 +312,10 @@ testComplicatedCommandLineStandard()
# results in the remaining flags being treated as arguments instead.
FLAGS -i 1 non_flag_1 -s 'two' non_flag_2 -f 3 non_flag_3 \
>"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue 'FLAGS returned a non-zero result' ${rtrn}
+ r3turn=$?
+ assertTrue 'FLAGS returned a non-zero result' ${r3turn}
assertEquals 'failed int test' 1 ${FLAGS_int}
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
eval set -- "${FLAGS_ARGV}"
assertEquals 'incorrect number of argv values' 7 $#
@@ -319,12 +327,12 @@ testComplicatedCommandLineEnhanced()
FLAGS -i 1 non_flag_1 --str='two' non_flag_2 --float 3 'non flag 3' \
>"${stdoutF}" 2>"${stderrF}"
- rtrn=$?
- assertTrue 'FLAGS returned a non-zero result' ${rtrn}
+ r3turn=$?
+ assertTrue 'FLAGS returned a non-zero result' ${r3turn}
assertEquals 'failed int test' 1 ${FLAGS_int}
assertEquals 'failed str test' 'two' "${FLAGS_str}"
assertEquals 'failed float test' 3 ${FLAGS_float}
- th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
+ th_showOutput ${r3turn} "${stdoutF}" "${stderrF}"
eval set -- "${FLAGS_ARGV}"
assertEquals 'incorrect number of argv values' 3 $#
diff --git a/source/1.0/src/shflags_test_public.sh b/source/1.0/src/shflags_test_public.sh
index adffb74..3877d80 100755
--- a/source/1.0/src/shflags_test_public.sh
+++ b/source/1.0/src/shflags_test_public.sh
@@ -18,53 +18,51 @@
testHelp()
{
- #
- # test short -h option
- #
+ _testHelp '-h'
+ flags_getoptIsEnh || return
+ _testHelp '--help'
+}
- result=`FLAGS -h 2>&1`
- r3turn=$?
+_testHelp()
+{
+ flag=$1
+
+ # test default help output
+ th_clearReturn
+ (
+ FLAGS ${flag} >"${stdoutF}" 2>"${stderrF}"
+ echo $? >"${returnF}"
+ )
+ th_queryReturn
assertTrue \
'short help request should have returned a true exit code.' \
- ${r3turn}
- echo "${result}" |grep -- 'show this help' >/dev/null
+ ${th_return}
+ grep 'show this help' "${stderrF}" >/dev/null
grepped=$?
assertTrue \
'short request for help should have produced some help output.' \
${grepped}
- [ ${grepped} -ne ${FLAGS_TRUE} ] && echo "${result}" >&2
+ [ ${grepped} -ne ${FLAGS_TRUE} ] && th_showOutput
# test proper output when FLAGS_HELP set
- result=`FLAGS_HELP='this is a test'; FLAGS -h 2>&1`
- echo "${result}" |grep -- 'this is a test' >/dev/null
+ (
+ FLAGS_HELP='this is a test'
+ FLAGS ${flag} >"${stdoutF}" 2>"${stderrF}"
+ )
+ grep 'this is a test' "${stderrF}" >/dev/null
grepped=$?
assertTrue 'setting FLAGS_HELP did not produce expected result' ${grepped}
- [ ${grepped} -ne ${FLAGS_TRUE} ] && echo "${result}" >&2
+ [ ${grepped} -ne ${FLAGS_TRUE} ] && th_showOutput
# test that "'" chars work in help string
- DEFINE_boolean b false "help string containing a ' char" b
- result=`FLAGS -h 2>&1`
- echo "${result}" |grep -- "help string containing a ' char" >/dev/null
+ (
+ DEFINE_boolean b false "help string containing a ' char" b
+ FLAGS ${flag} >"${stdoutF}" 2>"${stderrF}"
+ )
+ grep "help string containing a ' char" "${stderrF}" >/dev/null
grepped=$?
assertTrue "help strings containing apostrophes don't work" ${grepped}
- [ ${grepped} -ne ${FLAGS_TRUE} ] && echo "${result}" >&2
-
- #
- # test long --help option
- #
-
- flags_getoptIsEnh || startSkipping
-
- result=`FLAGS --help 2>&1`
- r3turn=$?
- assertTrue \
- 'long help request should have returned a true exit code' \
- ${r3turn}
- echo "${result}" |grep -- 'show this help' >/dev/null
- grepped=$?
- assertTrue \
- 'long help request should have produced some help output.' \
- ${grepped}
+ [ ${grepped} -ne ${FLAGS_TRUE} ] && th_showOutput
}
mock_flags_columns()
@@ -99,7 +97,7 @@ flags:
-h show this help (default: false)
EOF
(
- _flags_columns() { mock_flags_columns "\$@"; }
+ _flags_columns() { mock_flags_columns; }
FLAGS_HELP=${help};
FLAGS -h >"${stdoutF}" 2>"${stderrF}"
)
@@ -139,7 +137,7 @@ flags:
-h,--help: show this help (default: false)
EOF
(
- _flags_columns() { mock_flags_columns "\$@"; }
+ _flags_columns() { mock_flags_columns; }
FLAGS_HELP=${help};
FLAGS -h >"${stdoutF}" 2>"${stderrF}"
)