2008-09-19 15:39:49 -06:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# This script checks that the compilers emits the errors which we
|
|
|
|
# expect. Usage: errchk COMPILER [OPTS] SOURCEFILE. This will run
|
|
|
|
# the command COMPILER [OPTS] SOURCEFILE. The compilation is expected
|
|
|
|
# to fail; if it succeeds, this script will report an error. The
|
|
|
|
# stderr output of the compiler will be matched against comments in
|
|
|
|
# SOURCEFILE. For each line of the source file which should generate
|
|
|
|
# an error, there should be a comment of the form // ERROR "regexp".
|
|
|
|
# If the compiler generates an error for a line which has no such
|
|
|
|
# commnt, this script will report an error. Likewise if the compiler
|
|
|
|
# does not generate an error for a line which has a comment, or if the
|
|
|
|
# error message does not match the <regexp>. The <regexp> is
|
|
|
|
# interpreted by egrep.
|
|
|
|
|
|
|
|
if test $# -lt 2; then
|
|
|
|
echo 1>&2 "Usage: errchk COMPILER [OPTS] SOURCEFILE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ARGCOUNT=$#
|
|
|
|
SOURCEFILE=${!ARGCOUNT}
|
|
|
|
|
|
|
|
TMPOUT=/tmp/errchk-out-$$
|
|
|
|
TMPERR=/tmp/errchk-err-$$
|
|
|
|
TMPALL=/tmp/errchk-all-$$
|
|
|
|
TMPTMP=/tmp/errchk-tmp-$$
|
2008-10-30 13:43:32 -06:00
|
|
|
TMPBUG=/tmp/errchk-bug-$$
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-07-30 17:46:14 -06:00
|
|
|
rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG
|
2008-10-30 13:43:32 -06:00
|
|
|
|
2009-07-30 17:46:14 -06:00
|
|
|
trap "rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG" 0 1 2 3 14 15
|
2008-09-19 15:39:49 -06:00
|
|
|
|
|
|
|
if $* >$TMPOUT 2>$TMPERR; then
|
2009-07-21 20:45:06 -06:00
|
|
|
echo 1>&2 "BUG: errchk: command succeeded unexpectedly"
|
2008-09-19 15:39:49 -06:00
|
|
|
cat $TMPOUT
|
|
|
|
cat 1>&2 $TMPERR
|
|
|
|
rm -f $TMPOUT $TMPERR
|
2009-07-30 17:46:14 -06:00
|
|
|
exit 0
|
2008-09-19 15:39:49 -06:00
|
|
|
fi
|
|
|
|
|
2008-10-16 16:59:31 -06:00
|
|
|
cat $TMPOUT $TMPERR | grep -v '^ ' > $TMPALL
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2008-10-17 08:41:18 -06:00
|
|
|
bug() {
|
2008-10-30 13:43:32 -06:00
|
|
|
if ! test -f $TMPBUG
|
2008-10-17 08:41:18 -06:00
|
|
|
then
|
|
|
|
echo 1>&2 -n BUG: ''
|
2008-10-30 13:43:32 -06:00
|
|
|
echo >$TMPBUG
|
2008-10-17 08:41:18 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-09-19 15:39:49 -06:00
|
|
|
header=0
|
|
|
|
pr -n -t $SOURCEFILE | grep '// ERROR' | while read line; do
|
|
|
|
lineno=`echo $line | sed -e 's/^[ ]*\([0-9]*\).*$/\1/'`
|
|
|
|
regexp=`echo $line | sed -e 's|.*// ERROR "\([^"]*\)".*$|\1|'`
|
|
|
|
errmsg=`grep "$SOURCEFILE:$lineno" <$TMPALL`
|
|
|
|
grep -v "$SOURCEFILE:$lineno" < $TMPALL > $TMPTMP
|
|
|
|
mv -f $TMPTMP $TMPALL
|
|
|
|
if test -z "$errmsg"; then
|
2008-10-17 08:41:18 -06:00
|
|
|
bug
|
2009-03-12 20:04:38 -06:00
|
|
|
echo 1>&2 "errchk: $SOURCEFILE:$lineno: missing expected error: '$regexp'"
|
2008-09-19 15:39:49 -06:00
|
|
|
elif ! echo "$errmsg" | egrep -q "$regexp"; then
|
2008-10-17 08:41:18 -06:00
|
|
|
bug
|
2009-03-12 20:04:38 -06:00
|
|
|
echo 1>&2 "errchk: $SOURCEFILE:$lineno: error message does not match '$regexp'"
|
2008-09-19 15:39:49 -06:00
|
|
|
echo 1>&2 $errmsg
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test -s $TMPALL; then
|
2008-10-17 08:41:18 -06:00
|
|
|
bug
|
|
|
|
echo 1>&2 "errchk: $SOURCEFILE: unmatched error messages:"
|
2008-09-19 15:39:49 -06:00
|
|
|
echo 1>&2 "=================================================="
|
|
|
|
cat 1>&2 $TMPALL
|
|
|
|
echo 1>&2 "=================================================="
|
|
|
|
fi
|
|
|
|
|
2009-07-30 17:46:14 -06:00
|
|
|
exit 0
|