| 1 |
#! /bin/sh |
| 2 |
# Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2, or (at your option) |
| 7 |
# any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
# |
| 18 |
# Test driver for a very simple test protocol used by the Automake |
| 19 |
# testsuite to check support for custom test drivers allowing for more |
| 20 |
# test results per test script. |
| 21 |
# |
| 22 |
# The exit status of the wrapped script is ignored. Lines in its stdout |
| 23 |
# and stderr beginning with 'PASS', 'FAIL', 'XFAIL', 'XPASS', 'SKIP' or |
| 24 |
# 'ERROR' count as a test case result with the obviously-corresponding |
| 25 |
# outcome. Every other line is ignored for what concerns the testsuite |
| 26 |
# outcome. |
| 27 |
# |
| 28 |
# This script is used at least by the 'driver-custom-multitest*.test' |
| 29 |
# tests. |
| 30 |
# |
| 31 |
|
| 32 |
# Help to avoid typo-related bugs. |
| 33 |
set -u |
| 34 |
|
| 35 |
## Option parsing. |
| 36 |
|
| 37 |
test_name=INVALID.NAME |
| 38 |
log_file=BAD.LOG |
| 39 |
trs_file=BAD.TRS |
| 40 |
while test $# -gt 0; do |
| 41 |
case $1 in |
| 42 |
--test-name) test_name=$2; shift;; |
| 43 |
--log-file) log_file=$2; shift;; |
| 44 |
--trs-file) trs_file=$2; shift;; |
| 45 |
# Ignored. |
| 46 |
--expect-failure) shift;; |
| 47 |
--color-tests) shift;; |
| 48 |
--enable-hard-errors) shift;; |
| 49 |
# Explicitly terminate option list. |
| 50 |
--) shift; break;; |
| 51 |
# Shouldn't happen |
| 52 |
*) echo "$0: invalid option/argument: '$1'" >&2; exit 2;; |
| 53 |
esac |
| 54 |
shift |
| 55 |
done |
| 56 |
|
| 57 |
## Log file header. |
| 58 |
{ |
| 59 |
echo "RUN: $test_name" |
| 60 |
echo "RUN: $test_name" | sed 's/./=/g' |
| 61 |
echo |
| 62 |
} > $log_file |
| 63 |
|
| 64 |
## Run the test script, get test cases results, display them on console. |
| 65 |
|
| 66 |
"$@" 2>&1 | tee -a $log_file | ( |
| 67 |
i=0 st=0 |
| 68 |
exec 5> $trs_file |
| 69 |
while read line; do |
| 70 |
result= |
| 71 |
case $line in |
| 72 |
PASS:*) result=PASS ;; |
| 73 |
FAIL:*) result=FAIL ;; |
| 74 |
XPASS:*) result=XPASS ;; |
| 75 |
XFAIL:*) result=XFAIL ;; |
| 76 |
SKIP:*) result=SKIP ;; |
| 77 |
ERROR:*) result=ERROR ;; |
| 78 |
esac |
| 79 |
if test -n "$result"; then |
| 80 |
case $result in FAIL|XPASS|ERROR) st=1;; esac |
| 81 |
# Output testcase result to console. |
| 82 |
echo "$result: $test_name" |
| 83 |
# Register testcase outcome for the log file. |
| 84 |
echo ":test-result: $line" >&5 |
| 85 |
echo >&5 |
| 86 |
fi |
| 87 |
done |
| 88 |
if test $st -eq 0; then |
| 89 |
recheck=no |
| 90 |
copy_in_global_log=no |
| 91 |
else |
| 92 |
recheck=yes |
| 93 |
copy_in_global_log=yes |
| 94 |
fi |
| 95 |
echo ":recheck: $recheck" >&5 |
| 96 |
echo ":copy-in-global-log: $copy_in_global_log" >&5 |
| 97 |
exec 5>&- |
| 98 |
) | awk '{ print $0 ", testcase " NR }' |
| 99 |
|
| 100 |
## And we're done. |
| 101 |
|
| 102 |
exit 0 |