]> Cypherpunks.ru repositories - gostls13.git/commitdiff
Check for specific error messages in the testsuite. This
authorIan Lance Taylor <iant@golang.org>
Fri, 19 Sep 2008 21:39:49 +0000 (14:39 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 19 Sep 2008 21:39:49 +0000 (14:39 -0700)
permits testing that the compiler emits error messages for
specific lines that match egrep regexps.  The desired error
messages are expressed using comments of the form
// ERROR "regexp"

R=r
DELTA=90  (73 added, 8 deleted, 9 changed)
OCL=15513
CL=15566

test/errchk [new file with mode: 0755]
test/fixedbugs/bug014.go
test/fixedbugs/bug015.go
test/func1.go
test/golden.out
test/run

diff --git a/test/errchk b/test/errchk
new file mode 100755 (executable)
index 0000000..19fa1a5
--- /dev/null
@@ -0,0 +1,74 @@
+#!/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-$$
+TMPSTAT=/tmp/errchk-stat-$$
+rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPSTAT
+
+trap "rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPSTAT" 0 1 2 3 14 15
+
+if $* >$TMPOUT 2>$TMPERR; then
+  echo 1>&2 "errchk: command succeeded unexpectedly: " "$@"
+  cat $TMPOUT
+  cat 1>&2 $TMPERR
+  rm -f $TMPOUT $TMPERR
+  exit 1
+fi
+
+cat $TMPOUT $TMPERR > $TMPALL
+
+header=0
+echo 0 > $TMPSTAT
+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
+    echo 1>&2 "errchk: $SOURCEFILE: missing expected error message on line $lineno: '$regexp'"
+    echo 1 > $TMPSTAT
+  elif ! echo "$errmsg" | egrep -q "$regexp"; then
+    echo 1>&2 "errchk: $SOURCEFILE: error message on line $lineno does not match '$regexp'"
+    echo 1>&2 $errmsg
+    echo 1 > $TMPSTAT
+  fi
+done
+
+if test -s $TMPALL; then
+  echo 1>&2 "errchk: $SOURCEFILE: unmatched error messages:"
+  echo 1>&2 "=================================================="
+  cat 1>&2 $TMPALL
+  echo 1>&2 "=================================================="
+  echo 1 > $TMPSTAT
+fi
+
+status=`cat $TMPSTAT`
+
+exit $status
index 25a8af292f5a3ef9728c7ab6442aab1bf909d3df..dac2ce5174a48c95a377d9adc4a9cdba18f2b1ee 100644 (file)
@@ -7,8 +7,8 @@
 package main
 
 func main() {
-       var c00 uint8 = '\0';  // three octal required; should not compile
-       var c01 uint8 = '\07';  // three octal required; should not compile
-       var cx0 uint8 = '\x0';  // two hex required; should not compile
-       var cx1 uint8 = '\x';  // two hex required; REALLY should not compile
+       var c00 uint8 = '\0';  // ERROR "oct|char"
+       var c01 uint8 = '\07';  // ERROR "oct|char"
+       var cx0 uint8 = '\x0';  // ERROR "hex|char"
+       var cx1 uint8 = '\x';  // ERROR "hex|char"
 }
index cbb9652c06f1efcb76d0b2b0b768803ab33d0c03..9178f626fc7eef8f27a90469a72cda2396d77672 100644 (file)
@@ -8,6 +8,6 @@ package main
 
 func main() {
        var i33 int64;
-       if i33 == (1<<64) -1 {  // BUG: should not compile; constant too large
+       if i33 == (1<<64) -1 {  // ERROR "overflow"
        }
 }
index 895fe94b8d42b2d4ae1196f089ad00d04eac423c..2c767d21d55ea98d22e03c3d0ac2357d0152da76 100644 (file)
@@ -13,6 +13,6 @@ func f1(a int) (int, float) {  // BUG (not caught by compiler): multiple return
 }
 
 
-func f2(a int) (a int, b float) {  // return value names must be different from parameter names
+func f2(a int) (a int, b float) {  // ERROR "redeclared|definition"
        return 8, 8.0;
 }
index 9689f1cb73464b16388210969d36af6ac65df296..66ff71550565e42feb0d78d8f11d1a3bcb33ba7e 100644 (file)
@@ -1,8 +1,4 @@
 
-=========== ./func1.go
-func1.go:12: var a redeclared in this block
-     previous declaration at func1.go:12
-
 =========== ./helloworld.go
 hello, world
 
@@ -201,9 +197,6 @@ pc: 0x2615
        mainĀ·main(0x1, 0x7fff5fbff268, 0x0, ...)
 
 
-=========== fixedbugs/bug015.go
-fixedbugs/bug015.go:7: overflow converting constant to <int64>INT64
-
 =========== fixedbugs/bug016.go
 fixedbugs/bug016.go:7: overflow converting constant to <uint32>UINT32
 
index 8013efe4abaf09de61e7a8f54d3b4e2973d81fd0..dc429dd67b8e13e360f2ba5a299ab22eeaddcda4 100755 (executable)
--- a/test/run
+++ b/test/run
@@ -18,6 +18,8 @@ export L=${A}l
 
 failed=0
 
+PATH=/bin:/usr/bin:$HOME/bin:`pwd`
+
 # don't use $$ in file names to avoid spurious diffs
 RUNFILE=/tmp/gorun-$USER
 TMP1FILE=/tmp/gotest1-$USER