2009-10-09 01:39:32 -06:00
|
|
|
#!/usr/bin/perl
|
2008-09-19 15:39:49 -06:00
|
|
|
# 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
|
2009-10-09 01:39:32 -06:00
|
|
|
# error message does not match the <regexp>. The <regexp> syntax
|
|
|
|
# is Perl but its best to stick to egrep.
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
use POSIX;
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
if(@ARGV < 1) {
|
|
|
|
print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILE\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
$file = $ARGV[@ARGV-1];
|
|
|
|
open(SRC, $file) || die "BUG: errchk: open $file: $!";
|
|
|
|
@src = <SRC>;
|
|
|
|
close(SRC);
|
2008-10-30 13:43:32 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
# Run command
|
|
|
|
$cmd = join(' ', @ARGV);
|
2009-10-09 17:44:40 -06:00
|
|
|
open(CMD, "exec $cmd </dev/null 2>&1 |") || die "BUG: errchk: run $cmd: $!";
|
2010-06-20 13:05:43 -06:00
|
|
|
|
|
|
|
# 6g error messages continue onto additional lines with leading tabs.
|
|
|
|
# Split the output at the beginning of each line that doesn't begin with a tab.
|
|
|
|
$out = join('', <CMD>);
|
|
|
|
@out = split(/^(?!\t)/m, $out);
|
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
close CMD;
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
if($? == 0) {
|
|
|
|
print STDERR "BUG: errchk: command succeeded unexpectedly\n";
|
|
|
|
print STDERR @out;
|
|
|
|
exit 0;
|
|
|
|
}
|
2009-08-21 18:41:18 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
if(!WIFEXITED($?)) {
|
|
|
|
print STDERR "BUG: errchk: compiler crashed\n";
|
2009-10-09 17:44:40 -06:00
|
|
|
print STDERR @out, "\n";
|
2009-10-09 01:39:32 -06:00
|
|
|
exit 0;
|
|
|
|
}
|
2009-08-21 18:41:18 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
sub bug() {
|
|
|
|
if(!$bug++) {
|
|
|
|
print STDERR "BUG: ";
|
|
|
|
}
|
|
|
|
}
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
$line = 0;
|
|
|
|
foreach $src (@src) {
|
|
|
|
$line++;
|
2010-08-31 15:12:23 -06:00
|
|
|
next unless $src =~ m|// (GC_)?ERROR (.*)|;
|
|
|
|
$regexp = $2;
|
2009-10-09 01:39:32 -06:00
|
|
|
if($regexp !~ /^"([^"]*)"/) {
|
|
|
|
print STDERR "$file:$line: malformed regexp\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$regexp = $1;
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
@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;
|
|
|
|
}
|
2008-10-17 08:41:18 -06:00
|
|
|
}
|
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
if(@out != 0) {
|
|
|
|
bug();
|
|
|
|
print STDERR "errchk: $file: unmatched error messages:\n";
|
|
|
|
print STDERR "==================================================\n";
|
|
|
|
print STDERR @out;
|
|
|
|
print STDERR "==================================================\n";
|
|
|
|
}
|
2008-09-19 15:39:49 -06:00
|
|
|
|
2009-10-09 01:39:32 -06:00
|
|
|
exit 0;
|