This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SimpleCases sample to demonstrate failure propagation
- Loading branch information
joergboe
committed
Jan 3, 2020
1 parent
a272e27
commit 8bdafb6
Showing
10 changed files
with
78 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -----" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This test is skipped unconditional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters