From 82333cf7bcd9282498e2b87c9fb413eff0f9cf46 Mon Sep 17 00:00:00 2001 From: joergboe Date: Mon, 1 Apr 2019 16:26:24 +0200 Subject: [PATCH] Introduce search path for modules; remove --tools command line option --- bin/case.sh | 2 + bin/mainutil.sh | 4 -- bin/man.sh | 19 ++++---- bin/runTTF | 46 ++++--------------- bin/suite.sh | 5 ++ bin/util.sh | 35 +++++++++++--- test/imports/Case1/TestCase.sh | 11 ----- test/imports/Suite1/Case1/TestCase.sh | 22 +++++++++ test/imports/Suite1/Case1/tool2.sh | 12 +++++ test/imports/Suite1/TestSuite.sh | 1 + test/imports/TestProperties.sh | 3 +- test/imports/tool1.sh | 12 ++--- test/imports/tool2.sh | 7 --- .../Invocation/HelpFunctions/TestCase.sh | 1 - test/sequencetest/Suite1/TestSuite.sh | 2 +- 15 files changed, 95 insertions(+), 87 deletions(-) delete mode 100644 test/imports/Case1/TestCase.sh create mode 100644 test/imports/Suite1/Case1/TestCase.sh create mode 100644 test/imports/Suite1/Case1/tool2.sh create mode 100644 test/imports/Suite1/TestSuite.sh delete mode 100644 test/imports/tool2.sh diff --git a/bin/case.sh b/bin/case.sh index dbc5fa6..b8f68d9 100755 --- a/bin/case.sh +++ b/bin/case.sh @@ -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 { diff --git a/bin/mainutil.sh b/bin/mainutil.sh index af7ab6a..4f546d0 100644 --- a/bin/mainutil.sh +++ b/bin/mainutil.sh @@ -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 @@ -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 diff --git a/bin/man.sh b/bin/man.sh index ce28a5b..f824115 100644 --- a/bin/man.sh +++ b/bin/man.sh @@ -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. @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/bin/runTTF b/bin/runTTF index c24c662..e8f7d44 100755 --- a/bin/runTTF +++ b/bin/runTTF @@ -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 @@ -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 @@ -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[@]}" @@ -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 @@ -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' @@ -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 @@ -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 @@ -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 @@ -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]}" @@ -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 diff --git a/bin/suite.sh b/bin/suite.sh index f50bf6b..7f1eaf8 100755 --- a/bin/suite.sh +++ b/bin/suite.sh @@ -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 diff --git a/bin/util.sh b/bin/util.sh index 590624f..b771b17 100644 --- a/bin/util.sh +++ b/bin/util.sh @@ -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 diff --git a/test/imports/Case1/TestCase.sh b/test/imports/Case1/TestCase.sh deleted file mode 100644 index acc5b97..0000000 --- a/test/imports/Case1/TestCase.sh +++ /dev/null @@ -1,11 +0,0 @@ -STEPS=( - 'echo "######## STEP1"' - 'func1' - 'func2' - 'myEval' -) - -myEval() { - if [[ $TTRO_var1 -ne 55 ]]; then setFailure "wrong var1"; fi - if [[ $TTRO_var2 != func2 ]]; then setFailure "wrong var2"; fi -} diff --git a/test/imports/Suite1/Case1/TestCase.sh b/test/imports/Suite1/Case1/TestCase.sh new file mode 100644 index 0000000..a92149d --- /dev/null +++ b/test/imports/Suite1/Case1/TestCase.sh @@ -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 +} diff --git a/test/imports/Suite1/Case1/tool2.sh b/test/imports/Suite1/Case1/tool2.sh new file mode 100644 index 0000000..7c98104 --- /dev/null +++ b/test/imports/Suite1/Case1/tool2.sh @@ -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 diff --git a/test/imports/Suite1/TestSuite.sh b/test/imports/Suite1/TestSuite.sh new file mode 100644 index 0000000..f4982c0 --- /dev/null +++ b/test/imports/Suite1/TestSuite.sh @@ -0,0 +1 @@ +import Case1/tool2.sh diff --git a/test/imports/TestProperties.sh b/test/imports/TestProperties.sh index 80a451d..daa1948 100644 --- a/test/imports/TestProperties.sh +++ b/test/imports/TestProperties.sh @@ -1,5 +1,4 @@ -import "$TTRO_inputDir/tool1.sh" -import "$TTRO_inputDir/tool2.sh" +import " tool1.sh " setVar 'TTRO_var1' 55 diff --git a/test/imports/tool1.sh b/test/imports/tool1.sh index 700acdd..8573fa1 100644 --- a/test/imports/tool1.sh +++ b/test/imports/tool1.sh @@ -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 diff --git a/test/imports/tool2.sh b/test/imports/tool2.sh deleted file mode 100644 index 970b14a..0000000 --- a/test/imports/tool2.sh +++ /dev/null @@ -1,7 +0,0 @@ -echo "######### tool2.sh ########" - -func2() { - echo "func2 xxxx" - setVar 'TTRO_var1' 55 -} -export -f func2 diff --git a/test/selftest/Selftest/Invocation/HelpFunctions/TestCase.sh b/test/selftest/Selftest/Invocation/HelpFunctions/TestCase.sh index 14d59b3..dd82bd6 100644 --- a/test/selftest/Selftest/Invocation/HelpFunctions/TestCase.sh +++ b/test/selftest/Selftest/Invocation/HelpFunctions/TestCase.sh @@ -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' diff --git a/test/sequencetest/Suite1/TestSuite.sh b/test/sequencetest/Suite1/TestSuite.sh index 1323f92..cb29990 100644 --- a/test/sequencetest/Suite1/TestSuite.sh +++ b/test/sequencetest/Suite1/TestSuite.sh @@ -1 +1 @@ -import "$TTRO_scriptDir/testutils.sh" \ No newline at end of file +import " testutils.sh"