|
From: lacton <la...@us...> - 2008-03-24 17:20:20
|
Update of /cvsroot/shunit/ShUnit In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv14673 Modified Files: README shUnit shUnitAcceptanceTest Log Message: [add] shuStart returns an informative exit code for better integration in build scripts. Index: README =================================================================== RCS file: /cvsroot/shunit/ShUnit/README,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** README 22 Mar 2008 09:13:48 -0000 1.2 --- README 24 Mar 2008 17:20:15 -0000 1.3 *************** *** 76,80 **** ---- ! What new in 1.4? * Added automatic detection of test functions. You no longer need to call --- 76,89 ---- ---- ! What's new in version 1.5? ! ! * shuStart returns an informative exit code. A value of 0 means all tests were ! successful. A value between 1 and 125 means there were that many failures ! during the test run. A value of 126 means there were 126 failures or ! more. A value of 127 means ShUnit was unable to run the tests. With ! this exit code, you can easily integrate you test execution in a larger ! build script. ! ! What's new in version 1.4? * Added automatic detection of test functions. You no longer need to call Index: shUnit =================================================================== RCS file: /cvsroot/shunit/ShUnit/shUnit,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** shUnit 22 Mar 2008 09:13:49 -0000 1.24 --- shUnit 24 Mar 2008 17:20:15 -0000 1.25 *************** *** 87,91 **** printf "\n****** `basename ${0}` ******\n" ! SHU_TOTAL_NR_OF_TESTS=`echo ${SHU_STR_ALL_TESTS} | wc -w | sed -e 's/ *//'` shuFmtNbrTests "${SHU_TOTAL_NR_OF_TESTS}" printf "%s to run:\n" "$shuRetFmtNbrTests" --- 87,98 ---- printf "\n****** `basename ${0}` ******\n" ! SHU_TOTAL_NR_OF_TESTS=`echo ${SHU_STR_ALL_TESTS} | wc -w | sed -e 's/ *//'` ! ! if [ "$SHU_TOTAL_NR_OF_TESTS" -eq 0 ] ! then ! echo 'shUnit: No tests to run' >&2 ! return $SHU_ERROR_EXIT_CODE ! fi ! shuFmtNbrTests "${SHU_TOTAL_NR_OF_TESTS}" printf "%s to run:\n" "$shuRetFmtNbrTests" *************** *** 122,127 **** printf " %s succeeded.\n" "${shuRetFmtNbrTests}" ! shuFmtNbrTests `expr ${shuTestNbr} - ${SHU_TOTAL_NR_SUCCEEDED}` printf " %s failed.\n\n" "${shuRetFmtNbrTests}" } --- 129,142 ---- printf " %s succeeded.\n" "${shuRetFmtNbrTests}" ! shuFailedTestCount=`expr ${shuTestNbr} - ${SHU_TOTAL_NR_SUCCEEDED}` ! shuFmtNbrTests $shuFailedTestCount printf " %s failed.\n\n" "${shuRetFmtNbrTests}" + + if [ $shuFailedTestCount -lt $SHU_ERROR_EXIT_CODE ] + then + return $shuFailedTestCount + else + return `expr $SHU_ERROR_EXIT_CODE - 1` + fi } *************** *** 166,167 **** --- 181,183 ---- SHU_TRUE=0 SHU_FALSE=1 + SHU_ERROR_EXIT_CODE=127 \ No newline at end of file Index: shUnitAcceptanceTest =================================================================== RCS file: /cvsroot/shunit/ShUnit/shUnitAcceptanceTest,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** shUnitAcceptanceTest 24 Mar 2008 12:57:51 -0000 1.1 --- shUnitAcceptanceTest 24 Mar 2008 17:20:16 -0000 1.2 *************** *** 17,20 **** --- 17,22 ---- shuRegTest Test1SuccessAnd1FailureInTheSameTest shuRegTest Test1SuccessAnd1FailureInDifferentTests + shuRegTest Test126FailingTests + shuRegTest Test127FailingTests shuRegTest TestShuStartWith2Arguments } *************** *** 23,29 **** for shell in $available_shells do ! stdout=`runEmbeddedTest $shell "Suite() { :; }"` ! # shuDeny "Expected error exit code with $shell" $? # TODO ! assertContains 'No tests to run' "$stdout" "$shell" done } --- 25,36 ---- for shell in $available_shells do ! SuiteWithNoTest() { ! runEmbeddedTest $shell "Suite() { :; }" ! } ! stdout=`SuiteWithNoTest 2>/dev/null` ! stderr=`SuiteWithNoTest 2>&1 >/dev/null` ! [ 127 -eq $? ] ! shuAssert "Expected exit code 127 with $shell" $? ! assertContains 'shUnit: No tests to run' "$stderr" "$shell" done } *************** *** 35,39 **** SuccessfulTest() { shuAssert 'Always true' 0; } Suite() { shuRegTest SuccessfulTest; }"` ! shuAssert "Expected successful exit code with $shell" $? assertContains '1 test succeeded.' "$stdout" "$shell" assertContains 'No tests failed.' "$stdout" "$shell" --- 42,47 ---- SuccessfulTest() { shuAssert 'Always true' 0; } Suite() { shuRegTest SuccessfulTest; }"` ! [ 0 -eq $? ] ! shuAssert "Expected exit code 0 with $shell" $? assertContains '1 test succeeded.' "$stdout" "$shell" assertContains 'No tests failed.' "$stdout" "$shell" *************** *** 47,51 **** FailingTest() { shuAssert 'Always false' 1; } Suite() { shuRegTest FailingTest; }"` ! # shuDeny "Expected error exit code with $shell" $? # TODO assertContains 'No tests succeeded.' "$stdout" "$shell" assertContains '1 test failed.' "$stdout" "$shell" --- 55,60 ---- FailingTest() { shuAssert 'Always false' 1; } Suite() { shuRegTest FailingTest; }"` ! [ 1 -eq $? ] ! shuAssert "Expected exit code 1 with $shell" $? assertContains 'No tests succeeded.' "$stdout" "$shell" assertContains '1 test failed.' "$stdout" "$shell" *************** *** 60,64 **** SecondSuccessfulTest() { shuAssert 'Always true' 0; } Suite() { shuRegTest FirstSuccessfulTest; shuRegTest SecondSuccessfulTest; }"` ! shuAssert "Expected successful exit code with $shell" $? assertContains '2 tests succeeded.' "$stdout" "$shell" assertContains 'No tests failed.' "$stdout" "$shell" --- 69,74 ---- SecondSuccessfulTest() { shuAssert 'Always true' 0; } Suite() { shuRegTest FirstSuccessfulTest; shuRegTest SecondSuccessfulTest; }"` ! [ 0 -eq $? ] ! shuAssert "Expected exit code 0 with $shell" $? assertContains '2 tests succeeded.' "$stdout" "$shell" assertContains 'No tests failed.' "$stdout" "$shell" *************** *** 75,79 **** } Suite() { shuRegTest TestWithASuccessAndAFailure; }"` ! # shuDeny "Expected error exit code with $shell" $? # TODO assertContains 'No tests succeeded.' "$stdout" "$shell" assertContains '1 test failed.' "$stdout" "$shell" --- 85,90 ---- } Suite() { shuRegTest TestWithASuccessAndAFailure; }"` ! [ 1 -eq $? ] ! shuAssert "Expected exit code 1 with $shell" $? assertContains 'No tests succeeded.' "$stdout" "$shell" assertContains '1 test failed.' "$stdout" "$shell" *************** *** 88,92 **** FailingTest() { shuAssert 'Always false' 1; } Suite() { shuRegTest SuccessfulTest; shuRegTest FailingTest; }"` ! # shuDeny "Expected error exit code with $shell" $? # TODO assertContains '1 test succeeded.' "$stdout" "$shell" assertContains '1 test failed.' "$stdout" "$shell" --- 99,104 ---- FailingTest() { shuAssert 'Always false' 1; } Suite() { shuRegTest SuccessfulTest; shuRegTest FailingTest; }"` ! [ 1 -eq $? ] ! shuAssert "Expected exit code 1 with $shell" $? assertContains '1 test succeeded.' "$stdout" "$shell" assertContains '1 test failed.' "$stdout" "$shell" *************** *** 94,97 **** --- 106,131 ---- } + Test126FailingTests() { + scriptWith126Failures=`scriptWithNFailures 126` + + for shell in $available_shells + do + stdout=`runEmbeddedTest $shell "$scriptWith126Failures"` + [ 126 -eq $? ] + shuAssert "Expected exit code 126 with $shell" $? + done + } + + Test127FailingTests() { + scriptWith127Failures=`scriptWithNFailures 127` + + for shell in $available_shells + do + stdout=`runEmbeddedTest $shell "$scriptWith127Failures"` + [ 126 -eq $? ] + shuAssert "Expected exit code 126 with $shell" $? + done + } + TestShuStartWith2Arguments() { for shell in $available_shells *************** *** 154,157 **** --- 188,207 ---- } + scriptWithNFailures() { + failingTestCount=${1} + + failingTestIdx=1 + testDeclarations="" + testRegistration="" + while [ $failingTestIdx -le $failingTestCount ] + do + testName="FailingTest$failingTestIdx" + testDeclarations="$testDeclarations $testName() { shuAssert 'Always false' 1; };" + testRegistration="$testRegistration shuRegTest $testName;" + failingTestIdx=`expr $failingTestIdx + 1` + done + echo "$testDeclarations Suite() { $testRegistration }" + } + # # Main |