2 # Check GNU m4 against examples from the manual source.
3 # Copyright (C) 1992, 2006, 2007 Free Software Foundation, Inc.
5 # Sanity check what we are testing
8 # Clean up temp files on exit
11 trap 'stat=$?; cd "$pwd"; rm -rf $tmp && exit $stat' 0
12 trap '(exit $?); exit $?' 1 2 13 15
16 mkdir
$tmp || framework_failure
=1
18 if test $framework_failure = 1; then
19 echo "$0: failure in testing framework" 1>&2
32 # Find out how the executable prints argv[0]
33 m4=`m4 --help | sed -e 's/Usage: \(.*\) \[OPTION.*/\1/' \
34 -e 's/\\\\/\\\\\\\\/g' -e 1q`
36 # Find out if we should strip \r in the output
38 m4 --version |
tr -d '\015' > $xout
39 if cmp -s $out $xout; then
42 echo "Ignoring carriage returns"
46 # Find out where the examples live.
48 if test "x$1" = x-I
; then
53 # Find out if diff supports useful options.
54 if diff -u /dev
/null
/dev
/null
2>/dev
/null
; then
57 if diff -a /dev
/null
/dev
/null
2>/dev
/null
; then
58 diffopts
="$diffopts -a"
65 echo "No such file: $file"
69 options
=`sed -ne '3s/^dnl @ extra options: //p;3q' "$file"`
70 sed -e '/^dnl @/d' -e '/^\^D$/q' "$file" \
71 | LC_MESSAGES
=C
m4 -d -I "$examples" $options - >$out 2>$err
74 xstat
=`sed -ne '2s/^dnl @ expected status: //p;2q' "$file"`
77 skipped
="$skipped $file"
83 failed
="$failed $file:status"
84 echo `sed -e 's/^dnl //' -e 1q $file`
85 echo "$file: status was $stat, expected $xstat"
89 xoutfile
=`sed -n 's/^dnl @ expected output: //p' "$file"`
90 if test -z "$xoutfile" ; then
91 sed -e '/^dnl @result{}/!d' -e 's///' -e "s|\.\./examples|$examples|" \
94 cp "$examples/$xoutfile" $xout
97 xerrfile
=`sed -n 's/^dnl @ expected error: //p' "$file"`
98 if test -z "$xerrfile" ; then
99 sed -e '/^dnl @error{}/!d' -e 's///' -e "s|^m4:|$m4:|" "$file" > $xerr
101 cp "$examples/$xerrfile" $xerr
104 # For the benefit of mingw, normalize \r\n line endings
105 if $strip_needed ; then
106 tr -d '\015' < $out > $out.t
108 tr -d '\015' < $xout > $xout.t
110 tr -d '\015' < $err > $err.t
112 tr -d '\015' < $xerr > $xerr.t
116 if cmp -s $out $xout; then
119 failed
="$failed $file:out"
120 echo `sed -e 's/^dnl //' -e 1q $file`
121 echo "$file: stdout mismatch"
122 diff $diffopts $xout $out
125 if cmp -s $err $xerr; then
128 failed
="$failed $file:err"
129 echo `sed -e 's/^dnl //' -e 1q $file`
130 echo "$file: stderr mismatch"
131 diff $diffopts $xerr $err
136 rm -f $out $err $xout $xerr
139 if test -n "$skipped"; then
140 echo "Skipped checks were:"
143 if test -z "$failed"; then
144 echo "All checks successful"
147 echo "Failed checks were:"
151 (exit $stat); exit $stat