| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# Copyright (C) 2005-2015, 2018-2021 Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
SHELL=/bin/sh |
| 19 |
export SHELL |
| 20 |
|
| 21 |
me=$(basename "$1" .test) |
| 22 |
medir=$(dirname "$1" | sed -e 's,.*examples/,,') |
| 23 |
|
| 24 |
# Number of the current test. |
| 25 |
number=1 |
| 26 |
|
| 27 |
# Exit status of this script. |
| 28 |
status=0 |
| 29 |
|
| 30 |
# top_builddir. |
| 31 |
cwd=$(pwd) |
| 32 |
|
| 33 |
# Whether to strip '> ...' lines from the expected output. |
| 34 |
# See bistromathic.test. |
| 35 |
strip_prompt=false |
| 36 |
|
| 37 |
# If diff supports --strip-trailing-cr, use it, to avoid EOL issues |
| 38 |
# when testing Java programs on Windows. |
| 39 |
echo "checking for diff --strip-trailing-cr..." |
| 40 |
diff_opts= |
| 41 |
if diff --strip-trailing-cr "$1" "$1"; then |
| 42 |
diff_opts=--strip-trailing-cr |
| 43 |
fi |
| 44 |
echo "checking for diff --strip-trailing-cr... $diff_opts" |
| 45 |
|
| 46 |
# The exercised program. |
| 47 |
abs_medir=$cwd/examples/$medir |
| 48 |
if test -x "$abs_medir/$me"; then |
| 49 |
prog () |
| 50 |
{ |
| 51 |
"$abs_medir/$me" "$@" |
| 52 |
} |
| 53 |
elif test -f "$abs_medir/$me.class"; then |
| 54 |
prog () |
| 55 |
{ |
| 56 |
"$SHELL" "$cwd/javaexec.sh" -cp "$abs_medir" "$me" "$@" |
| 57 |
} |
| 58 |
else |
| 59 |
echo "$me: ERROR: cannot find program to exercise in:" |
| 60 |
echo "$me: ERROR: $cwd/examples/$medir/$me" |
| 61 |
exit 1 |
| 62 |
fi |
| 63 |
|
| 64 |
|
| 65 |
# cleanup |
| 66 |
# ------- |
| 67 |
cleanup () |
| 68 |
{ |
| 69 |
status=$? |
| 70 |
if test -z "$DEBUG"; then |
| 71 |
cd "$cwd" |
| 72 |
rm -rf $$.dir |
| 73 |
fi |
| 74 |
exit $status |
| 75 |
} |
| 76 |
trap cleanup 0 1 2 13 15 |
| 77 |
mkdir $$.dir |
| 78 |
cd $$.dir |
| 79 |
|
| 80 |
|
| 81 |
# skip [MSG] |
| 82 |
# ---------- |
| 83 |
# Skip this test. |
| 84 |
skip () |
| 85 |
{ |
| 86 |
if test x"$1" != x; then |
| 87 |
echo "SKIP: $1" |
| 88 |
fi |
| 89 |
# See Autoconf's doc on 'trap'. |
| 90 |
(exit 77); exit 77 |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
# run [-n, -noerr, -t] EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS] |
| 95 |
# -------------------------------------------------------------------------- |
| 96 |
# -n: no final end-of-line in expected-output |
| 97 |
# -noerr: ignore stderr, otherwise merge it into effective output. |
| 98 |
# -t: nuke the possible trailing white spaces in the effective output. |
| 99 |
run () |
| 100 |
{ |
| 101 |
echo=echo |
| 102 |
noerr=false |
| 103 |
rstrip=false |
| 104 |
while true; do |
| 105 |
case $1 in |
| 106 |
(-n) echo=printf; shift;; |
| 107 |
(-noerr) noerr=true; shift;; |
| 108 |
(-t) rstrip=true; shift;; |
| 109 |
(*) break;; |
| 110 |
esac |
| 111 |
done |
| 112 |
|
| 113 |
# Expected exit status. |
| 114 |
sta_exp=$1 |
| 115 |
shift |
| 116 |
|
| 117 |
# Expected output. |
| 118 |
$echo "$1" | |
| 119 |
sed -e 's/Reducing stack by rule .* (line .*):/Reducing stack by rule XX (line XXX):/g' | |
| 120 |
if $strip_prompt; then |
| 121 |
# An extra EOL added in bistromathic's main. Keep that empty line. |
| 122 |
sed -e '/^> ./d;s/^> $//g' |
| 123 |
else |
| 124 |
cat |
| 125 |
fi >exp |
| 126 |
shift |
| 127 |
|
| 128 |
# Effective exit status. |
| 129 |
sta_eff=0 |
| 130 |
|
| 131 |
prog "$@" - <input >out_eff 2>err_eff || sta_eff=$? |
| 132 |
|
| 133 |
# Combine effective output and error streams. |
| 134 |
{ |
| 135 |
if $rstrip; then |
| 136 |
sed -e 's/ *$//g' out_eff |
| 137 |
else |
| 138 |
cat out_eff |
| 139 |
fi |
| 140 |
if ! $noerr; then |
| 141 |
sed -e 's/^/err: /g' \ |
| 142 |
-e 's/Reducing stack by rule .* (line .*):/Reducing stack by rule XX (line XXX):/g' \ |
| 143 |
err_eff |
| 144 |
fi |
| 145 |
} >eff |
| 146 |
|
| 147 |
if test $sta_eff -eq $sta_exp; then |
| 148 |
if diff $diff_opts eff exp >/dev/null 2>&1; then |
| 149 |
echo "$me: PASS: $number" |
| 150 |
else |
| 151 |
echo "$me: FAIL: $number" |
| 152 |
echo "$me: input:" |
| 153 |
sed -e 's/^/ /' input |
| 154 |
echo "$me: expected output:" |
| 155 |
sed -e 's/^/ /' exp |
| 156 |
echo "$me: effective output:" |
| 157 |
sed -e 's/^/ /' eff |
| 158 |
echo "$me: diff:" |
| 159 |
diff $diff_opts -u exp eff | sed -e 's/^/ /' |
| 160 |
status=1 |
| 161 |
fi |
| 162 |
else |
| 163 |
echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)" |
| 164 |
cat err_eff |
| 165 |
status=1 |
| 166 |
fi |
| 167 |
number=$(expr $number + 1) |
| 168 |
} |
| 169 |
|
| 170 |
# We have cd'd one level deeper. |
| 171 |
case $1 in |
| 172 |
/*) . "$1" || status=2;; |
| 173 |
*) . "../$1" || status=2;; |
| 174 |
esac |
| 175 |
|
| 176 |
exit $status |