| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# MT, run all or specific parts of the test suite |
| 4 |
# Copyright (C) 2018-2022 Xavier Delaruelle |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
########################################################################## |
| 20 |
|
| 21 |
set -u |
| 22 |
|
| 23 |
# print help message |
| 24 |
echo_usage() { |
| 25 |
echo "Usage: $0 [options] [testsuite] [serienum[/testfilenum]]... |
| 26 |
|
| 27 |
Run all or specific parts of the test suite |
| 28 |
|
| 29 |
Test suites: |
| 30 |
modules Test modulecmd.tcl built script (default) |
| 31 |
quick Short version of modulecmd.tcl testsuite |
| 32 |
cov Coverage mode of modulecmd.tcl testsuite |
| 33 |
install Test Modules installation |
| 34 |
lint Lint script files of this repository |
| 35 |
|
| 36 |
Select parts of testsuite: |
| 37 |
serienum Identification number of testsuite directory containing a |
| 38 |
series of testfile (e.g., '50' for modules.50-cmds dir.) |
| 39 |
testfilenum Identification number of testfile in a testserie (e.g., |
| 40 |
'370' for 370-variant.exp testfile in modules.70-maint dir.) |
| 41 |
|
| 42 |
Options: |
| 43 |
-h, --help Show this help message and exit |
| 44 |
|
| 45 |
Examples: |
| 46 |
$0 |
| 47 |
$0 quick |
| 48 |
$0 lint |
| 49 |
$0 50/37 61 70/{290,440} |
| 50 |
" |
| 51 |
} |
| 52 |
|
| 53 |
# print message on stderr then exit |
| 54 |
echo_error() { |
| 55 |
echo -e "ERROR: $1" >&2 |
| 56 |
exit 1 |
| 57 |
} |
| 58 |
|
| 59 |
if [ ! -e tcl/main.tcl.in ]; then |
| 60 |
echo_error "Not in correct directory" |
| 61 |
fi |
| 62 |
|
| 63 |
# make bin, should use GNU make |
| 64 |
if command -v gmake >/dev/null; then |
| 65 |
make='gmake' |
| 66 |
else |
| 67 |
make='make' |
| 68 |
fi |
| 69 |
|
| 70 |
# make target |
| 71 |
target='test' |
| 72 |
testserie='modules' |
| 73 |
setuptestfiles=(00/005 00/006 00/010 00/050 00/060 00/080 00/085) |
| 74 |
if [ $# -gt 0 ]; then |
| 75 |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then |
| 76 |
echo_usage |
| 77 |
exit 0 |
| 78 |
elif [ "$1" = "modules" ]; then |
| 79 |
target='test' |
| 80 |
testserie='modules' |
| 81 |
shift |
| 82 |
elif [ "$1" = "quick" ]; then |
| 83 |
export QUICKTEST=1 |
| 84 |
shift |
| 85 |
elif [ "$1" = "cov" ]; then |
| 86 |
export COVERAGE=y |
| 87 |
shift |
| 88 |
elif [ "$1" = "install" ]; then |
| 89 |
target='testinstall' |
| 90 |
testserie='install' |
| 91 |
setuptestfiles=(00/005 00/006 00/010 00/011) |
| 92 |
shift |
| 93 |
elif [ "$1" = "lint" ]; then |
| 94 |
target='testlint' |
| 95 |
testserie='lint' |
| 96 |
setuptestfiles=(00/005 00/006 00/011) |
| 97 |
shift |
| 98 |
fi |
| 99 |
fi |
| 100 |
|
| 101 |
if [ $# -gt 0 ]; then |
| 102 |
# build list of test files to run test on |
| 103 |
declare -a testfiles |
| 104 |
for i in "${setuptestfiles[@]}" "${@}"; do |
| 105 |
j=${i##*/} |
| 106 |
i=${i%/*} |
| 107 |
|
| 108 |
# add all test files if passed a full section number or a test file |
| 109 |
# from collection section (this section must be run entirely) |
| 110 |
if [ "$j" == "$i" ] || [ "$i" == "61" ]; then |
| 111 |
testfiles+=(testsuite/"$testserie.${i}"*/*.exp) |
| 112 |
else |
| 113 |
testfiles+=(testsuite"/$testserie.${i}"*/{010,999,$j}*.exp) |
| 114 |
fi |
| 115 |
done |
| 116 |
|
| 117 |
# get file name of selected test files (runtest requires .exp file name) |
| 118 |
declare -a testfnames=() |
| 119 |
for i in "${testfiles[@]}"; do |
| 120 |
if [ -e "$i" ]; then |
| 121 |
fname=${i##*/} |
| 122 |
# build list of unique file names |
| 123 |
if [ ${#testfnames[@]} -eq 0 ]\ |
| 124 |
|| [[ ! " ${testfnames[*]} " == *" $fname "* ]]; then |
| 125 |
testfnames+=("$fname") |
| 126 |
fi |
| 127 |
fi |
| 128 |
done |
| 129 |
|
| 130 |
# pass list to make target |
| 131 |
export RUNTESTFILES="${testfnames[*]}" |
| 132 |
fi |
| 133 |
|
| 134 |
# attempt to get enhanced diff tool but disable this retrieval if download |
| 135 |
# tentative fails |
| 136 |
if [ ! -e .noicdiff ]; then |
| 137 |
$make icdiff || touch .noicdiff |
| 138 |
fi |
| 139 |
|
| 140 |
rm -f $testserie.log |
| 141 |
|
| 142 |
if [ -t 1 ]; then |
| 143 |
fail_count=0 |
| 144 |
xfail_count=0 |
| 145 |
pass_count=0 |
| 146 |
error_count=0 |
| 147 |
current_fail_count=0 |
| 148 |
current_xfail_count=0 |
| 149 |
current_pass_count=0 |
| 150 |
current_error_count=0 |
| 151 |
current_case='' |
| 152 |
pass_sgr='1;32;7' |
| 153 |
fail_sgr=0 |
| 154 |
error_sgr=0 |
| 155 |
tail --follow=name --retry --quiet $testserie.log \ |
| 156 |
| while read -r logline; do |
| 157 |
case_changed=0 |
| 158 |
case "$logline" in |
| 159 |
PASS*) |
| 160 |
((pass_count++)) |
| 161 |
((current_pass_count++)) ;; |
| 162 |
FAIL*) |
| 163 |
((fail_count++)) |
| 164 |
((current_fail_count++)) ;; |
| 165 |
XFAIL*) |
| 166 |
((xfail_count++)) |
| 167 |
((current_xfail_count++)) ;; |
| 168 |
ERROR:\ tcl\ error\ sourcing*) |
| 169 |
((error_count++)) |
| 170 |
((current_error_count++)) ;; |
| 171 |
Running*) |
| 172 |
case_raw=${logline/*${testserie}.} |
| 173 |
case_suite=${case_raw:0:2} |
| 174 |
number_raw=${case_raw#*/} |
| 175 |
case_number=${number_raw:0:3} |
| 176 |
previous_case=$current_case |
| 177 |
current_case="$case_suite/$case_number" |
| 178 |
case_changed=1 ;; |
| 179 |
esac |
| 180 |
if [ $error_count -eq 1 ]; then |
| 181 |
pass_sgr=0 |
| 182 |
fail_sgr=0 |
| 183 |
error_sgr='1;35;7' |
| 184 |
elif [ $error_count -eq 0 ] && [ $fail_count -eq 1 ]; then |
| 185 |
pass_sgr=0 |
| 186 |
fail_sgr='1;31;7' |
| 187 |
fi |
| 188 |
if [ $case_changed -eq 1 ] ; then |
| 189 |
if [ $current_fail_count -ne 0 ] || [ $current_xfail_count -ne 0 ]\ |
| 190 |
|| [ $current_error_count -ne 0 ]; then |
| 191 |
issue_info="case=$previous_case, " |
| 192 |
issue_info+="pass=$current_pass_count, " |
| 193 |
issue_info+="fail=$current_fail_count, " |
| 194 |
issue_info+="xfail=$current_xfail_count, " |
| 195 |
issue_info+="error=$current_error_count" |
| 196 |
echo -e "\e[1A\e[Kissue: $issue_info" |
| 197 |
echo |
| 198 |
fi |
| 199 |
current_fail_count=0 |
| 200 |
current_xfail_count=0 |
| 201 |
current_pass_count=0 |
| 202 |
current_error_count=0 |
| 203 |
progress_info="current=$current_case, " |
| 204 |
progress_info+="\e[${pass_sgr}mpass=$pass_count\e[0m, " |
| 205 |
progress_info+="\e[${fail_sgr}mfail=$fail_count\e[0m, " |
| 206 |
progress_info+="xfail=$xfail_count, " |
| 207 |
progress_info+="\e[${error_sgr}merror=$error_count\e[0m" |
| 208 |
echo -e "\e[1A\e[Kprogress: $progress_info" |
| 209 |
fi |
| 210 |
done & |
| 211 |
|
| 212 |
# ensure log analysis is stopped when script finishes or if aborted |
| 213 |
trap 'kill $! 2>/dev/null' EXIT |
| 214 |
fi |
| 215 |
|
| 216 |
export RUNTESTFLAGS='-v -v >/dev/null 2>&1' |
| 217 |
$make $target |
| 218 |
ret=$? |
| 219 |
|
| 220 |
if [ -t 1 ]; then |
| 221 |
kill $! |
| 222 |
fi |
| 223 |
|
| 224 |
# highlight failed tests |
| 225 |
retreview=0 |
| 226 |
if [ -e $testserie.log ]; then |
| 227 |
script/mtreview $testserie.log |
| 228 |
retreview+=$? |
| 229 |
fi |
| 230 |
|
| 231 |
# testsuite ok but mtreview failed to run |
| 232 |
if [ $ret -eq 0 ] && [ $retreview -ne 0 ]; then |
| 233 |
ret=$retreview |
| 234 |
fi |
| 235 |
|
| 236 |
exit $ret |
| 237 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |