1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:54:39 -07:00

errchk: accept multiple source files

R=rsc, iant
CC=golang-dev
https://golang.org/cl/3217042
This commit is contained in:
Eoghan Sherry 2010-12-07 15:28:21 -05:00 committed by Russ Cox
parent 24a78a026d
commit 802360edb4

View File

@ -3,30 +3,38 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# This script checks that the compilers emits the errors which we # This script checks that the compilers emit the errors which we expect.
# expect. Usage: errchk COMPILER [OPTS] SOURCEFILE. This will run # Usage: errchk COMPILER [OPTS] SOURCEFILES. This will run the command
# the command COMPILER [OPTS] SOURCEFILE. The compilation is expected # COMPILER [OPTS] SOURCEFILES. The compilation is expected to fail; if
# to fail; if it succeeds, this script will report an error. The # it succeeds, this script will report an error. The stderr output of
# stderr output of the compiler will be matched against comments in # the compiler will be matched against comments in SOURCEFILES. For each
# SOURCEFILE. For each line of the source file which should generate # line of the source files which should generate an error, there should
# an error, there should be a comment of the form // ERROR "regexp". # be a comment of the form // ERROR "regexp". If the compiler generates
# If the compiler generates an error for a line which has no such # an error for a line which has no such comment, this script will report
# commnt, this script will report an error. Likewise if the compiler # an error. Likewise if the compiler does not generate an error for a
# does not generate an error for a line which has a comment, or if the # line which has a comment, or if the error message does not match the
# error message does not match the <regexp>. The <regexp> syntax # <regexp>. The <regexp> syntax is Perl but its best to stick to egrep.
# is Perl but its best to stick to egrep.
use POSIX; use POSIX;
if(@ARGV < 1) { if(@ARGV < 1) {
print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILE\n"; print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILES\n";
exit 1; exit 1;
} }
$file = $ARGV[@ARGV-1]; # Grab SOURCEFILES
open(SRC, $file) || die "BUG: errchk: open $file: $!"; foreach(reverse 0 .. @ARGV-1) {
@src = <SRC>; unless($ARGV[$_] =~ /\.go$/) {
close(SRC); @file = @ARGV[$_+1 .. @ARGV-1];
last;
}
}
foreach $file (@file) {
open(SRC, $file) || die "BUG: errchk: open $file: $!";
$src{$file} = [<SRC>];
close(SRC);
}
# Run command # Run command
$cmd = join(' ', @ARGV); $cmd = join(' ', @ARGV);
@ -57,35 +65,45 @@ sub bug() {
} }
} }
$line = 0; sub chk {
foreach $src (@src) { my $file = shift;
$line++; my $line = 0;
next unless $src =~ m|// (GC_)?ERROR (.*)|; my $regexp;
$regexp = $2; my @errmsg;
if($regexp !~ /^"([^"]*)"/) { my @match;
print STDERR "$file:$line: malformed regexp\n"; foreach my $src (@{$src{$file}}) {
next; $line++;
} next unless $src =~ m|// (GC_)?ERROR (.*)|;
$regexp = $1; $regexp = $2;
if($regexp !~ /^"([^"]*)"/) {
print STDERR "$file:$line: malformed regexp\n";
next;
}
$regexp = $1;
@errmsg = grep { /$file:$line[:[]/ } @out; @errmsg = grep { /$file:$line[:[]/ } @out;
@out = grep { !/$file:$line[:[]/ } @out; @out = grep { !/$file:$line[:[]/ } @out;
if(@errmsg == 0) { if(@errmsg == 0) {
bug(); bug();
print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n"; print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n";
next; next;
} }
@match = grep { /$regexp/ } @errmsg; @match = grep { /$regexp/ } @errmsg;
if(@match == 0) { if(@match == 0) {
bug(); bug();
print STDERR "errchk: $file:$line: error message does not match '$regexp'\n"; print STDERR "errchk: $file:$line: error message does not match '$regexp'\n";
next; next;
}
} }
} }
foreach $file (@file) {
chk($file)
}
if(@out != 0) { if(@out != 0) {
bug(); bug();
print STDERR "errchk: $file: unmatched error messages:\n"; print STDERR "errchk: unmatched error messages:\n";
print STDERR "==================================================\n"; print STDERR "==================================================\n";
print STDERR @out; print STDERR @out;
print STDERR "==================================================\n"; print STDERR "==================================================\n";