4 # @author MyungJoo Ham <myungjoo.ham@gmail.com>
7 # @brief This executes test groups and reports aggregated test results.
8 # @exit 0 if all PASSED. Positive if some FAILED.
11 # If there is no arguments specified, this will search for all "runTest.sh" in
12 # the subdirectory of this file and regard them as the test groups.
14 # If a testgroup (runTest.sh) returns 0 while there are failed testcase,
15 # it implies that the failed testcases may be ignored and it's good to go.
17 # If --help or -h is given, this will show detailed description.
20 BASEPATH=`dirname "$0"`
21 BASENAME=`basename "$0"`
34 printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>] [--nocolor] [--showstdout]\n\n"
35 printf "These are common ${Red}ssat${NC} commands used:\n\n"
36 printf "Test all test-groups in the current ($(pwd)) directory, recursively\n"
37 printf " (no options specified)\n"
38 printf " $ ${BASENAME}\n"
40 printf "Test all test-groups in the specified directory, recursively\n"
42 printf " $ ${BASENAME} /home/username/test\n"
43 printf " If there are multiple paths, the last one will be used\n"
45 printf "Search for \"filename\" as the testcase scripts\n"
46 printf " --testcase or -t\n"
47 printf " $ ${BASENAME} --testcase cases.sh\n"
48 printf " Search for cases.sh instead of runTest.sh\n"
50 printf "Do not emit colored text\n"
51 printf " --nocolor or -n\n"
53 printf "Show stdout of test cases\n"
54 printf " --showstdout or -s\n"
56 printf "Shows this message\n"
57 printf " --help or -h\n"
58 printf " $ ${BASENAME} --help \n"
75 *) # Unknown, which is probably target (the path to root-dir of test groups).
80 source ${BASEPATH}/ssat-api.sh
82 if [[ "${#TARGET}" -eq "0" ]]
96 while read -d $'\0' file
98 CASEBASEPATH=`dirname "$file"`
99 CASENAME=`basename "$CASEBASEPATH"`
105 pushd $CASEBASEPATH > /dev/null
108 if [[ "${SILENT}" -eq "0" ]]
110 printf "${output}" | sed '$d'
114 logfile="${output##*$'\n'}"
116 resultlog=$(<$logfile)
117 effectiveOutput=`printf "$resultlog" | sed '$d'`
118 log="$log$effectiveOutput\n"
120 lastline=`printf "${resultlog}" | sed '$!d'`
128 TNtcpass=$((TNtcpass+Npass))
129 TNtcfail=$((TNtcfail+Nfail))
131 TNgroup=$((TNgroup+1))
132 if [[ "$retcode" -eq "0" ]]
134 TNgrouppass=$((TNgrouppass+1))
135 groupLog="${groupLog}${LightGreen}[PASSED]${NC} ${Blue}${CASENAME}${NC} ($Npass passed among $Ntc cases)\n"
137 TNgroupfail=$((TNgroupfail+1))
138 groupLog="${groupLog}${Red}[FAILED]${NC} ${Blue}${CASENAME}${NC} ($Npass passed among $Ntc cases)\n"
141 done < <(find $TARGET -name $TESTCASE -print0)
143 printf "\n\n==================================================\n\n"
146 printf "==================================================\n\n"
148 printf "==================================================\n"
150 if (( ${TNgroupfail} == 0 ))
152 printf "${LightGreen}[PASSED] ${Blue}All Test Groups (${TNgroup}) Passed!${NC}\n\n"
155 printf "${Red}[FAILED] ${Purple}There are failed test groups! (${TNgroupfail})${NC}\n\n"
158 # gather reports & publish them.