Permalink
Browse files

fixed some stdandard vs. enhanced testing issues

git-svn-id: http://shflags.googlecode.com/svn/trunk/source/1.0@112 9d7cb843-df4f-0410-8a79-4785ae5a3405
  • Loading branch information...
kate.ward@forestent.com
kate.ward@forestent.com committed Apr 1, 2009
1 parent 594410a commit 518af1993e8107017a5d09def23414b29db9ed82
Showing with 54 additions and 30 deletions.
  1. +9 −8 doc/CHANGES-1.0.txt
  2. +7 −3 doc/RELEASE_NOTES-1.0.3.txt
  3. +38 −19 src/shflags_test_parsing.sh
View
@@ -4,22 +4,23 @@ Changes in shFlags 1.0.x
Changes with 1.0.3
------------------
-MAJOR CHANGE! FLAGS_ARGC is now obsolete, and is replaced by FLAGS_ARGV.
+MAJOR CHANGE! ``FLAGS_ARGC`` is now obsolete, and is replaced by
+``FLAGS_ARGV``.
Fixed issue# 7 where long flags defined with '=' (e.g. --abc=123) made it
impossible for the user to know how many non-flag command-line arguments were
-available because the value returned by FLAGS_ARGC was wrong. The FLAGS_ARGC
-value is now obsolete, but will be maintained for backwards compatibility. The
-new method of getting the non-flag arguments is by executing 'eval set --
-"${FLAGS_ARGV}"' after the FLAGS command. The arguments will then be available
-using the standard shell $#, $@, $*, $1, etc. variables.
+available because the value returned by ``FLAGS_ARGC`` was wrong. The
+``FLAGS_ARGC`` value is now obsolete, but will be maintained for backwards
+compatibility. The new method of getting the non-flag arguments is by executing
+``eval set -- "${FLAGS_ARGV}"`` after the **FLAGS** call. The arguments will
+then be available using the standard shell $#, $@, $*, $1, etc. variables.
Due to above fix for issue# 7, there is now proper support for mixing flags
with non-flag arguments on the command-line. Previously, all non-flag arguments
had to be at the end of the command-line.
-Renamed _flags_standardGetopt() and _flags_enhancedGetopt() functions to
-_flags_getoptStandard() and _flags_getoptEnhanced().
+Renamed ``_flags_standardGetopt()`` and ``_flags_enhancedGetopt()`` functions to
+``_flags_getoptStandard()`` and ``_flags_getoptEnhanced()``.
Took out the setting and restoration of the '-u' shell flag to treat unset
variables as an error. No point in having it in this library as it is verified
@@ -27,8 +27,11 @@ wrong when flag and non-flag arguments are mixed together on the command-line.
To gain access to the non-flag arguments, replace the following snippet of code
in your scripts with the updated version.
-:old: shift ${FLAGS_ARGC}
-:new: eval set -- "${FLAGS_ARGV}"
+old ::
+ shift ${FLAGS_ARGC}
+
+new ::
+ eval set -- "${FLAGS_ARGV}"
Please see the CHANGES-1.0.txt file for a complete list of changes.
@@ -78,7 +81,8 @@ Known Issues
The **getopt** version provided by default with all versions of Mac OS X (up to
and including 10.5.6) is the standard version. As such, only short flags are
-supported.
+supported. Additionally, the version supplied does not support intermixing flag
+and non-flag arguments on the command-line.
The **getopt** version provided by default with all versions of Solaris (up to
and including Solaris 10 and OpenSolaris) is the standard version. As such,
@@ -19,7 +19,7 @@
# suite tests
#
-testStandardGetopt()
+testGetopt_Standard()
{
_flags_getoptStandard '-b' >"${stdoutF}" 2>"${stderrF}"
rslt=$?
@@ -30,7 +30,7 @@ testStandardGetopt()
assertFalse "parsed invalid flag 'x'" $?
}
-testEnhancedGetopt()
+testGetopt_Enhanced()
{
flags_getoptIsEnh || startSkipping
@@ -70,7 +70,7 @@ testValidBooleanShort()
testValidBooleanLong()
{
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
# note: the default value of bool is 'false'
@@ -102,7 +102,7 @@ testValidBooleanLong()
testValidFloats()
{
_testValidFloats '-f'
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
_testValidFloats '--float'
}
@@ -122,7 +122,7 @@ _testValidFloats()
testInvalidFloats()
{
_testInvalidFloats '-f'
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
_testInvalidFloats '--float'
}
@@ -140,7 +140,7 @@ _testInvalidFloats()
testValidIntegers()
{
_testValidIntegers '-i'
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
_testValidIntegers '--int'
}
@@ -160,7 +160,7 @@ _testValidIntegers()
testInvalidIntegers()
{
_testInvalidIntegers '-i'
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
_testInvalidIntegers '--int'
}
@@ -178,7 +178,7 @@ _testInvalidIntegers()
testValidStrings()
{
_testValidStrings '-s'
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
_testValidStrings '--str'
}
@@ -203,7 +203,7 @@ _testValidStrings()
testMultipleFlags()
{
_testMultipleFlags '-b' '-i' '-f' '-s'
- flags_getoptIsStd && startSkipping
+ flags_getoptIsEnh || startSkipping
_testMultipleFlags '--bool' '--int' '--float' '--str'
}
@@ -235,8 +235,10 @@ _testNonFlagArgs()
argv=$1
shift
- FLAGS "$@"
- assertTrue 'parse returned non-zero value.' $?
+ FLAGS "$@" >"${stdoutF}" 2>"${stderrF}"
+ rtrn=$?
+ assertTrue 'parse returned non-zero value.' ${rtrn}
+ th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
eval set -- "${FLAGS_ARGV}"
assertEquals 'wrong count of argv arguments returned.' ${argv} $#
@@ -260,6 +262,8 @@ testMultipleNonFlagStringArgsWithSpaces()
testFlagsWithEquals()
{
+ flags_getoptIsEnh || startSkipping
+
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}"
@@ -270,17 +274,32 @@ testFlagsWithEquals()
assertEquals 'wrong count of argc arguments returned.' 1 ${FLAGS_ARGC}
}
-testComplicatedCommandLine()
+_testComplicatedCommandLine()
{
- FLAGS -i 1 --str='two' non_flag_1 --float 3 non_flag_two 'non flag 3' \
- >"${stdoutF}" 2>"${stderrF}"
- assertTrue 'FLAGS returned a non-zero result' $?
- assertEquals 1 ${FLAGS_int}
- assertEquals 'two' "${FLAGS_str}"
- assertEquals 3 ${FLAGS_float}
+ FLAGS "$@" >"${stdoutF}" 2>"${stderrF}"
+ rtrn=$?
+ assertTrue 'FLAGS returned a non-zero result' ${rtrn}
+ assertEquals 'failed std int test' 1 ${FLAGS_int}
+ assertEquals 'failed std str test' 'two' "${FLAGS_str}"
+ assertEquals 'failed std float test' 3 ${FLAGS_float}
+ th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
eval set -- "${FLAGS_ARGV}"
- assertEquals $# 3
+ assertEquals 'incorrect number of std argv values' 3 $#
+}
+
+testComplicatedCommandLine_Standard()
+{
+ _testComplicatedCommandLine \
+ -i 1 non_flag_1 -s 'two' non_flag_2 -f 3 non_flag_3
+}
+
+testComplicatedCommandLine_Enhanced()
+{
+ flags_getoptIsEnh || startSkipping
+
+ _testComplicatedCommandLine \
+ -i 1 non_flag_1 --str='two' non_flag_2 --float 3 'non flag 3'
}
#------------------------------------------------------------------------------

0 comments on commit 518af19

Please sign in to comment.