From 17c8bab4445917564c441bba082a0346ccef07ba Mon Sep 17 00:00:00 2001 From: deajan Date: Thu, 2 Jul 2015 17:46:41 +0200 Subject: [PATCH] Updated shunit2 to 2.1.7pre --- tests/run.sh | 2 + tests/shunit2/shunit2 | 59 ++++++++++++++++-------- tests/shunit2/shunit2_test.sh | 2 +- tests/shunit2/shunit2_test_asserts.sh | 7 +-- tests/shunit2/shunit2_test_failures.sh | 7 +-- tests/shunit2/shunit2_test_helpers | 54 +++++++++++++++++++++- tests/shunit2/shunit2_test_macros.sh | 7 +-- tests/shunit2/shunit2_test_misc.sh | 13 ++---- tests/shunit2/shunit2_test_standalone.sh | 2 +- 9 files changed, 106 insertions(+), 47 deletions(-) diff --git a/tests/run.sh b/tests/run.sh index 4f77c80..e459c58 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +TEST_BUILD=2015070201 + cd -P -- "$(dirname -- "$0")" OSYNC_EXECUTABLE=$(readlink -e ../osync.sh) declare -A sandbox_osync diff --git a/tests/shunit2/shunit2 b/tests/shunit2/shunit2 index 8862ffd..d6e7503 100755 --- a/tests/shunit2/shunit2 +++ b/tests/shunit2/shunit2 @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2 335 2011-05-01 20:10:33Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. @@ -15,20 +15,31 @@ # return if shunit already loaded [ -n "${SHUNIT_VERSION:-}" ] && exit 0 +SHUNIT_VERSION='2.1.7pre' -SHUNIT_VERSION='2.1.6' - +# return values that scripts can use SHUNIT_TRUE=0 SHUNIT_FALSE=1 SHUNIT_ERROR=2 -# enable strict mode by default -SHUNIT_STRICT=${SHUNIT_STRICT:-${SHUNIT_TRUE}} - +# logging functions _shunit_warn() { echo "shunit2:WARN $@" >&2; } _shunit_error() { echo "shunit2:ERROR $@" >&2; } _shunit_fatal() { echo "shunit2:FATAL $@" >&2; exit ${SHUNIT_ERROR}; } +# determine some reasonable command defaults +__SHUNIT_UNAME_S=`uname -s` +case "${__SHUNIT_UNAME_S}" in + BSD) __SHUNIT_EXPR_CMD='gexpr' ;; + *) __SHUNIT_EXPR_CMD='expr' ;; +esac + +# commands a user can override if needed +SHUNIT_EXPR_CMD=${SHUNIT_EXPR_CMD:-${__SHUNIT_EXPR_CMD}} + +# enable strict mode by default +SHUNIT_STRICT=${SHUNIT_STRICT:-${SHUNIT_TRUE}} + # specific shell checks if [ -n "${ZSH_VERSION:-}" ]; then setopt |grep "^shwordsplit$" >/dev/null @@ -51,19 +62,24 @@ __SHUNIT_MODE_STANDALONE='standalone' __SHUNIT_PARENT=${SHUNIT_PARENT:-$0} # set the constants readonly -shunit_constants_=`set |grep '^__SHUNIT_' |cut -d= -f1` -echo "${shunit_constants_}" |grep '^Binary file' >/dev/null && \ - shunit_constants_=`set |grep -a '^__SHUNIT_' |cut -d= -f1` -for shunit_constant_ in ${shunit_constants_}; do - shunit_ro_opts_='' - case ${ZSH_VERSION:-} in - '') ;; # this isn't zsh - [123].*) ;; # early versions (1.x, 2.x, 3.x) - *) shunit_ro_opts_='-g' ;; # all later versions. declare readonly globally - esac - readonly ${shunit_ro_opts_} ${shunit_constant_} +__shunit_constants=`set |grep '^__SHUNIT_' |cut -d= -f1` +echo "${__shunit_constants}" |grep '^Binary file' >/dev/null && \ + __shunit_constants=`set |grep -a '^__SHUNIT_' |cut -d= -f1` +for __shunit_const in ${__shunit_constants}; do + if [ -z "${ZSH_VERSION:-}" ]; then + readonly ${__shunit_const} + else + case ${ZSH_VERSION} in + [123].*) readonly ${__shunit_const} ;; + *) readonly -g ${__shunit_const} # declare readonly constants globally + esac + fi done -unset shunit_constant_ shunit_constants_ shunit_ro_opts_ +unset __shunit_const __shunit_constants + +# +# internal variables +# # variables __shunit_lineno='' # line number of executed test @@ -88,6 +104,9 @@ __shunit_assertsSkipped=0 # macros _SHUNIT_LINENO_='eval __shunit_lineno=""; if [ "${1:-}" = "--lineno" ]; then [ -n "$2" ] && __shunit_lineno="[$2] "; shift 2; fi' +#----------------------------------------------------------------------------- +# private functions + #----------------------------------------------------------------------------- # assert functions # @@ -313,8 +332,8 @@ _ASSERT_NOT_SAME_='eval assertNotSame --lineno "${LINENO:-}"' assertTrue() { ${_SHUNIT_LINENO_} - if [ $# -gt 2 ]; then - _shunit_error "assertTrue() takes one two arguments; $# given" + if [ $# -lt 1 -o $# -gt 2 ]; then + _shunit_error "assertTrue() takes one or two arguments; $# given" return ${SHUNIT_ERROR} fi _shunit_shouldSkip && return ${SHUNIT_TRUE} diff --git a/tests/shunit2/shunit2_test.sh b/tests/shunit2/shunit2_test.sh index f5a0ff8..d8f5a9c 100755 --- a/tests/shunit2/shunit2_test.sh +++ b/tests/shunit2/shunit2_test.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2_test.sh 322 2011-04-24 00:09:45Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. diff --git a/tests/shunit2/shunit2_test_asserts.sh b/tests/shunit2/shunit2_test_asserts.sh index 1f8040d..38647ec 100755 --- a/tests/shunit2/shunit2_test_asserts.sh +++ b/tests/shunit2/shunit2_test_asserts.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2_test_asserts.sh 312 2011-03-14 22:41:29Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. @@ -196,10 +196,7 @@ testAssertFalse() oneTimeSetUp() { - tmpDir="${__shunit_tmpDir}/output" - mkdir "${tmpDir}" - stdoutF="${tmpDir}/stdout" - stderrF="${tmpDir}/stderr" + th_oneTimeSetUp MSG='This is a test message' } diff --git a/tests/shunit2/shunit2_test_failures.sh b/tests/shunit2/shunit2_test_failures.sh index 4aec943..933a0b1 100755 --- a/tests/shunit2/shunit2_test_failures.sh +++ b/tests/shunit2/shunit2_test_failures.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2_test_failures.sh 286 2008-11-24 21:42:34Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. @@ -76,10 +76,7 @@ testFailSame() oneTimeSetUp() { - tmpDir="${__shunit_tmpDir}/output" - mkdir "${tmpDir}" - stdoutF="${tmpDir}/stdout" - stderrF="${tmpDir}/stderr" + th_oneTimeSetUp MSG='This is a test message' } diff --git a/tests/shunit2/shunit2_test_helpers b/tests/shunit2/shunit2_test_helpers index 82a0eef..a9989d6 100644 --- a/tests/shunit2/shunit2_test_helpers +++ b/tests/shunit2/shunit2_test_helpers @@ -1,4 +1,4 @@ -# $Id: shunit2_test_helpers 286 2008-11-24 21:42:34Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. @@ -52,6 +52,15 @@ th_fatal() { echo "${MY_NAME}:FATAL $@" >&2; } # output subtest name th_subtest() { echo " $@" >&2; } +th_oneTimeSetUp() +{ + # these files will be cleaned up automatically by shUnit2 + stdoutF="${SHUNIT_TMPDIR}/stdout" + stderrF="${SHUNIT_TMPDIR}/stderr" + returnF="${SHUNIT_TMPDIR}/return" + expectedF="${SHUNIT_TMPDIR}/expected" +} + # generate a random number th_generateRandom() { @@ -141,6 +150,8 @@ th_assertFalseWithOutput() "[ -s '${th_stdout_}' ]" assertFalse "${th_test_}; expected no output to STDERR" \ "[ -s '${th_stderr_}' ]" + [ -s "${th_stdout_}" -a ! -s "${th_stderr_}" ] || \ + _th_showOutput ${SHUNIT_FALSE} "${th_stdout_}" "${th_stderr_}" unset th_test_ th_rtrn_ th_stdout_ th_stderr_ } @@ -165,10 +176,51 @@ th_assertFalseWithError() "[ -s '${th_stdout_}' ]" assertTrue "${th_test_}; expected output to STDERR" \ "[ -s '${th_stderr_}' ]" + [ ! -s "${th_stdout_}" -a -s "${th_stderr_}" ] || \ + _th_showOutput ${SHUNIT_FALSE} "${th_stdout_}" "${th_stderr_}" unset th_test_ 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 +} + +# Providing external and internal calls to the showOutput helper function. +th_showOutput() { _th_showOutput $@; } +_th_showOutput() +{ + _th_return_=$1 + _th_stdout_=$2 + _th_stderr_=$3 + + isSkipping + if [ $? -eq ${SHUNIT_FALSE} -a ${_th_return_} != ${SHUNIT_TRUE} ]; then + if [ -n "${_th_stdout_}" -a -s "${_th_stdout_}" ]; then + echo '>>> STDOUT' >&2 + cat "${_th_stdout_}" >&2 + fi + if [ -n "${_th_stderr_}" -a -s "${_th_stderr_}" ]; then + echo '>>> STDERR' >&2 + cat "${_th_stderr_}" >&2 + fi + if [ -n "${_th_stdout_}" -o -n "${_th_stderr_}" ]; then + echo '<<< end output' >&2 + fi + fi + + unset _th_return_ _th_stdout_ _th_stderr_ +} + # # main # diff --git a/tests/shunit2/shunit2_test_macros.sh b/tests/shunit2/shunit2_test_macros.sh index 94fdbed..ce57b14 100755 --- a/tests/shunit2/shunit2_test_macros.sh +++ b/tests/shunit2/shunit2_test_macros.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2_test_macros.sh 299 2010-05-03 12:44:20Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. @@ -238,10 +238,7 @@ testFailNotSame() oneTimeSetUp() { - tmpDir="${__shunit_tmpDir}/output" - mkdir "${tmpDir}" - stdoutF="${tmpDir}/stdout" - stderrF="${tmpDir}/stderr" + th_oneTimeSetUp } # load and run shUnit2 diff --git a/tests/shunit2/shunit2_test_misc.sh b/tests/shunit2/shunit2_test_misc.sh index e3be229..d264628 100755 --- a/tests/shunit2/shunit2_test_misc.sh +++ b/tests/shunit2/shunit2_test_misc.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2_test_misc.sh 322 2011-04-24 00:09:45Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2008 Kate Ward. All Rights Reserved. @@ -20,6 +20,7 @@ # incorrectly interpret the embedded functions as real functions. testUnboundVariable() { + unittestF="${SHUNIT_TMPDIR}/unittest" sed 's/^#//' >"${unittestF}" <"${f}" #testABC() { echo 'ABC'; } #test_def() { @@ -147,17 +148,11 @@ setUp() for f in ${expectedF} ${stdoutF} ${stderrF}; do cp /dev/null ${f} done - rm -fr "${tmpD}" - mkdir "${tmpD}" } oneTimeSetUp() { - tmpD="${SHUNIT_TMPDIR}/tmp" - expectedF="${SHUNIT_TMPDIR}/expected" - stdoutF="${SHUNIT_TMPDIR}/stdout" - stderrF="${SHUNIT_TMPDIR}/stderr" - unittestF="${SHUNIT_TMPDIR}/unittest" + th_oneTimeSetUp } # load and run shUnit2 diff --git a/tests/shunit2/shunit2_test_standalone.sh b/tests/shunit2/shunit2_test_standalone.sh index 6df64b3..2ac4725 100755 --- a/tests/shunit2/shunit2_test_standalone.sh +++ b/tests/shunit2/shunit2_test_standalone.sh @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: shunit2_test_standalone.sh 303 2010-05-03 13:11:27Z kate.ward@forestent.com $ +# $Id$ # vim:et:ft=sh:sts=2:sw=2 # # Copyright 2010 Kate Ward. All Rights Reserved.