Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Update SimpleCases sample to demonstrate failure propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
joergboe committed Jan 3, 2020
1 parent a272e27 commit 8bdafb6
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 32 deletions.
33 changes: 24 additions & 9 deletions samples/SimpleCases/CaseWithError/TestCase.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
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 -----"
else
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
}
24 changes: 12 additions & 12 deletions samples/SimpleCases/CaseWithFailure/TestCase.sh
Original file line number Diff line number Diff line change
@@ -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 -----"
}
33 changes: 27 additions & 6 deletions samples/SimpleCases/CaseWithSuccess/TestCase.sh
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 4 additions & 2 deletions samples/SimpleCases/README.md
Original file line number Diff line number Diff line change
@@ -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

Empty file.
2 changes: 0 additions & 2 deletions samples/SimpleCases/SkippedCase2/TestCase.sh

This file was deleted.

8 changes: 8 additions & 0 deletions samples/SimpleCases/SkippedCaseDynamic/TestCase.sh
Original file line number Diff line number Diff line change
@@ -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'

1 change: 1 addition & 0 deletions samples/SimpleCases/SkippedCaseFile/TestCase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This test is skipped unconditional
3 changes: 2 additions & 1 deletion test/jobtest/Suite1/TestSuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down

0 comments on commit 8bdafb6

Please sign in to comment.