diff --git a/samples/SimpleCases/CaseWithError/TestCase.sh b/samples/SimpleCases/CaseWithError/TestCase.sh index 688b71b..65e8094 100644 --- a/samples/SimpleCases/CaseWithError/TestCase.sh +++ b/samples/SimpleCases/CaseWithError/TestCase.sh @@ -1,12 +1,21 @@ -STEPS=( 'mytest' ) -FINS='mytestfin' +#--variantList='step step2 prep' -# Demonstrate the execution of the finalization function -function mytestfin { - echo "----- $FUNCNAME Execute finalization of the test step -----" +echo "Variant step demonstrate an failed test case step with a function that returns a value not equal zero" +echo "Variant step2 demonstrate an failed test case step with an external command that returns a value not equal zero" +echo "Variant prep demonstrates an failure during test preparation" +echo "Both variants execute finally the testFinalization function" + +PREPS='myprep' +STEPS='mytest' +FINS=( 'echo "----- $FUNCNAME Execute finalization of the test step -----"' ) + +myprep() { + if [[ "$TTRO_variantCase" == "prep" ]]; then + echoAndExecute myFailedFunction + fi } -function mytest { +mytest() { echo "----- Guard a function or command that may fail $FUNCNAME -----" if myFailedFunction; then echo "----- The called function return success -----" @@ -14,12 +23,18 @@ function mytest { echo "----- The called function returned failure code $? -----" fi echo "----- If this function not guarded, the test case exits -----" - echoAndExecute myFailedFunction - #this statement is nopt reached + if [[ "$TTRO_variantCase" == "step" ]]; then + echoAndExecute myFailedFunction + fi + if [[ "$TTRO_variantCase" == "step2" ]]; then + /bin/false + fi + #this statement is not reached + echo "*********** This must not be seen ********************************" return 0 } -function myFailedFunction { +myFailedFunction() { echo "----- Hello $FUNCNAME this function returns an error -----" return 55 } \ No newline at end of file diff --git a/samples/SimpleCases/CaseWithFailure/TestCase.sh b/samples/SimpleCases/CaseWithFailure/TestCase.sh index 52c66f3..2b55177 100644 --- a/samples/SimpleCases/CaseWithFailure/TestCase.sh +++ b/samples/SimpleCases/CaseWithFailure/TestCase.sh @@ -1,24 +1,24 @@ -#--variantList='failure error' +#--variantList='step prep' + +echo "Variant step demonstrate an failed test case step" +echo "Variant prep demonstrates an failure during test preparation (This should not happen, but is is tollerated)" +echo "Both variants execute finally the testFinalization function" -# Variant failure demonstrate an failed test case -# Variant error demonstrates an failure during test preparation -# which is turend into an error -# Both variants execute finally the testFinalization function testStep() { - if [[ "$TTRO_variantCase" == "failure" ]]; then - echo "----- Execute test and fail -----" - setFailure "CUSTOM FAILURE" + if [[ "$TTRO_variantCase" == "step" ]]; then + echo "----- Execute test and set failure -----" + setFailure "CUSTOM FAILURE during STEP" fi } testPreparation() { - if [[ "$TTRO_variantCase" == "error" ]]; then - echo "----- Execute test and fail -----" - setFailure "CUSTOM FAILURE" + if [[ "$TTRO_variantCase" == "prep" ]]; then + echo "----- Execute preparation and set failure -----" + setFailure "CUSTOM FAILURE during PREPS" fi } # Demonstrate the execution of the finalization function testFinalization() { - echo "----- $FUNCNAME Execute finalization of the test step -----" + echo "----- $FUNCNAME Execute finalization of the test -----" } diff --git a/samples/SimpleCases/CaseWithSuccess/TestCase.sh b/samples/SimpleCases/CaseWithSuccess/TestCase.sh index 4fd000e..7a282d5 100644 --- a/samples/SimpleCases/CaseWithSuccess/TestCase.sh +++ b/samples/SimpleCases/CaseWithSuccess/TestCase.sh @@ -1,17 +1,38 @@ -#Here we use a function for the test case -# execution -function testStep { +#Here the function for test case preparation: must succeed +testPreparation() { + echo "$FUNCNAME" + return 0 +} + +#Here we use a function for the test case execution +testStep() { echo "$FUNCNAME Demonstrate a successful test execution" echo "Guard a function that maiy fail during test preparation, execution of finalization" - if myFailedFunction; then + if myFailedFunction 55; then echo "Function return success" else echo "Function returned failure $?" fi + echo "Or expect the failure of the function and evaluate the result code" + echoExecuteAndIntercept myFailedFunction 56 + echo "Function returns $TTTT_result" + echo "Or expect failure and store the output for furthere evaluation" + executeLogAndError myFailedFunction 57 + echo "Function returns $TTTT_result" + echo "The output is logged in file \$TT_evaluationFile=$TT_evaluationFile" + cat "$TT_evaluationFile" return 0 } -function myFailedFunction { - echo "Hello $FUNCNAME this function returns an error" +#Here we use a function for the test case finalization +testFinalization() { + echo "$FUNCNAME goes here! It should not faikl and it should not set failure conditions. But it may fail and it may set failures, which are ignored" + echo $- + setFailure "Failure to be ignored" return 1 +} + +myFailedFunction() { + echo "Hello $FUNCNAME this function returns an $1 as return code" + return $1 } \ No newline at end of file diff --git a/samples/SimpleCases/README.md b/samples/SimpleCases/README.md index 862ab15..667f5fe 100644 --- a/samples/SimpleCases/README.md +++ b/samples/SimpleCases/README.md @@ -1,4 +1,6 @@ Demonstrate a test collection -with one successful, one failed and one test case with an error result -and two skipped test case +with successful, failed and test cases with an error result +and two skipped test cases +expected result is: +cases executed=8 failures=2 errors=3 skipped=2 diff --git a/samples/SimpleCases/SkippedCase/TestCase.sh b/samples/SimpleCases/SkippedCase/TestCase.sh deleted file mode 100644 index e69de29..0000000 diff --git a/samples/SimpleCases/SkippedCase2/TestCase.sh b/samples/SimpleCases/SkippedCase2/TestCase.sh deleted file mode 100644 index 0086bc5..0000000 --- a/samples/SimpleCases/SkippedCase2/TestCase.sh +++ /dev/null @@ -1,2 +0,0 @@ -# Set the skip condition in test initialization -setSkip diff --git a/samples/SimpleCases/SkippedCaseDynamic/TestCase.sh b/samples/SimpleCases/SkippedCaseDynamic/TestCase.sh new file mode 100644 index 0000000..de700ec --- /dev/null +++ b/samples/SimpleCases/SkippedCaseDynamic/TestCase.sh @@ -0,0 +1,8 @@ +# Set the skip condition dynamically in test initialization +# depending on some conditions +if true; then + setSkip "Some Condition met" +fi + +STEPS='true' + diff --git a/samples/SimpleCases/SkippedCase/SKIP b/samples/SimpleCases/SkippedCaseFile/SKIP similarity index 100% rename from samples/SimpleCases/SkippedCase/SKIP rename to samples/SimpleCases/SkippedCaseFile/SKIP diff --git a/samples/SimpleCases/SkippedCaseFile/TestCase.sh b/samples/SimpleCases/SkippedCaseFile/TestCase.sh new file mode 100644 index 0000000..a42f208 --- /dev/null +++ b/samples/SimpleCases/SkippedCaseFile/TestCase.sh @@ -0,0 +1 @@ +# This test is skipped unconditional \ No newline at end of file diff --git a/test/jobtest/Suite1/TestSuite.sh b/test/jobtest/Suite1/TestSuite.sh index 5d28c5b..03a0126 100644 --- a/test/jobtest/Suite1/TestSuite.sh +++ b/test/jobtest/Suite1/TestSuite.sh @@ -4,7 +4,8 @@ PREPS=myPrep myPrep() { echo "expected result is in parallel mode:" - echo "executed=4 failures=0 errors=1 skipped=0" + echo "executed=4 failures=0 errors=2 skipped=0" + echo "Test case error for case Case0ReadFromConsole" echo "Test case error (timout) for case Case1EndlessSync" echo echo "in serial mode:"