diff options
author | kate.ward <kate.ward@forestent.com> | 2010-03-18 00:25:34 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2010-03-18 00:25:34 +0000 |
commit | 9a183b8fa2dbe49701f1a26bbca812aa823c0422 (patch) | |
tree | 6688cb23dd768dbd90f32f4432793eaf916b3d0a | |
parent | c12b30cebb92b49c5edb6df255c0952c65b4ddc6 (diff) | |
download | shflags-9a183b8fa2dbe49701f1a26bbca812aa823c0422.tar.gz |
fixed expn usage bug under FreeBSD 7.2
-rw-r--r-- | source/1.0/doc/CHANGES-1.0.txt | 7 | ||||
-rw-r--r-- | source/1.0/lib/shunit2 | 711 | ||||
-rw-r--r-- | source/1.0/src/shflags | 22 |
3 files changed, 284 insertions, 456 deletions
diff --git a/source/1.0/doc/CHANGES-1.0.txt b/source/1.0/doc/CHANGES-1.0.txt index f2e6d35..0ec3471 100644 --- a/source/1.0/doc/CHANGES-1.0.txt +++ b/source/1.0/doc/CHANGES-1.0.txt @@ -1,6 +1,13 @@ Changes in shFlags 1.0.x ======================== +Changes with 1.0.4 +------------------ + +Fixed usage of ``expn`` under FreeBSD 7.2 (FreeNAS 0.7.1) that was causing many +unit tests to fail. + + Changes with 1.0.3 ------------------ diff --git a/source/1.0/lib/shunit2 b/source/1.0/lib/shunit2 index d900a70..68f6e19 100644 --- a/source/1.0/lib/shunit2 +++ b/source/1.0/lib/shunit2 @@ -1,24 +1,18 @@ -# $Id: shunit2 277 2008-10-29 21:20:22Z kate.ward@forestent.com $ +# $Id: shunit2 296 2010-03-17 23:49:03Z kate.ward@forestent.com $ # vim:et:ft=sh:sts=2:sw=2 -# vim:foldmethod=marker:foldmarker=/**,*/ # -#/** -# <?xml version="1.0" encoding="UTF-8"?> -# <s:shelldoc xmlns:s="http://www.forestent.com/projects/shelldoc/xsl/2005.0"> -# <s:header> -# shUnit 2.1.5 -# Shell Unit Test Framework +# Copyright 2008 Kate Ward. All Rights Reserved. +# Released under the LGPL (GNU Lesser General Public License) # -# http://shunit2.googlecode.com/ +# shUnit2 -- Unit testing framework for Unix shell scripts. +# http://code.google.com/p/shunit2/ # -# written by Kate Ward <kate.ward@forestent.com> -# released under the LGPL +# Author: kate.ward@forestent.com (Kate Ward) # -# This module implements a xUnit based unit test framework similar to JUnit. -# </s:header> -#*/ +# shUnit2 is a xUnit based unit test framework for Bourne shell scripts. It is +# based on the popular JUnit unit testing framework for Java. -SHUNIT_VERSION='2.1.5' +SHUNIT_VERSION='2.1.6pre' SHUNIT_TRUE=0 SHUNIT_FALSE=1 @@ -90,26 +84,14 @@ _SHUNIT_LINENO_='eval __shunit_lineno=""; if [ "${1:-}" = "--lineno" ]; then [ - # assert functions # -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertEquals</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>expected</parameter></paramdef> -# <paramdef>string <parameter>actual</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that <emphasis>expected</emphasis> and -# <emphasis>actual</emphasis> are equal to one another. The message is -# optional.</para> -# </entry> -# </s:function> -#*/ +# Assert that two values are equal to one another. +# +# Args: +# message: string: failure message [optional] +# expected: string: expected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertEquals() { ${_SHUNIT_LINENO_} @@ -141,26 +123,14 @@ assertEquals() } _ASSERT_EQUALS_='eval assertEquals --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertNotEquals</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>unexpected</parameter></paramdef> -# <paramdef>string <parameter>actual</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that <emphasis>unexpected</emphasis> and -# <emphasis>actual</emphasis> are <emphasis role="strong">not</emphasis> -# equal to one another. The message is optional.</para> -# </entry> -# </s:function> -#*/ +# Assert that two values are not equal to one another. +# +# Args: +# message: string: failure message [optional] +# expected: string: expected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertNotEquals() { ${_SHUNIT_LINENO_} @@ -191,24 +161,13 @@ assertNotEquals() } _ASSERT_NOT_EQUALS_='eval assertNotEquals --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertNull</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>value</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that <emphasis>value</emphasis> is <literal>null</literal>, -# or in shell terms a zero-length string. The message is optional.</para> -# </entry> -# </s:function> -#*/ +# Assert that a value is null (i.e. an empty string) +# +# Args: +# message: string: failure message [optional] +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertNull() { ${_SHUNIT_LINENO_} @@ -231,25 +190,13 @@ assertNull() } _ASSERT_NULL_='eval assertNull --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertNotNull</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>value</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that <emphasis>value</emphasis> is <emphasis -# role="strong">not</emphasis> <literal>null</literal>, or in shell terms not -# a zero-length string. The message is optional.</para> -# </entry> -# </s:function> -#*/ +# Assert that a value is not null (i.e. a non-empty string) +# +# Args: +# message: string: failure message [optional] +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertNotNull() { ${_SHUNIT_LINENO_} @@ -272,25 +219,14 @@ assertNotNull() } _ASSERT_NOT_NULL_='eval assertNotNull --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertSame</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>expected</parameter></paramdef> -# <paramdef>string <parameter>actual</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>This function is functionally equivalent to -# <function>assertEquals</function>.</para> -# </entry> -# </s:function> -#*/ +# Assert that two values are the same (i.e. equal to one another). +# +# Args: +# message: string: failure message [optional] +# expected: string: expected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertSame() { ${_SHUNIT_LINENO_} @@ -313,26 +249,14 @@ assertSame() } _ASSERT_SAME_='eval assertSame --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertNotSame</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>unexpected</parameter></paramdef> -# <paramdef>string <parameter>actual</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that <emphasis>unexpected</emphasis> and -# <emphasis>actual</emphasis> are <emphasis role="strong">not</emphasis> -# equal to one another. The message is optional.</para> -# </entry> -# </s:function> -#*/ +# Assert that two values are not the same (i.e. not equal to one another). +# +# Args: +# message: string: failure message [optional] +# expected: string: expected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertNotSame() { ${_SHUNIT_LINENO_} @@ -355,33 +279,27 @@ assertNotSame() } _ASSERT_NOT_SAME_='eval assertNotSame --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertTrue</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>condition</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that a given shell test condition is true. The message is -# optional.</para> -# <para>Testing whether something is true or false is easy enough by using -# the assertEquals/assertNotSame functions. Shell supports much more -# complicated tests though, and a means to support them was needed. As such, -# this function tests that conditions are true or false through evaluation -# rather than just looking for a true or false.</para> -# <funcsynopsis> -# The following test will succeed: <funcsynopsisinfo>assertTrue "[ 34 -gt 23 ]"</funcsynopsisinfo> -# The folloing test will fail with a message: <funcsynopsisinfo>assertTrue "test failed" "[ -r '/non/existant/file' ]"</funcsynopsisinfo> -# </funcsynopsis> -# </entry> -# </s:function> -#*/ +# Assert that a value or shell test condition is true. +# +# In shell, a value of 0 is true and a non-zero value is false. Any integer +# value passed can thereby be tested. +# +# Shell supports much more complicated tests though, and a means to support +# them was needed. As such, this function tests that conditions are true or +# false through evaluation rather than just looking for a true or false. +# +# The following test will succeed: +# assertTrue 0 +# assertTrue "[ 34 -gt 23 ]" +# The folloing test will fail with a message: +# assertTrue 123 +# assertTrue "test failed" "[ -r '/non/existant/file' ]" +# +# Args: +# message: string: failure message [optional] +# condition: string: integer value or shell conditional statement +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertTrue() { ${_SHUNIT_LINENO_} @@ -425,33 +343,27 @@ assertTrue() } _ASSERT_TRUE_='eval assertTrue --lineno "${LINENO:-}"' -#/** -# <s:function group="asserts"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>assertFalse</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>condition</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Asserts that a given shell test condition is false. The message is -# optional.</para> -# <para>Testing whether something is true or false is easy enough by using -# the assertEquals/assertNotSame functions. Shell supports much more -# complicated tests though, and a means to support them was needed. As such, -# this function tests that conditions are true or false through evaluation -# rather than just looking for a true or false.</para> -# <funcsynopsis> -# The following test will succeed: <funcsynopsisinfo>assertFalse "[ 'apples' = 'oranges' ]"</funcsynopsisinfo> -# The folloing test will fail with a message: <funcsynopsisinfo>assertFalse "test failed" "[ 1 -eq 1 -a 2 -eq 2 ]"</funcsynopsisinfo> -# </funcsynopsis> -# </entry> -# </s:function> -#*/ +# Assert that a value or shell test condition is false. +# +# In shell, a value of 0 is true and a non-zero value is false. Any integer +# value passed can thereby be tested. +# +# Shell supports much more complicated tests though, and a means to support +# them was needed. As such, this function tests that conditions are true or +# false through evaluation rather than just looking for a true or false. +# +# The following test will succeed: +# assertFalse 1 +# assertFalse "[ 'apples' = 'oranges' ]" +# The folloing test will fail with a message: +# assertFalse 0 +# assertFalse "test failed" "[ 1 -eq 1 -a 2 -eq 2 ]" +# +# Args: +# message: string: failure message [optional] +# condition: string: integer value or shell conditional statement +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) assertFalse() { ${_SHUNIT_LINENO_} @@ -499,27 +411,17 @@ _ASSERT_FALSE_='eval assertFalse --lineno "${LINENO:-}"' # failure functions # -#/** -# <s:function group="failures"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>fail</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Fails the test immediately, with the optional message.</para> -# </entry> -# </s:function> -#*/ +# Records a test failure. +# +# Args: +# message: string: failure message [optional] +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) fail() { ${_SHUNIT_LINENO_} if [ $# -gt 1 ]; then - _shunit_error "fail() requires one or two arguments; $# given" + _shunit_error "fail() requires zero or one arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} @@ -537,26 +439,14 @@ fail() } _FAIL_='eval fail --lineno "${LINENO:-}"' -#/** -# <s:function group="failures"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>failNotEquals</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>unexpected</parameter></paramdef> -# <paramdef>string <parameter>actual</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Fails the test if <emphasis>unexpected</emphasis> and -# <emphasis>actual</emphasis> are <emphasis role="strong">not</emphasis> -# equal to one another. The message is optional.</para> -# </entry> -# </s:function> -#*/ +# Records a test failure, stating two values were not equal. +# +# Args: +# message: string: failure message [optional] +# unexpected: string: unexpected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) failNotEquals() { ${_SHUNIT_LINENO_} @@ -581,23 +471,14 @@ failNotEquals() } _FAIL_NOT_EQUALS_='eval failNotEquals --lineno "${LINENO:-}"' -#/** -# <s:function group="failures"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>failSame</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Indicate test failure because arguments were the same. The message is -# optional.</para> -# </entry> -# </s:function> -#*/ +# Records a test failure, stating two values should have been the same. +# +# Args: +# message: string: failure message [optional] +# expected: string: expected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) failSame() { ${_SHUNIT_LINENO_} @@ -620,25 +501,16 @@ failSame() } _FAIL_SAME_='eval failSame --lineno "${LINENO:-}"' -#/** -# <s:function group="failures"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>failNotSame</function></funcdef> -# <paramdef>string <parameter>[message]</parameter></paramdef> -# <paramdef>string <parameter>expected</parameter></paramdef> -# <paramdef>string <parameter>actual</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>Indicate test failure because arguments were not the same. The -# message is optional.</para> -# </entry> -# </s:function> -#*/ +# Records a test failure, stating two values were not equal. +# +# This is functionally equivalent to calling failNotEquals(). +# +# Args: +# message: string: failure message [optional] +# unexpected: string: unexpected value +# actual: string: actual value +# Returns: +# integer: success (TRUE/FALSE/ERROR constant) failNotSame() { ${_SHUNIT_LINENO_} @@ -665,67 +537,34 @@ _FAIL_NOT_SAME_='eval failNotSame --lineno "${LINENO:-}"' # skipping functions # -#/** -# <s:function group="skipping"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>startSkipping</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function forces the remaining assert and fail functions to be -# "skipped", i.e. they will have no effect. Each function skipped will be -# recorded so that the total of asserts and fails will not be altered.</para> -# </entry> -# </s:function> -#*/ +# Force remaining assert and fail functions to be "skipped". +# +# This function forces the remaining assert and fail functions to be "skipped", +# i.e. they will have no effect. Each function skipped will be recorded so that +# the total of asserts and fails will not be altered. +# +# Args: +# None startSkipping() { __shunit_skip=${SHUNIT_TRUE} } -#/** -# <s:function group="skipping"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>endSkipping</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function returns calls to the assert and fail functions to their -# default behavior, i.e. they will be called.</para> -# </entry> -# </s:function> -#*/ +# Resume the normal recording behavior of assert and fail calls. +# +# Args: +# None endSkipping() { __shunit_skip=${SHUNIT_FALSE} } -#/** -# <s:function group="skipping"> -# <entry align="right"> -# <emphasis>boolean</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>isSkipping</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function returns the state of skipping.</para> -# </entry> -# </s:function> -#*/ +# Returns the state of assert and fail call skipping. +# +# Args: +# None +# Returns: +# boolean: (TRUE/FALSE constant) isSkipping() { return ${__shunit_skip} @@ -735,49 +574,30 @@ isSkipping() # suite functions # -#/** -# <s:function group="suites"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>suite</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function can be optionally overridden by the user in their test -# suite.</para> -# <para>If this function exists, it will be called when -# <command>shunit2</command> is sourced. If it does not exist, shUnit2 will -# search the parent script for all functions beginning with the word -# <literal>test</literal>, and they will be added dynamically to the test -# suite.</para> -# </entry> -# </s:function> -#*/ +# Stub. This function should contains all unit test calls to be made. +# +# DEPRECATED (as of 2.1.0) +# +# This function can be optionally overridden by the user in their test suite. +# +# If this function exists, it will be called when shunit2 is sourced. If it +# does not exist, shunit2 will search the parent script for all functions +# beginning with the word 'test', and they will be added dynamically to the +# test suite. +# +# This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation -# suite() { :; } - -#/** -# <s:function group="suites"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>suite_addTest</function></funcdef> -# <paramdef>string <parameter>function</parameter></paramdef> -# </funcprototype> -# </funcsynopsis> -# <para>This function adds a function name to the list of tests scheduled for -# execution as part of this test suite. This function should only be called -# from within the <function>suite()</function> function.</para> -# </entry> -# </s:function> -#*/ +# +# Args: +# None +#suite() { :; } # DO NOT UNCOMMENT THIS FUNCTION + +# Adds a function name to the list of tests schedule for execution. +# +# This function should only be called from within the suite() function. +# +# Args: +# function: string: name of a function to add to current unit test suite suite_addTest() { shunit_func_=${1:-} @@ -788,108 +608,75 @@ suite_addTest() unset shunit_func_ } -#/** -# <s:function group="suites"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>oneTimeSetUp</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function can be be optionally overridden by the user in their -# test suite.</para> -# <para>If this function exists, it will be called once before any tests are -# run. It is useful to prepare a common environment for all tests.</para> -# </entry> -# </s:function> -#*/ +# Stub. This function will be called once before any tests are run. +# +# Common one-time environment preparation tasks shared by all tests can be +# defined here. +# +# This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation -# oneTimeSetUp() { :; } - -#/** -# <s:function group="suites"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>oneTimeTearDown</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function can be be optionally overridden by the user in their -# test suite.</para> -# <para>If this function exists, it will be called once after all tests are -# completed. It is useful to clean up the environment after all tests.</para> -# </entry> -# </s:function> -#*/ +# +# Args: +# None +#oneTimeSetUp() { :; } # DO NOT UNCOMMENT THIS FUNCTION + +# Stub. This function will be called once after all tests are finished. +# +# Common one-time environment cleanup tasks shared by all tests can be defined +# here. +# +# This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation -# oneTimeTearDown() { :; } - -#/** -# <s:function group="suites"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>setUp</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function can be be optionally overridden by the user in their -# test suite.</para> -# <para>If this function exists, it will be called before each test is run. -# It is useful to reset the environment before each test.</para> -# </entry> -# </s:function> -#*/ +# +# Args: +# None +#oneTimeTearDown() { :; } # DO NOT UNCOMMENT THIS FUNCTION + +# Stub. This function will be called before each test is run. +# +# Common environment preparation tasks shared by all tests can be defined here. +# +# This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation -# setUp() { :; } - -#/** -# <s:function group="suites"> -# <entry align="right"> -# <emphasis>void</emphasis> -# </entry> -# <entry> -# <funcsynopsis> -# <funcprototype> -# <funcdef><function>tearDown</function></funcdef> -# <paramdef /> -# </funcprototype> -# </funcsynopsis> -# <para>This function can be be optionally overridden by the user in their -# test suite.</para> -# <para>If this function exists, it will be called after each test completes. -# It is useful to clean up the environment after each test.</para> -# </entry> -# </s:function> -#*/ +# +# Args: +# None +#setUp() { :; } + +# Note: see _shunit_mktempFunc() for actual implementation +# Stub. This function will be called after each test is run. +# +# Common environment cleanup tasks shared by all tests can be defined here. +# +# This function should be overridden by the user in their unit test suite. # Note: see _shunit_mktempFunc() for actual implementation -# tearDown() { :; } +# +# Args: +# None +#tearDown() { :; } # DO NOT UNCOMMENT THIS FUNCTION #------------------------------------------------------------------------------ # internal shUnit2 functions # -# this function is a cross-platform temporary directory creation tool. not all +# Create a temporary directory to store various run-time files in. +# +# This function is a cross-platform temporary directory creation tool. Not all # OSes have the mktemp function, so one is included here. +# +# Args: +# None +# Outputs: +# string: the temporary directory that was created _shunit_mktempDir() { # try the standard mktemp function ( exec mktemp -dqt shunit.XXXXXX 2>/dev/null ) && return # the standard mktemp didn't work. doing our own. - if [ -r '/dev/urandom' ]; then - _shunit_random_=`od -vAn -N4 -tx4 </dev/urandom |sed 's/^[^0-9a-f]*//'` + if [ -r '/dev/urandom' -a -x '/usr/bin/od' ]; then + _shunit_random_=`/usr/bin/od -vAn -N4 -tx4 </dev/urandom \ + |sed 's/^[^0-9a-f]*//'` elif [ -n "${RANDOM:-}" ]; then # $RANDOM works _shunit_random_=${RANDOM}${RANDOM}${RANDOM}$$ @@ -902,14 +689,17 @@ _shunit_mktempDir() _shunit_tmpDir_="${TMPDIR:-/tmp}/shunit.${_shunit_random_}" ( umask 077 && mkdir "${_shunit_tmpDir_}" ) || { _shunit_fatal 'could not create temporary directory! exiting' - exit ${SHUNIT_FALSE} + return ${SHUNIT_ERROR} } echo ${_shunit_tmpDir_} unset _shunit_date_ _shunit_random_ _shunit_tmpDir_ } -# this function is here to work around issues in Cygwin +# This function is here to work around issues in Cygwin +# +# Args: +# None _shunit_mktempFunc() { for _shunit_func_ in oneTimeSetUp oneTimeTearDown setUp tearDown suite; do @@ -924,6 +714,14 @@ EOF unset _shunit_file_ } +# Final cleanup function to leave things as we found them. +# +# Besides removing the temporary directory, this function is in charge of the +# final exit code of the unit test. The exit code is based on how the script +# was ended (e.g. normal exit, or via Ctrl-C). +# +# Args: +# name: string: name of the trap called (specified when trap defined) _shunit_cleanup() { _shunit_name_=$1 @@ -958,6 +756,9 @@ _shunit_cleanup() } # The actual running of the tests happens here. +# +# Args: +# None _shunit_execSuite() { for _shunit_test_ in ${__shunit_suite}; do @@ -987,8 +788,12 @@ _shunit_execSuite() unset _shunit_test_ } -# This function exits shUnit2 with the appropriate error code and OK/FAILED -# message. +# Generates the user friendly report with appropriate OK/FAILED message. +# +# Args: +# None +# Output: +# string: the report of successful and failed tests, as well as totals. _shunit_generateReport() { _shunit_ok_=${SHUNIT_TRUE} @@ -1030,18 +835,32 @@ _shunit_generateReport() unset _shunit_failures_ _shunit_msg_ _shunit_ok_ _shunit_skipped_ } +# Test for whether a function should be skipped. +# +# Args: +# None +# Returns: +# boolean: whether the test should be skipped (TRUE/FALSE constant) _shunit_shouldSkip() { [ ${__shunit_skip} -eq ${SHUNIT_FALSE} ] && return ${SHUNIT_FALSE} _shunit_assertSkip } +# Records a successful test. +# +# Args: +# None _shunit_assertPass() { __shunit_assertsPassed=`expr ${__shunit_assertsPassed} + 1` __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1` } +# Records a test failure. +# +# Args: +# message: string: failure message to provide user _shunit_assertFail() { _shunit_msg_=$1 @@ -1054,6 +873,10 @@ _shunit_assertFail() unset _shunit_msg_ } +# Records a skipped test. +# +# Args: +# None _shunit_assertSkip() { __shunit_assertsSkipped=`expr ${__shunit_assertsSkipped} + 1` @@ -1065,7 +888,7 @@ _shunit_assertSkip() # # create a temporary storage location -__shunit_tmpDir=`_shunit_mktempDir` +__shunit_tmpDir=`_shunit_mktempDir` || exit ${SHUNIT_ERROR} # provide a public temporary directory for unit test scripts # TODO(kward): document this @@ -1110,7 +933,3 @@ _shunit_generateReport # that's it folks [ ${__shunit_testsFailed} -eq 0 ] exit $? - -#/** -# </s:shelldoc> -#*/ diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags index f69928e..aaea760 100644 --- a/source/1.0/src/shflags +++ b/source/1.0/src/shflags @@ -78,7 +78,7 @@ # return if FLAGS already loaded [ -n "${FLAGS_VERSION:-}" ] && return 0 -FLAGS_VERSION='1.0.3' +FLAGS_VERSION='1.0.4pre' # return values FLAGS_TRUE=0 @@ -508,10 +508,12 @@ _flags_validateFloat() flags_return=${FLAGS_TRUE} case ${_flags_float_} in -*) # negative floats - _flags_test_=`expr "${_flags_float_}" : '\(-[0-9][0-9]*\.[0-9][0-9]*\)'` + _flags_test_=`expr -- "${_flags_float_}" :\ + '\(-[0-9][0-9]*\.[0-9][0-9]*\)'` ;; *) # positive floats - _flags_test_=`expr "${_flags_float_}" : '\([0-9][0-9]*\.[0-9][0-9]*\)'` + _flags_test_=`expr -- "${_flags_float_}" :\ + '\([0-9][0-9]*\.[0-9][0-9]*\)'` ;; esac [ "${_flags_test_}" != "${_flags_float_}" ] && flags_return=${FLAGS_FALSE} @@ -534,10 +536,10 @@ _flags_validateInteger() flags_return=${FLAGS_TRUE} case ${_flags_int_} in -*) # negative ints - _flags_test_=`expr "${_flags_int_}" : '\(-[0-9][0-9]*\)'` + _flags_test_=`expr -- "${_flags_int_}" : '\(-[0-9][0-9]*\)'` ;; *) # positive ints - _flags_test_=`expr "${_flags_int_}" : '\([0-9][0-9]*\)'` + _flags_test_=`expr -- "${_flags_int_}" : '\([0-9][0-9]*\)'` ;; esac [ "${_flags_test_}" != "${_flags_int_}" ] && flags_return=${FLAGS_FALSE} @@ -661,14 +663,14 @@ _flags_parseGetopt() --) shift; break ;; # discontinue option parsing --*) # long option - _flags_opt_=`expr "${_flags_opt_}" : '--\(.*\)'` + _flags_opt_=`expr -- "${_flags_opt_}" : '--\(.*\)'` _flags_len_=${__FLAGS_LEN_LONG} if _flags_itemInList "${_flags_opt_}" ${__flags_longNames}; then _flags_name_=${_flags_opt_} else # check for negated long boolean version if _flags_itemInList "${_flags_opt_}" ${__flags_boolNames}; then - _flags_name_=`expr "${_flags_opt_}" : 'no\(.*\)'` + _flags_name_=`expr -- "${_flags_opt_}" : 'no\(.*\)'` _flags_type_=${__FLAGS_TYPE_BOOLEAN} _flags_arg_=${__FLAGS_NULL} fi @@ -676,7 +678,7 @@ _flags_parseGetopt() ;; -*) # short option - _flags_opt_=`expr "${_flags_opt_}" : '-\(.*\)'` + _flags_opt_=`expr -- "${_flags_opt_}" : '-\(.*\)'` _flags_len_=${__FLAGS_LEN_SHORT} if _flags_itemInList "${_flags_opt_}" ${__flags_shortNames}; then # yes. match short name to long name. note purposeful off-by-one @@ -947,7 +949,7 @@ flags_help() flags_defaultStr_="(default: ${flags_defaultStr_})" flags_helpStr_=" ${flags_flagStr_} ${flags_help_} ${flags_defaultStr_}" - flags_helpStrLen_=`expr "${flags_helpStr_}" : '.*'` + flags_helpStrLen_=`expr -- "${flags_helpStr_}" : '.*'` flags_columns_=`_flags_columns` if [ ${flags_helpStrLen_} -lt ${flags_columns_} ]; then echo "${flags_helpStr_}" >&2 @@ -958,7 +960,7 @@ flags_help() flags_emptyStr_="`echo \"x${flags_flagStr_}x\" \ |awk '{printf "%"length($0)-2"s", ""}'`" flags_helpStr_=" ${flags_emptyStr_} ${flags_defaultStr_}" - flags_helpStrLen_=`expr "${flags_helpStr_}" : '.*'` + flags_helpStrLen_=`expr -- "${flags_helpStr_}" : '.*'` if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} \ -o ${flags_helpStrLen_} -lt ${flags_columns_} ]; then # indented to match help string |