|
From: lacton <la...@us...> - 2008-03-25 22:02:32
|
Update of /cvsroot/shunit/ShUnit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13022 Modified Files: shUnit Log Message: [refactor] Reordering, regrouping and documentation of functions. Index: shUnit =================================================================== RCS file: /cvsroot/shunit/ShUnit/shUnit,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** shUnit 25 Mar 2008 21:49:07 -0000 1.29 --- shUnit 25 Mar 2008 22:02:28 -0000 1.30 *************** *** 9,72 **** # ! # Function Declarations ! ! shuRegTest() { ! strFunction=${1} ! ! SHU_STR_ALL_TESTS="${SHU_STR_ALL_TESTS} ${strFunction}" ! } ! ! shuGetDeclaredFunctions() { ! declarations="`declare -F 2>/dev/null || typeset +f 2>/dev/null`" ! if [ -z "$declarations" ] ! then ! echo "ShUnit did not detect any function. Use the shuRegTest function to register all test functions." >&2 ! fi ! echo "$declarations" | sed 's/declare -f //' | sed 's/^\([^ ]*\)() .*$/\1/' ! } ! shuRunOneTest() { ! strTestToRun=${1} ! SHU_TEST_SUCCEEDED=${SHU_TRUE} ! if type shuSetUp > /dev/null 2>&1 ! then ! shuSetUp ! fi ! if type ${strTestToRun} > /dev/null 2>&1 then ! ${strTestToRun} ! if [ ${SHU_TEST_SUCCEEDED} -eq ${SHU_TRUE} ] ! then ! SHU_TOTAL_NR_SUCCEEDED=`expr $SHU_TOTAL_NR_SUCCEEDED + 1` ! fi ! else SHU_TEST_SUCCEEDED=${SHU_FALSE} ! printf " ERROR: \"%s\" not found.\n" "${strTestToRun}" fi ! if type shuTearDown > /dev/null 2>&1 ! then ! shuTearDown ! fi } ! shuFmtNbrTests() { ! n="${1}" ! if [ ${n} -eq 0 ] ! then ! shuRetFmtNbrTests="No tests" ! elif [ ${n} -eq 1 ] ! then ! shuRetFmtNbrTests="1 test" ! else ! shuRetFmtNbrTests="${n} tests" ! fi } shuStart() { strInitFunction="${1}" --- 9,76 ---- # ! # ! # Global Constants ! # ! SHU_TRUE=0 ! SHU_FALSE=1 ! SHU_ERROR_EXIT_CODE=127 ! # ! # Public Function Declarations ! # ! shuAssert() { ! # Assert that a predicate is true. ! # [ 4 -eq `expr 2 + 2` ] ! # shuAssert 'Two plus two equals four' $? ! strMessage="${1:-}" ! boolResult="${2:-${SHU_FALSE}}" ! if [ ${boolResult} -ne ${SHU_TRUE} ] then ! shuTestFailure "${strMessage}" SHU_TEST_SUCCEEDED=${SHU_FALSE} ! else ! shuTestSuccess fi + } ! shuDeny() { ! # Assert that a predicate is false. ! # [ 5 -eq `expr 2 + 2` ] ! # shuDeny 'Two plus two should not be equal to 5' $? ! strMessage="${1:-}" ! boolResult="${2:-${SHU_TRUE}}" + [ ${boolResult} -ne ${SHU_TRUE} ] + shuAssert "${strMessage}" $? } ! shuRegTest() { ! # If you do not use the automatic detection of test function, you have to ! # register each of them. ! # Suite() { ! # shuRegTest FirstTestFunction ! # shuRegTest SecondTestFunction ! # } ! strFunction=${1} ! ! SHU_STR_ALL_TESTS="${SHU_STR_ALL_TESTS} ${strFunction}" } shuStart() { + # Runs all tests. + # + # If called with no argument, it will try to detect all declared functions + # starting with 'Test'. + # + # If called with a function name as an argument, it will delegate to this + # function the test functions' registration. + # Suite() { + # shuRegTest FirstTestFunction + # shuRegTest SecondTestFunction + # } + # shuStart Suite strInitFunction="${1}" *************** *** 131,165 **** } ! shuRegisterFailedTest() { ! msg="${1}" ! if [ -z "${SHU_STR_FAILED}" ] ! then ! SHU_STR_FAILED="${msg}" ! else ! SHU_STR_FAILED="${SHU_STR_FAILED}^${msg}" ! fi } ! shuAssert() { ! strMessage="${1:-}" ! boolResult="${2:-${SHU_FALSE}}" ! if [ ${boolResult} -ne ${SHU_TRUE} ] then ! shuTestFailure "${strMessage}" ! SHU_TEST_SUCCEEDED=${SHU_FALSE} else ! shuTestSuccess fi } ! shuDeny() { ! strMessage="${1:-}" ! boolResult="${2:-${SHU_TRUE}}" ! [ ${boolResult} -ne ${SHU_TRUE} ] ! shuAssert "${strMessage}" $? } if ! type shuSuiteStart >/dev/null 2>&1 then --- 135,206 ---- } ! # ! # Private Function Declarations ! # ! ! shuGetDeclaredFunctions() { ! declarations="`declare -F 2>/dev/null || typeset +f 2>/dev/null`" ! if [ -z "$declarations" ] ! then ! echo "ShUnit did not detect any function. Use the shuRegTest function to register all test functions." >&2 ! fi ! ! echo "$declarations" | sed 's/declare -f //' | sed 's/^\([^ ]*\)() .*$/\1/' } ! shuRunOneTest() { ! strTestToRun=${1} ! SHU_TEST_SUCCEEDED=${SHU_TRUE} ! if type shuSetUp > /dev/null 2>&1 then ! shuSetUp ! fi ! ! if type ${strTestToRun} > /dev/null 2>&1 ! then ! ${strTestToRun} ! if [ ${SHU_TEST_SUCCEEDED} -eq ${SHU_TRUE} ] ! then ! SHU_TOTAL_NR_SUCCEEDED=`expr $SHU_TOTAL_NR_SUCCEEDED + 1` ! fi else ! SHU_TEST_SUCCEEDED=${SHU_FALSE} ! printf " ERROR: \"%s\" not found.\n" "${strTestToRun}" ! fi ! ! if type shuTearDown > /dev/null 2>&1 ! then ! shuTearDown fi } ! shuFmtNbrTests() { ! n="${1}" ! if [ ${n} -eq 0 ] ! then ! shuRetFmtNbrTests="No tests" ! elif [ ${n} -eq 1 ] ! then ! shuRetFmtNbrTests="1 test" ! else ! shuRetFmtNbrTests="${n} tests" ! fi ! } ! shuRegisterFailedTest() { ! msg="${1}" ! if [ -z "${SHU_STR_FAILED}" ] ! then ! SHU_STR_FAILED="${msg}" ! else ! SHU_STR_FAILED="${SHU_STR_FAILED}^${msg}" ! fi } + # + # Extension points for alternative resultat formatters. + # + if ! type shuSuiteStart >/dev/null 2>&1 then *************** *** 218,225 **** } fi - - - # Global Variables - SHU_TRUE=0 - SHU_FALSE=1 - SHU_ERROR_EXIT_CODE=127 \ No newline at end of file --- 259,260 ---- |