2 # Copyright 2009 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file.
6 # This script checks that the compilers emit the errors which we expect.
7 # Usage: errchk COMPILER [OPTS] SOURCEFILES. This will run the command
8 # COMPILER [OPTS] SOURCEFILES. The compilation is expected to fail; if
9 # it succeeds, this script will report an error. The stderr output of
10 # the compiler will be matched against comments in SOURCEFILES. For each
11 # line of the source files which should generate an error, there should
12 # be a comment of the form // ERROR "regexp". If the compiler generates
13 # an error for a line which has no such comment, this script will report
14 # an error. Likewise if the compiler does not generate an error for a
15 # line which has a comment, or if the error message does not match the
16 # <regexp>. The <regexp> syntax is Perl but its best to stick to egrep.
22 if(@ARGV >= 1 && $ARGV[0] eq "-0") {
28 print STDERR
"Usage: errchk COMPILER [OPTS] SOURCEFILES\n";
33 foreach(reverse 0 .. @ARGV-1) {
34 unless($ARGV[$_] =~ /\.(go|s)$/) {
35 @file = @ARGV[$_+1 .. @ARGV-1];
40 foreach $file (@file) {
41 open(SRC
, $file) || die "BUG: errchk: open $file: $!";
42 $src{$file} = [<SRC
>];
47 $cmd = join(' ', @ARGV);
48 open(CMD
, "exec $cmd </dev/null 2>&1 |") || die "BUG: errchk: run $cmd: $!";
50 # 6g error messages continue onto additional lines with leading tabs.
51 # Split the output at the beginning of each line that doesn't begin with a tab.
52 $out = join('', <CMD
>);
53 @out = split(/^(?!\t)/m, $out);
57 if($exitcode != 0 && $?
== 0) {
58 print STDERR
"BUG: errchk: command succeeded unexpectedly\n";
63 if($exitcode == 0 && $?
!= 0) {
64 print STDERR
"BUG: errchk: command failed unexpectedly\n";
70 print STDERR
"BUG: errchk: compiler crashed\n";
71 print STDERR
@out, "\n";
87 foreach my $src (@
{$src{$file}}) {
89 next if $src =~ m
|////|; # double comment disables ERROR
90 next unless $src =~ m
|// (GC_
)?ERROR
(.*)|;
92 if($all !~ /^"([^"]*)"/) {
93 print STDERR
"$file:$line: malformed regexp\n";
96 @errmsg = grep { /$file:$line[:[]/ } @out;
97 @out = grep { !/$file:$line[:[]/ } @out;
100 print STDERR
"errchk: $file:$line: missing expected error: '$all'\n";
103 foreach my $regexp ($all =~ /"([^"]*)"/g) {
104 # Turn relative line number in message into absolute line number.
105 if($regexp =~ /LINE(([+-])([0-9]+))?/) {
114 $regexp = "$`$file:$n$'";
117 @match = grep { /$regexp/ } @errmsg;
120 print STDERR
"errchk: $file:$line: error messages do not match '$regexp'\n";
123 @errmsg = grep { !/$regexp/ } @errmsg;
127 print STDERR
"errchk: $file:$line: unmatched error messages:\n";
128 foreach my $l (@errmsg) {
135 foreach $file (@file) {
141 print STDERR
"errchk: unmatched error messages:\n";
142 print STDERR
"==================================================\n";
144 print STDERR
"==================================================\n";