mirror of
https://github.com/golang/go
synced 2024-11-13 18:10:24 -07:00
f861c7f61b
message with the full path of the errchk script. Catch that by wrapping the if statement which invokes the compiler in a subshell. Use the $TMPOUT file as a flag to let the main shell know whether the subshell ran. Since the compiler stdout and stderr are redirected, if the if statement produces any output, then the compiler crashed, and we report that. R=r,rsc DELTA=14 (11 added, 1 deleted, 2 changed) OCL=33690 CL=33692
91 lines
2.6 KiB
Bash
Executable File
91 lines
2.6 KiB
Bash
Executable File
#!/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-$$
|
|
TMPBUG=/tmp/errchk-bug-$$
|
|
|
|
rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG
|
|
|
|
trap "rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG" 0 1 2 3 14 15
|
|
|
|
(if $* >$TMPOUT 2>$TMPERR; then
|
|
echo 1>&4 "BUG: errchk: command succeeded unexpectedly"
|
|
cat 1>&3 $TMPOUT
|
|
cat 1>&4 $TMPERR
|
|
rm -f $TMPOUT $TMPERR
|
|
fi) 3>&1 4>&2 >$TMPTMP 2>&1
|
|
|
|
if ! test -f $TMPOUT; then
|
|
exit 0
|
|
fi
|
|
|
|
if test -s $TMPTMP; then
|
|
echo 1>&2 BUG: errchk: compiler crashed
|
|
cat $TMPOUT
|
|
cat 1>&2 $TMPERR
|
|
exit 0
|
|
fi
|
|
|
|
cat $TMPOUT $TMPERR | grep -v '^ ' > $TMPALL
|
|
|
|
bug() {
|
|
if ! test -f $TMPBUG
|
|
then
|
|
echo 1>&2 -n BUG: ''
|
|
echo >$TMPBUG
|
|
fi
|
|
}
|
|
|
|
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
|
|
bug
|
|
echo 1>&2 "errchk: $SOURCEFILE:$lineno: missing expected error: '$regexp'"
|
|
elif ! echo "$errmsg" | egrep -q "$regexp"; then
|
|
bug
|
|
echo 1>&2 "errchk: $SOURCEFILE:$lineno: error message does not match '$regexp'"
|
|
echo 1>&2 $errmsg
|
|
fi
|
|
done
|
|
|
|
if test -s $TMPALL; then
|
|
bug
|
|
echo 1>&2 "errchk: $SOURCEFILE: unmatched error messages:"
|
|
echo 1>&2 "=================================================="
|
|
cat 1>&2 $TMPALL
|
|
echo 1>&2 "=================================================="
|
|
fi
|
|
|
|
exit 0
|