Use fastmaps for better regex performance.
[m4/ericb.git] / checks / check-them
blobdaa1b001f6bcac52fda91a01b5b6de10b2e3ccdb
1 #!/bin/sh
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
6 m4 --version
8 # Clean up temp files on exit
9 pwd=`pwd`
10 tmp=m4-tmp.$$
11 trap 'stat=$?; cd "$pwd"; rm -rf $tmp && exit $stat' 0
12 trap '(exit $?); exit $?' 1 2 13 15
14 # Create scratch dir
15 framework_failure=0
16 mkdir $tmp || framework_failure=1
18 if test $framework_failure = 1; then
19 echo "$0: failure in testing framework" 1>&2
20 (exit 1); exit 1
23 out=$tmp/m4-out
24 err=$tmp/m4-err
25 xout=$tmp/m4-xout
26 xerr=$tmp/m4-xerr
27 failed=
28 skipped=
29 strip_needed=false
30 diffopts=-c
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
37 m4 --version > $out
38 m4 --version | tr -d '\015' > $xout
39 if cmp -s $out $xout; then
41 else
42 echo "Ignoring carriage returns"
43 strip_needed=:
46 # Find out where the examples live.
47 examples=.
48 if test "x$1" = x-I ; then
49 examples="$2"
50 shift; shift
53 # Find out if diff supports useful options.
54 if diff -u /dev/null /dev/null 2>/dev/null ; then
55 diffopts="-u"
57 if diff -a /dev/null /dev/null 2>/dev/null ; then
58 diffopts="$diffopts -a"
61 # Run the tests.
62 for file
64 test -f "$file" || {
65 echo "No such file: $file"
66 continue
68 echo "Checking $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
72 stat=$?
74 xstat=`sed -ne '2s/^dnl @ expected status: //p;2q' "$file"`
75 case $stat in
76 77)
77 skipped="$skipped $file"
78 cat $err
79 continue
81 $xstat) ;;
83 failed="$failed $file:status"
84 echo `sed -e 's/^dnl //' -e 1q $file`
85 echo "$file: status was $stat, expected $xstat"
87 esac
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|" \
92 "$file" > $xout
93 else
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
100 else
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
107 mv $out.t $out
108 tr -d '\015' < $xout > $xout.t
109 mv $xout.t $xout
110 tr -d '\015' < $err > $err.t
111 mv $err.t $err
112 tr -d '\015' < $xerr > $xerr.t
113 mv $xerr.t $xerr
116 if cmp -s $out $xout; then
118 else
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
127 else
128 failed="$failed $file:err"
129 echo `sed -e 's/^dnl //' -e 1q $file`
130 echo "$file: stderr mismatch"
131 diff $diffopts $xerr $err
134 done
136 rm -f $out $err $xout $xerr
138 echo
139 if test -n "$skipped"; then
140 echo "Skipped checks were:"
141 echo " $skipped"
143 if test -z "$failed"; then
144 echo "All checks successful"
145 stat=0
146 else
147 echo "Failed checks were:"
148 echo " $failed"
149 stat=1
151 (exit $stat); exit $stat