summaryrefslogtreecommitdiff
path: root/test/errchk
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-09 00:39:32 -0700
committerRuss Cox <rsc@golang.org>2009-10-09 00:39:32 -0700
commit44d62180abb9f6865be919fc04f575f1fb7d5791 (patch)
tree93644a8af0089ade1ce44fa23775aa28384d2126 /test/errchk
parent4d63548cffa90abbf6ff8ef6a6668ef388f0e597 (diff)
downloadgo-44d62180abb9f6865be919fc04f575f1fb7d5791.tar.gz
rewrite errchk in perl for speed (compared to bash)
R=iant DELTA=125 (51 added, 53 deleted, 21 changed) OCL=35508 CL=35511
Diffstat (limited to 'test/errchk')
-rwxr-xr-xtest/errchk126
1 files changed, 62 insertions, 64 deletions
diff --git a/test/errchk b/test/errchk
index c1183868f..0625dbca1 100755
--- a/test/errchk
+++ b/test/errchk
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/perl
# 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.
@@ -13,78 +13,76 @@
# 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.
+# error message does not match the <regexp>. The <regexp> syntax
+# is Perl but its best to stick to egrep.
-if test $# -lt 2; then
- echo 1>&2 "Usage: errchk COMPILER [OPTS] SOURCEFILE"
- exit 1
-fi
+use POSIX;
-ARGCOUNT=$#
-SOURCEFILE=${!ARGCOUNT}
-
-TMPOUT=/tmp/errchk-out-$$
-TMPERR=/tmp/errchk-err-$$
-TMPALL=/tmp/errchk-all-$$
-TMPTMP=/tmp/errchk-tmp-$$
-TMPBUG=/tmp/errchk-bug-$$
+if(@ARGV < 1) {
+ print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILE\n";
+ exit 1;
+}
-rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG
+$file = $ARGV[@ARGV-1];
+open(SRC, $file) || die "BUG: errchk: open $file: $!";
+@src = <SRC>;
+close(SRC);
-trap "rm -f $TMPOUT $TMPERR $TMPALL $TMPTMP $TMPBUG" 0 1 2 3 14 15
+# Run command
+$cmd = join(' ', @ARGV);
+open(CMD, "$cmd </dev/null 2>&1 |") || die "BUG: errchk: run $cmd: $!";
+@out = grep { !/^ / } <CMD>;
+close CMD;
-(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($? == 0) {
+ print STDERR "BUG: errchk: command succeeded unexpectedly\n";
+ print STDERR @out;
+ exit 0;
+}
-if ! test -f $TMPOUT; then
- exit 0
-fi
+if(!WIFEXITED($?)) {
+ print STDERR "BUG: errchk: compiler crashed\n";
+ exit 0;
+}
-if test -s $TMPTMP; then
- echo 1>&2 BUG: errchk: compiler crashed
- cat $TMPOUT
- cat 1>&2 $TMPERR
- exit 0
-fi
+sub bug() {
+ if(!$bug++) {
+ print STDERR "BUG: ";
+ }
+}
-cat $TMPOUT $TMPERR | grep -v '^ ' > $TMPALL
+$line = 0;
+foreach $src (@src) {
+ $line++;
+ next unless $src =~ m|// ERROR (.*)|;
+ $regexp = $1;
+ if($regexp !~ /^"([^"]*)"/) {
+ print STDERR "$file:$line: malformed regexp\n";
+ next;
+ }
+ $regexp = $1;
-bug() {
- if ! test -f $TMPBUG
- then
- echo 1>&2 -n BUG: ''
- echo >$TMPBUG
- fi
+ @errmsg = grep { /$file:$line:/ } @out;
+ @out = grep { !/$file:$line:/ } @out;
+ if(@errmsg == 0) {
+ bug();
+ print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n";
+ next;
+ }
+ @match = grep { /$regexp/ } @errmsg;
+ if(@match == 0) {
+ bug();
+ print STDERR "errchk: $file:$line: error message does not match '$regexp'\n";
+ next;
+ }
}
-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
+if(@out != 0) {
+ bug();
+ print STDERR "errchk: $file: unmatched error messages:\n";
+ print STDERR "==================================================\n";
+ print STDERR @out;
+ print STDERR "==================================================\n";
+}
-exit 0
+exit 0;