3 # Copyright (C) 2005-2015, 2018-2022 Free Software Foundation, Inc.
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.
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.
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/>.
21 me
=$
(basename "$1" .
test)
22 medir
=$
(dirname "$1" |
sed -e 's,.*examples/,,')
24 # Number of the current test.
27 # Exit status of this script.
33 # Whether to strip '> ...' lines from the expected output.
34 # See bistromathic.test.
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..."
41 if diff --strip-trailing-cr "$1" "$1"; then
42 diff_opts
=--strip-trailing-cr
44 echo "checking for diff --strip-trailing-cr... $diff_opts"
46 # The exercised program.
47 abs_medir
=$cwd/examples
/$medir
48 if test -x "$abs_medir/$me"; then
53 elif test -f "$abs_medir/$me.class"; then
56 "$SHELL" "$cwd/javaexec.sh" -cp "$abs_medir" "$me" "$@"
59 echo "$me: ERROR: cannot find program to exercise in:"
60 echo "$me: ERROR: $cwd/examples/$medir/$me"
70 if test -z "$DEBUG"; then
76 trap cleanup
0 1 2 13 15
86 if test x
"$1" != x
; then
89 # See Autoconf's doc on 'trap'.
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.
106 (-n) echo=printf; shift;;
107 (-noerr) noerr
=true
; shift;;
108 (-t) rstrip
=true
; shift;;
113 # Expected exit status.
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'
128 # Effective exit status.
131 prog
"$@" - <input
>out_eff
2>err_eff || sta_eff
=$?
133 # Combine effective output and error streams.
136 sed -e 's/ *$//g' out_eff
140 # Ignore informational messages from the JVM.
143 -e '/^Picked up _JAVA_OPTIONS: /d' \
144 -e 's/Reducing stack by rule .* (line .*):/Reducing stack by rule XX (line XXX):/g' \
150 if test $sta_eff -eq $sta_exp; then
151 if diff $diff_opts eff exp
>/dev
/null
2>&1; then
152 echo "$me: PASS: $number"
154 echo "$me: FAIL: $number"
156 sed -e 's/^/ /' input
157 echo "$me: expected output:"
159 echo "$me: effective output:"
162 diff $diff_opts -u exp eff |
sed -e 's/^/ /'
166 echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
170 number
=$
(expr $number + 1)
173 # We have cd'd one level deeper.
175 /*) .
"$1" || status
=2;;
176 *) .
"../$1" || status
=2;;