2 # Check GNU m4 against examples from the manual source.
3 # Copyright (C) 1992, 2006-2014, 2016 Free Software Foundation, Inc.
5 # This file is part of GNU M4.
7 # GNU M4 is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GNU M4 is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Clean up temp files on exit
23 trap 'stat=$?; cd "$pwd"; rm -rf $tmp && exit $stat' 0
24 trap '(exit $?); exit $?' 1 2 13 15
28 mkdir $tmp || framework_failure=1
30 if test $framework_failure = 1; then
31 echo "$0: failure in testing framework" 1>&2
44 # Allow user to select sed
47 # Find out where the examples live.
49 if test "x$1" = x-I ; then
54 # Find out how to run m4.
56 if test "x$1" = x-m ; then
61 # Find out how the executable prints argv[0]
62 m4name=`"$m4" --help | ${SED} -e 's/Usage: \(.*\) \[OPTION.*/\1/' \
63 -e 's/\\\\/\\\\\\\\/g' -e 1q`
65 # Find out if we should strip \r in the output
66 "$m4" --version | tee $out
67 "$m4" --version | tr -d '\015' > $xout
68 if cmp -s $out $xout; then
71 echo "Ignoring carriage returns"
75 # Find out if diff supports useful options.
76 if diff -u /dev/null /dev/null 2>/dev/null ; then
79 if diff -a /dev/null /dev/null 2>/dev/null ; then
80 diffopts="$diffopts -a"
87 echo "No such file: $file"
96 77) skipped="$skipped $file";;
98 *) failed="$failed $file"
103 options=`${SED} -ne '3s/^dnl @ extra options: //p;3q' "$file"`
104 ${SED} -e '/^dnl @/d' -e '/^\^D$/q' "$file" \
105 | LC_MESSAGES=C M4PATH=$examples "$m4" -d $options - >$out 2>$err
108 xstat=`${SED} -ne '2s/^dnl @ expected status: //p;2q' "$file"`
111 skipped="$skipped $file"
117 failed="$failed $file:status"
118 echo `${SED} -e 's/^dnl //' -e 1q $file`
119 echo "$file: status was $stat, expected $xstat"
123 xoutfile=`${SED} -n 's/^dnl @ expected output: //p' "$file"`
124 if test -z "$xoutfile" ; then
125 ${SED} -e '/^dnl @result{}/!d' -e 's///' -e "s|examples/|$examples/|" \
128 cp "$examples/$xoutfile" $xout
131 xerrfile=`${SED} -n 's/^dnl @ expected error: //p' "$file"`
136 ${SED} '/^dnl @error{}/!d
137 s///; '"s|^m4:|$m4name:|; s|examples/|$examples/|" \
140 ${SED} "s|^m4:|$m4name:|; s|examples/|$examples/|" \
141 "$examples/$xerrfile" > $xerr ;;
144 # For the benefit of mingw, normalize \r\n line endings
145 if $strip_needed ; then
146 tr -d '\015' < $out > $out.t
148 tr -d '\015' < $xout > $xout.t
150 tr -d '\015' < $err > $err.t
152 tr -d '\015' < $xerr > $xerr.t
156 if cmp -s $out $xout; then
159 failed="$failed $file:out"
160 echo `${SED} -e 's/^dnl //' -e 1q $file`
161 echo "$file: stdout mismatch"
162 diff $diffopts $xout $out
165 if cmp -s $err $xerr; then
168 failed="$failed $file:err"
169 echo `${SED} -e 's/^dnl //' -e 1q $file`
170 echo "$file: stderr mismatch"
171 diff $diffopts $xerr $err
176 rm -f $out $err $xout $xerr
179 if test -n "$skipped"; then
180 echo "Skipped checks were:"
183 if test -z "$failed"; then
184 echo "All checks successful"
187 echo "Failed checks were:"
191 (exit $stat); exit $stat