Skip to content

Commit

Permalink
fixed some stdandard vs. enhanced testing issues
Browse files Browse the repository at this point in the history
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 committed Apr 1, 2009
1 parent 594410a commit 518af19
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
17 changes: 9 additions & 8 deletions doc/CHANGES-1.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions doc/RELEASE_NOTES-1.0.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand Down
57 changes: 38 additions & 19 deletions src/shflags_test_parsing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# suite tests
#

testStandardGetopt()
testGetopt_Standard()
{
_flags_getoptStandard '-b' >"${stdoutF}" 2>"${stderrF}"
rslt=$?
Expand All @@ -30,7 +30,7 @@ testStandardGetopt()
assertFalse "parsed invalid flag 'x'" $?
}

testEnhancedGetopt()
testGetopt_Enhanced()
{
flags_getoptIsEnh || startSkipping

Expand Down Expand Up @@ -70,7 +70,7 @@ testValidBooleanShort()

testValidBooleanLong()
{
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping

# note: the default value of bool is 'false'

Expand Down Expand Up @@ -102,7 +102,7 @@ testValidBooleanLong()
testValidFloats()
{
_testValidFloats '-f'
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping
_testValidFloats '--float'
}

Expand All @@ -122,7 +122,7 @@ _testValidFloats()
testInvalidFloats()
{
_testInvalidFloats '-f'
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping
_testInvalidFloats '--float'
}

Expand All @@ -140,7 +140,7 @@ _testInvalidFloats()
testValidIntegers()
{
_testValidIntegers '-i'
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping
_testValidIntegers '--int'
}

Expand All @@ -160,7 +160,7 @@ _testValidIntegers()
testInvalidIntegers()
{
_testInvalidIntegers '-i'
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping
_testInvalidIntegers '--int'
}

Expand All @@ -178,7 +178,7 @@ _testInvalidIntegers()
testValidStrings()
{
_testValidStrings '-s'
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping
_testValidStrings '--str'
}

Expand All @@ -203,7 +203,7 @@ _testValidStrings()
testMultipleFlags()
{
_testMultipleFlags '-b' '-i' '-f' '-s'
flags_getoptIsStd && startSkipping
flags_getoptIsEnh || startSkipping
_testMultipleFlags '--bool' '--int' '--float' '--str'
}

Expand Down Expand Up @@ -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} $#
Expand All @@ -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}"
Expand All @@ -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'
}

#------------------------------------------------------------------------------
Expand Down

0 comments on commit 518af19

Please sign in to comment.