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

Commit

Permalink
Introduce search path for modules; remove --tools command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
joergboe committed Apr 1, 2019
1 parent 472b61e commit 82333cf
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 87 deletions.
2 changes: 2 additions & 0 deletions bin/case.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ declare TTTT_caseFinalized=''
declare TTTT_failureOccurred=''
eval "$TTXX_runCategoryPatternArray"
declare -a TTTT_categoryArray=( 'default' )
TTXX_searchPath="$TTRO_inputDirCase $TTXX_searchPath"
export TTXX_searchPath

#test finalization function
function caseFinalization {
Expand Down
4 changes: 0 additions & 4 deletions bin/mainutil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function usage {
-i|--directory VALUE : The input directory - the test collection directory. There is no default. This option must be entered.
-p|--properties VALUE : This specifies the file with the global property values. Default is file $TEST_PROPERTIES in input directory.
This option can be given more than one time. This overwrites the environment \$TTRO_propertyFiles
-t|--tools VALUE : Includes (source) files with test tool scripts. This option can be given more than one time.
-c|--category VALUE : Enter the category pattern for this test run. The pattern must not contain white spaces.
Quote the value or escape special characters. This option can be given more than one time.
--skip-ignore : If this option is given the skip and category attributes of the cases and suite are ignored
Expand Down Expand Up @@ -290,9 +289,6 @@ function printParams {
for ((i=0; i<${#propertyFiles[@]}; i++)); do
printDebug "propertyFiles[$i]=${propertyFiles[$i]}"
done
for ((i=0; i<${#toolsFiles[@]}; i++)); do
printDebug "toolsFiles[$i]=${toolsFiles[$i]}"
done
for ((i=0; i<${#varNamesToSet[@]}; i++)); do
printDebug "-D ${varNamesToSet[$i]}=${varValuesToSet[$i]}"
done
Expand Down
19 changes: 8 additions & 11 deletions bin/man.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ function manpage () {
A test suite is defined through a directory with the main suite file with name: '$TEST_SUITE_FILE'
The name of a test suite is the relative path from the containing entity to the main test suite file.
The test suite file contains the necessary definitions and the script code to execute the test suite preparation
and suite finalization. The test suite file may contain common suite code (you must register functions, that are to be
and suite finalization. The test suite file may contain common suite code (you must export functions, that are to be
used in sub-suites or test cases).
Test cases may exists without a suite.
One or more test suites and/or test cases form a Test Collection. A Test Collection is defined through a directory.
A test collection may execute common code (functions must be registered).
A test collection may have a test properties file $TEST_PROPERTIES which should contain the definition of variables and
properties which may be variable in different test environments.
The name of the test properties file may be changed by a command line parameter (--properties).
Common used script code may be placed in separate script files, which must be registered during test run (--tools command line option).
Common used script code may be placed in separate script files, which must be imported during test run (use the import function).
Test cases must not be nested in other test case directories.
All path names of test cases and suites must not contain any white space characters.
Expand Down Expand Up @@ -120,8 +119,8 @@ function manpage () {
the default. The properties file is a bash script.
## Test Tools
=============
## Test Tools/Modules
=====================
If your test collection requires special functions, you must import the appropriate script module in the initialization part of a
Test Suite or Test Case file. The test Tools Script may define user defined variables, properties and functions. The defined
functions in a Tools Script must be exported like:
Expand All @@ -133,9 +132,10 @@ function manpage () {
Especially the streamsutils.sh must be imported at the beginning of the main body of the outermost Test Suite file:
import "\$TTRO_scriptDir/streamsutils.sh"\n
import "streamsutils.sh"\n
An alternative way to import a Test Tools module is the command line options --tools, which imports one Tools script.
This modules are searched in the directory of the current TestCase/TestSuite, in all directories of enclosing suites,
in the directory of the Test Collection and in the bin-directory.
## Test File Preamble
Expand Down Expand Up @@ -407,13 +407,11 @@ function manpage () {
- Set programm defined props/vars
- Set properties and variables defined with command line parameter -D..
- Source properties file if required - set props and vars
- Source all defined tools scripts
- Execute root suite in inherited environment
- print result
The Test Suite:
- Source all defined tools scripts
- Source Test Suite file - executes initialization in the main body of the script / set props and vars
- Check is suite is to be skipped and end suite execution if required
- Execute all Test Suite preparation steps if required
Expand All @@ -432,9 +430,8 @@ function manpage () {
The Test Case
- Source all defined tools scripts
- Source Test Case file - executes initialization in the main body of the script / set props and vars
- Check is cuite is to be skipped and end cuite execution if required
- Check if case is to be skipped and end case execution if so
- Execute all Test Case preparation steps if required
- Execute all test steps
- Execute all test finalization steps
Expand Down
46 changes: 10 additions & 36 deletions bin/runTTF
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ done
for x in ${!valueOptions[@]}; do
declare ${x}=""
done
declare -a toolsFiles=() #The with tools fies to include
declare -a propertyFiles=() # The property files
declare -a varNamesToSet=() #The list with variable names to set
declare -a varValuesToSet=() #The list with variables values to set
Expand All @@ -154,6 +153,8 @@ if ! declare -p TTPRN_debugDisable &> /dev/null; then TTPRN_debugDisable=''; fi
if ! declare -p TTPRN_verbose &> /dev/null; then TTPRN_verbose=''; fi
if ! declare -p TTPRN_verboseDisable &> /dev/null; then TTPRN_verboseDisable=''; fi

declare -x TTXX_searchPath="$TTRO_scriptDir"

#------------------------------------------------------
# get parametes and set option variables and cases map
declare parametersection="" # we start with options
Expand All @@ -178,11 +179,6 @@ while [[ $# -ge 1 ]]; do
[[ -z $parametersection ]] || optionInParamSection $1
echo "$TTRO_version"
exit 0;;
-t|--tools)
[[ $# -ge 2 && $2 != -* ]] || missOptionArg $1;
tmp="${#toolsFiles[@]}"
toolsFiles[$tmp]="$2"
shift;;
-p|--properties)
[[ $# -ge 2 && $2 != -* ]] || missOptionArg $1;
tmp="${#propertyFiles[@]}"
Expand Down Expand Up @@ -227,7 +223,7 @@ while [[ $# -ge 1 ]]; do
if [[ -n ${!option} ]]; then duplicateOption "${1}"; fi
[[ $# -ge 2 && $2 != -* ]] || missOptionArg $1;
if [[ $option == reference && -z $2 ]]; then
reference="${TTRO_scriptDir}/util.sh"
reference="util.sh"
else
eval "${option}=$2"
fi
Expand Down Expand Up @@ -266,6 +262,7 @@ unset -v parametersection
unset -v exportCheckFailed

#-----------------------------------------------
declare -x TTXX_modulesImported=''
declare -x TTRO_reference=""
if [[ -n $reference ]]; then
TTRO_reference='true'
Expand All @@ -274,8 +271,8 @@ readonly TTRO_reference
if [[ -n $TTRO_reference ]]; then
list1=$(echo "${!TTRO_help@} " | sort)
list3=''
if [[ $reference != "${TTRO_scriptDir}/util.sh" ]]; then
source "$reference"
if [[ $reference != "util.sh" ]]; then
import "$reference"
list2=$(echo "${!TTRO_help@} " | sort)
for x in $list2; do
if ! isInList "$x" "$list1"; then
Expand Down Expand Up @@ -359,13 +356,15 @@ else
fi
cd "${currentDir}"
#---------------------------------------------------------
# get input directory and make it absolute
# get input directory and make it absolute correct search path
if [[ -z ${directory} ]]; then
printErrorAndExit "No input directory specified" ${errInvocation}
else
if cd "${directory}"; then
directory=$(pwd -P)
declare -x TTRO_inputDir="$directory"
TTXX_searchPath="$TTRO_inputDir $TTXX_searchPath"
export TTXX_searchPath
else
printErrorAndExit "Invalid directory '${directory}' specified" ${errInvocation}
fi
Expand Down Expand Up @@ -394,15 +393,7 @@ for ((i=0; i<${#propertyFiles[@]}; i++)); do
tmp2=$(readlink -m "$tmp")
propertyFiles[$i]="$tmp2"
done
for ((i=0; i<${#toolsFiles[@]}; i++)); do
tmp="${toolsFiles[$i]}"
if [[ ${tmp:0:1} != "/" ]]; then
tmp="${currentDir}/${tmp}"
fi
tmp2=$(readlink -m "$tmp")
toolsFiles[$i]="$tmp2"
done
readonly propertyFiles toolsFiles
readonly propertyFiles

#----------------------------------
#finally make option variables read only
Expand Down Expand Up @@ -632,7 +623,6 @@ cd "$TTRO_workDir"

#-----------------------------------------------------------
#check if properties file exists - read properties and fixup
declare -x TTXX_tools='' # allow imports in property file
if [[ ${#propertyFiles[@]} -gt 0 ]]; then
for ((i=0; i<${#propertyFiles[@]}; i++)); do
x="${propertyFiles[$i]}"
Expand All @@ -652,22 +642,6 @@ else
TTTF_writeProtectExportedFunctions
fi

#------------------------------------------------
# source tools
if [[ ${#toolsFiles[@]} -gt 0 ]]; then
for ((i=0; i<${#toolsFiles[@]}; i++)); do
x="${toolsFiles[$i]}"
printInfo "Source global tools file: $x"
if [[ -r $x ]]; then
import "$x"
else
printErrorAndExit "Tools file $x is required but this file is not readable" $errRt
fi
done
else
isDebug && printDebug "No additional global test tools files defined"
fi

#------------------------------------------------
# diagnostics
isVerbose && printTestframeEnvironment
Expand Down
5 changes: 5 additions & 0 deletions bin/suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ eval "$TTXX_runCategoryPatternArray"
declare -rx TTRO_suite="${TTTI_suitesName[$TTRO_suiteIndex]}"
declare -rx TTRO_inputDirSuite="${TTTI_suitesPath[$TTRO_suiteIndex]}"
declare -a TTTT_categoryArray=()
#append suite input dir to the top of the search pathes
if [[ $TTRO_suiteIndex -ne 0 ]]; then
TTXX_searchPath="$TTRO_inputDirSuite $TTXX_searchPath"
export TTXX_searchPath
fi
TTTF_fixPropsVars

# enter working dir
Expand Down
35 changes: 29 additions & 6 deletions bin/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1540,14 +1540,37 @@ TTRO_help_import='
# return the result code of the source command'
function import {
isDebug && printDebug "$FUNCNAME $*"
local tmp=$(readlink -m "$1")
if isInList "$tmp" "$TTXX_tools"; then
printWarning "file $tmp is already registerd in TTXX_tools=$TTXX_tools"
[[ $# -ne 1 ]] && printErrorAndExit "$FUNCNAME invalid no of params. Number of Params is $#" $errRt
local TTTT_trim
trim "$1"
local componentName="${TTTT_trim##*/}"
if isInList "$componentName" "$TTXX_modulesImported"; then
printWarning "file $componentName is already registerd in TTXX_modulesImported=$TTXX_modulesImported"
return 0
fi
local filename=''
if [[ ${TTTT_trim:0:1} == '/' ]]; then
if [[ -r $TTTT_trim ]]; then
filename="$TTTT_trim"
fi
else
isDebug && printDebug "\$TTXX_searchPath=$TTXX_searchPath"
local x
for x in $TTXX_searchPath; do
local composite="$x/$TTTT_trim"
if [[ -r $composite ]]; then
filename="$composite"
break
fi
done
fi
if [[ -z $filename ]]; then
printErrorAndExit "$FUNCNAME: no readable file found for module '$TTTT_trim' in search path '$TTXX_searchPath'" $errRt
else
TTXX_tools="$TTXX_tools $tmp"
export TTXX_tools
source "$tmp"
printInfo "Module $componentName import found here: $filename"
TTXX_modulesImported="$TTXX_modulesImported $componentName"
export TTXX_modulesImported
source "$filename"
TTTF_fixPropsVars
TTTF_writeProtectExportedFunctions
fi
Expand Down
11 changes: 0 additions & 11 deletions test/imports/Case1/TestCase.sh

This file was deleted.

22 changes: 22 additions & 0 deletions test/imports/Suite1/Case1/TestCase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import tool1.sh
import "tool2.sh"

STEPS=(
'echo "######## STEP1"'
'func1'
'func2'
'myEval'
)

myEval() {
echo "$TTPR_var11=$TTPR_var11"
echo "$TTPR_var12=$TTPR_var12"
echo "$TTPR_var21=$TTPR_var21"
echo "$TTPR_var22=$TTPR_var22"
echo "\$TTRO_var1=$TTRO_var1"
if [[ $TTPR_var11 != 'set_from_tool1.sh' ]]; then setError "wrong value \$TTPR_var11"; fi
if [[ $TTPR_var12 != 'set_from_func1' ]]; then setError "wrong value \$TTPR_var12"; fi
if [[ $TTPR_var21 != 'set_from_tool2.sh' ]]; then setError "wrong value \$TTPR_var21"; fi
if [[ $TTPR_var22 != 'set_from_func2' ]]; then setError "wrong value \$TTPR_var22"; fi
if [[ $TTRO_var1 != '55' ]]; then setError "wrong value \$TTRO_var1"; fi
}
12 changes: 12 additions & 0 deletions test/imports/Suite1/Case1/tool2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
echo "######### tool2.sh ########"
setVar 'TTPR_var11' 'set_from_tool2.sh'
setVar 'TTPR_var21' 'set_from_tool2.sh'

func2() {
echo "######### func2 xxxx"
setVar 'TTPR_var11' 'set_from_func2'
setVar 'TTPR_var12' 'set_from_func2'
setVar 'TTPR_var21' 'set_from_func2'
setVar 'TTPR_var22' 'set_from_func2'
}
export -f func2
1 change: 1 addition & 0 deletions test/imports/Suite1/TestSuite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Case1/tool2.sh
3 changes: 1 addition & 2 deletions test/imports/TestProperties.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import "$TTRO_inputDir/tool1.sh"
import "$TTRO_inputDir/tool2.sh"
import " tool1.sh "

setVar 'TTRO_var1' 55
12 changes: 4 additions & 8 deletions test/imports/tool1.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@

echo "######### tool1.sh ########"
setVar 'TTPR_var11' 'set_from_tool1.sh'

func1() {
echo "func1 xxxx"
echo "TTRO_var1=$TTRO_var1"
echo "######### func1 xxxx"
setVar 'TTPR_var11' 'set_from_func1'
setVar 'TTPR_var12' 'set_from_func1'
}
export -f func1

func2() {
echo "func2 xxxx"
setVar 'TTRO_var2' 'func2'
}
export -f func2
7 changes: 0 additions & 7 deletions test/imports/tool2.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ case $TTRO_variantCase in
'--noprompt : Do not prompt berfore an existing working directory is removed.'
'-i|--directory VALUE : The input directory - the test collection directory. There is no default. This option must be entered.'
'-p|--properties VALUE : This specifies the file with the global property values. Default is file TestProperties.sh in input directory.'
'-t|--tools VALUE : Includes (source) files with test tool scripts. This option can be given more than one time.'
'-c|--category VALUE : Enter the category pattern for this test run. The pattern must not contain white spaces.'
' Quote the value or escape special characters. This option can be given more than one time.'
'--skip-ignore : If this option is given the skip and category attributes of the cases and suite are ignored'
Expand Down
2 changes: 1 addition & 1 deletion test/sequencetest/Suite1/TestSuite.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "$TTRO_scriptDir/testutils.sh"
import " testutils.sh"

0 comments on commit 82333cf

Please sign in to comment.