| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# MT, run all or specific parts of the test suite |
| 4 |
# Copyright (C) 2018-2026 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 |
comp Test shell completion scripts |
| 36 |
cook Test the cookbook recipes documented in doc/source/cookbook |
| 37 |
|
| 38 |
Select parts of testsuite: |
| 39 |
serienum Identification number of testsuite directory containing a |
| 40 |
series of testfile (e.g., '50' for modules.50-cmds dir.) |
| 41 |
testfilenum Identification number of testfile in a testserie (e.g., |
| 42 |
'370' for 370-variant.exp testfile in modules.70-maint dir.) |
| 43 |
|
| 44 |
Options: |
| 45 |
-h, --help Show this help message and exit |
| 46 |
|
| 47 |
Examples: |
| 48 |
$0 |
| 49 |
$0 quick |
| 50 |
$0 lint |
| 51 |
$0 comp |
| 52 |
$0 cook |
| 53 |
$0 50/37 61 70/{290,440} |
| 54 |
" |
| 55 |
} |
| 56 |
|
| 57 |
# print message on stderr then exit |
| 58 |
echo_error() { |
| 59 |
echo -e "ERROR: $1" >&2 |
| 60 |
exit 1 |
| 61 |
} |
| 62 |
|
| 63 |
# process log file to highlight failed tests |
| 64 |
review_log() { |
| 65 |
if [ -e $testserie.log ]; then |
| 66 |
script/mtreview $testserie.log |
| 67 |
fi |
| 68 |
} |
| 69 |
|
| 70 |
if [ ! -e tcl/main.tcl.in ]; then |
| 71 |
echo_error "Not in correct directory" |
| 72 |
fi |
| 73 |
|
| 74 |
# make bin, should use GNU make |
| 75 |
if command -v gmake >/dev/null; then |
| 76 |
make='gmake' |
| 77 |
else |
| 78 |
make='make' |
| 79 |
fi |
| 80 |
|
| 81 |
# make target |
| 82 |
target='test' |
| 83 |
testserie='modules' |
| 84 |
setuptestfiles=(00/005 00/006 00/010 00/050 00/060 00/080 00/085) |
| 85 |
if [ $# -gt 0 ]; then |
| 86 |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then |
| 87 |
echo_usage |
| 88 |
exit 0 |
| 89 |
elif [ "$1" = "modules" ]; then |
| 90 |
target='test' |
| 91 |
testserie='modules' |
| 92 |
shift |
| 93 |
elif [ "$1" = "quick" ]; then |
| 94 |
export QUICKTEST=1 |
| 95 |
shift |
| 96 |
elif [ "$1" = "cov" ]; then |
| 97 |
export COVERAGE=y |
| 98 |
shift |
| 99 |
elif [ "$1" = "install" ]; then |
| 100 |
target='testinstall' |
| 101 |
testserie='install' |
| 102 |
setuptestfiles=(00/005 00/006 00/010 00/011) |
| 103 |
shift |
| 104 |
elif [ "$1" = "lint" ]; then |
| 105 |
target='testlint' |
| 106 |
testserie='lint' |
| 107 |
setuptestfiles=(00/005 00/006 00/011) |
| 108 |
shift |
| 109 |
elif [ "$1" = "comp" ]; then |
| 110 |
target='testcompletion' |
| 111 |
testserie='completion' |
| 112 |
setuptestfiles=(00/005 00/006 00/007 00/008 00/010 00/011 00/020 00/030 00/040 00/050) |
| 113 |
shift |
| 114 |
elif [ "$1" = "cook" ]; then |
| 115 |
target='testcookbook' |
| 116 |
testserie='cookbook' |
| 117 |
setuptestfiles=(00/005 00/006 00/010 00/011) |
| 118 |
shift |
| 119 |
fi |
| 120 |
fi |
| 121 |
|
| 122 |
if [ $# -gt 0 ]; then |
| 123 |
# build list of test files to run test on |
| 124 |
declare -a testfiles |
| 125 |
for i in "${setuptestfiles[@]}" "${@}"; do |
| 126 |
j=${i##*/} |
| 127 |
i=${i%/*} |
| 128 |
|
| 129 |
# add all test files if passed a full section number or a test file |
| 130 |
# from collection section (this section must be run entirely) |
| 131 |
if [ "$j" == "$i" ] || [ "$i" == "61" ]; then |
| 132 |
testfiles+=(testsuite/"$testserie.${i}"*/*.exp) |
| 133 |
else |
| 134 |
testfiles+=(testsuite"/$testserie.${i}"*/{010,999,$j}*.exp) |
| 135 |
fi |
| 136 |
done |
| 137 |
|
| 138 |
# get file name of selected test files (runtest requires .exp file name) |
| 139 |
declare -a testfnames=() |
| 140 |
for i in "${testfiles[@]}"; do |
| 141 |
if [ -e "$i" ]; then |
| 142 |
fname=${i##*/} |
| 143 |
# build list of unique file names |
| 144 |
if [ ${#testfnames[@]} -eq 0 ]\ |
| 145 |
|| [[ ! " ${testfnames[*]} " == *" $fname "* ]]; then |
| 146 |
testfnames+=("$fname") |
| 147 |
fi |
| 148 |
fi |
| 149 |
done |
| 150 |
|
| 151 |
# pass list to make target |
| 152 |
export RUNTESTFILES="${testfnames[*]}" |
| 153 |
fi |
| 154 |
|
| 155 |
# attempt to get enhanced diff tool but disable this retrieval if download |
| 156 |
# tentative fails |
| 157 |
if [ ! -e .noicdiff ]; then |
| 158 |
$make icdiff || touch .noicdiff |
| 159 |
fi |
| 160 |
|
| 161 |
rm -f $testserie.log |
| 162 |
|
| 163 |
if [ -t 1 ]; then |
| 164 |
fail_count=0 |
| 165 |
xfail_count=0 |
| 166 |
pass_count=0 |
| 167 |
error_count=0 |
| 168 |
current_fail_count=0 |
| 169 |
current_xfail_count=0 |
| 170 |
current_pass_count=0 |
| 171 |
current_error_count=0 |
| 172 |
current_case='' |
| 173 |
pass_sgr='1;32;7' |
| 174 |
fail_sgr=0 |
| 175 |
error_sgr=0 |
| 176 |
tail --follow=name --retry --quiet $testserie.log \ |
| 177 |
| while read -r logline; do |
| 178 |
case_changed=0 |
| 179 |
case "$logline" in |
| 180 |
PASS*) |
| 181 |
((pass_count++)) |
| 182 |
((current_pass_count++)) ;; |
| 183 |
FAIL*) |
| 184 |
((fail_count++)) |
| 185 |
((current_fail_count++)) ;; |
| 186 |
XFAIL*) |
| 187 |
((xfail_count++)) |
| 188 |
((current_xfail_count++)) ;; |
| 189 |
ERROR:\ tcl\ error\ sourcing*) |
| 190 |
((error_count++)) |
| 191 |
((current_error_count++)) ;; |
| 192 |
Running*) |
| 193 |
case_raw=${logline/*${testserie}.} |
| 194 |
case_suite=${case_raw:0:2} |
| 195 |
number_raw=${case_raw#*/} |
| 196 |
case_number=${number_raw:0:3} |
| 197 |
previous_case=$current_case |
| 198 |
current_case="$case_suite/$case_number" |
| 199 |
case_changed=1 ;; |
| 200 |
esac |
| 201 |
if [ $error_count -eq 1 ]; then |
| 202 |
pass_sgr=0 |
| 203 |
fail_sgr=0 |
| 204 |
error_sgr='1;35;7' |
| 205 |
elif [ $error_count -eq 0 ] && [ $fail_count -eq 1 ]; then |
| 206 |
pass_sgr=0 |
| 207 |
fail_sgr='1;31;7' |
| 208 |
fi |
| 209 |
if [ $case_changed -eq 1 ] ; then |
| 210 |
if [ $current_fail_count -ne 0 ] || [ $current_xfail_count -ne 0 ]\ |
| 211 |
|| [ $current_error_count -ne 0 ]; then |
| 212 |
issue_info="case=$previous_case, " |
| 213 |
issue_info+="pass=$current_pass_count, " |
| 214 |
issue_info+="fail=$current_fail_count, " |
| 215 |
issue_info+="xfail=$current_xfail_count, " |
| 216 |
issue_info+="error=$current_error_count" |
| 217 |
echo -e "\e[1A\e[Kissue: $issue_info" |
| 218 |
echo |
| 219 |
fi |
| 220 |
current_fail_count=0 |
| 221 |
current_xfail_count=0 |
| 222 |
current_pass_count=0 |
| 223 |
current_error_count=0 |
| 224 |
progress_info="current=$current_case, " |
| 225 |
progress_info+="\e[${pass_sgr}mpass=$pass_count\e[0m, " |
| 226 |
progress_info+="\e[${fail_sgr}mfail=$fail_count\e[0m, " |
| 227 |
progress_info+="xfail=$xfail_count, " |
| 228 |
progress_info+="\e[${error_sgr}merror=$error_count\e[0m" |
| 229 |
echo -e "\e[1A\e[Kprogress: $progress_info" |
| 230 |
fi |
| 231 |
done & |
| 232 |
|
| 233 |
# ensure log analysis is stopped when script finishes or if aborted |
| 234 |
trap 'kill $! 2>/dev/null' EXIT |
| 235 |
fi |
| 236 |
|
| 237 |
# parse errors in log even if full run is aborted |
| 238 |
trap 'review_log && exit 1' SIGINT |
| 239 |
|
| 240 |
export RUNTESTFLAGS='-v -v >/dev/null 2>&1' |
| 241 |
$make $target |
| 242 |
ret=$? |
| 243 |
|
| 244 |
if [ -t 1 ]; then |
| 245 |
kill $! |
| 246 |
fi |
| 247 |
|
| 248 |
# highlight failed tests |
| 249 |
review_log |
| 250 |
retreview=$? |
| 251 |
|
| 252 |
# testsuite ok but mtreview failed to run |
| 253 |
if [ $ret -eq 0 ] && [ $retreview -ne 0 ]; then |
| 254 |
ret=$retreview |
| 255 |
fi |
| 256 |
|
| 257 |
exit $ret |
| 258 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |