2 # Check GNU m4 against examples from the manual source.
3 # Copyright (C) 1992, 2006-2014, 2016-2017, 2020-2021 Free Software
6 # This file is part of GNU M4.
8 # GNU M4 is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # GNU M4 is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 # Clean up temp files on exit
24 trap 'stat=$?; cd "$pwd"; rm -rf $tmp && exit $stat' 0
25 trap '(exit $?); exit $?' 1 2 13 15
29 mkdir $tmp || framework_failure=1
31 if test $framework_failure = 1; then
32 echo "$0: failure in testing framework" 1>&2
45 # Allow user to select sed
48 # Find out where the examples live.
50 if test "x$1" = x-I ; then
55 # Find out how to run m4.
57 if test "x$1" = x-m ; then
62 # Find out how the executable prints argv[0]
63 m4name=`"$m4" --help | ${SED} -e 's/Usage: \(.*\) \[OPTION.*/\1/' \
64 -e 's/\\\\/\\\\\\\\/g' -e 1q`
66 # Find out if we should strip \r in the output
67 "$m4" --version | tee $out
68 "$m4" --version | tr -d '\015' > $xout
69 if cmp -s $out $xout; then
72 echo "Ignoring carriage returns"
76 # Find out if diff supports useful options.
77 if diff -u /dev/null /dev/null 2>/dev/null ; then
80 if diff -a /dev/null /dev/null 2>/dev/null ; then
81 diffopts="$diffopts -a"
88 echo "No such file: $file"
97 77) skipped="$skipped $file";;
99 *) failed="$failed $file"
104 options=`${SED} -ne '3s/^dnl @ extra options: //p;3q' "$file"`
105 ${SED} -e '/^dnl @/d' -e '/^\^D$/q' "$file" \
106 | LC_MESSAGES=C M4PATH=$examples "$m4" -d $options - >$out 2>$err
109 xstat=`${SED} -ne '2s/^dnl @ expected status: //p;2q' "$file"`
112 skipped="$skipped $file"
118 failed="$failed $file:status"
119 echo `${SED} -e 's/^dnl //' -e 1q $file`
120 echo "$file: status was $stat, expected $xstat"
124 xoutfile=`${SED} -n 's/^dnl @ expected output: //p' "$file"`
125 if test -z "$xoutfile" ; then
126 ${SED} -e '/^dnl @result{}/!d' -e 's///' -e "s|examples/|$examples/|" \
129 cp "$examples/$xoutfile" $xout
132 xerrfile=`${SED} -n 's/^dnl @ expected error: //p' "$file"`
137 ${SED} '/^dnl @error{}/!d
138 s///; '"s|^m4:|$m4name:|; s|examples/|$examples/|" \
141 ${SED} "s|^m4:|$m4name:|; s|examples/|$examples/|" \
142 "$examples/$xerrfile" > $xerr ;;
145 # For the benefit of mingw, normalize \r\n line endings
146 if $strip_needed ; then
147 tr -d '\015' < $out > $out.t
149 tr -d '\015' < $xout > $xout.t
151 tr -d '\015' < $err > $err.t
153 tr -d '\015' < $xerr > $xerr.t
157 if cmp -s $out $xout; then
160 failed="$failed $file:out"
161 echo `${SED} -e 's/^dnl //' -e 1q $file`
162 echo "$file: stdout mismatch"
163 diff $diffopts $xout $out
166 if cmp -s $err $xerr; then
169 failed="$failed $file:err"
170 echo `${SED} -e 's/^dnl //' -e 1q $file`
171 echo "$file: stderr mismatch"
172 diff $diffopts $xerr $err
177 rm -f $out $err $xout $xerr
180 if test -n "$skipped"; then
181 echo "Skipped checks were:"
184 if test -z "$failed"; then
185 echo "All checks successful"
188 echo "Failed checks were:"
192 (exit $stat); exit $stat