2002-08-11 Martin Baulig <martin@gnome.org>
[mono.git] / mcs / errors / runtest.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use IPC::Open3;
5
6 # Setting $strict to 1 enables line number checks, setting it to 2 makes
7 # line number mismatches fatal.
8 my $strict = 2;
9 my $failures = 0;
10 my $mcs = (defined $ENV{MCS}) ? $ENV{MCS} : 'mcs';
11
12 unless ($#ARGV == 0) {
13     print STDERR "Usage: $0 testcase.cs\n";
14     exit 1;
15 }
16
17 my %errors = ();
18 my %warnings = ();
19 my %lines = ();
20
21 my $filename = $ARGV [0];
22 my $input;
23
24 my $line = 0;
25
26 open (INPUT, "<$filename") or die
27     "Can't open testcase: $!";
28 while (defined ($input = <INPUT>)) {
29     ++$line;
30     chop $input;
31     next unless $input =~ m,^\s*//\s*(error|warning)?\s*(CS\d+),;
32
33     if ((defined $1) and ($1 eq 'warning')) {
34         ++$warnings{$2};
35     } else {
36         ++$errors{$2};
37     }
38
39     $lines{$line+1} = $2;
40 }
41 close INPUT;
42
43 open (MCS, "$mcs $filename|") or die
44     "Can't open mcs pipe: $!";
45
46 while (defined ($input = <MCS>)) {
47     chop $input;
48     next unless $input =~ m,\((\d+)\)\s+(warning|error)\s+(CS\d+):,;
49
50     if ($2 eq 'warning') {
51         --$warnings{$3};
52     } else {
53         --$errors{$3};
54     }
55
56     next unless $strict;
57
58     if (!defined $lines{$1}) {
59         print "Didn't expect any warnings or errors in line $1, but got $2 $3.\n";
60         $failures++ if $strict == 2;
61     } elsif ($lines{$1} ne $3) {
62         print "Expected to find ".$lines{$1}." on line $1, but got $3.\n";
63         $failures++ if $strict == 2;
64     }
65 }
66
67 close MCS;
68
69 foreach my $error (keys %errors) {
70     my $times = $errors{$error};
71
72     if ($times == -1) {
73         print "Unexpected error $error.\n";
74     } elsif ($times < 0) {
75         print "Unexpected error $error (reported ".(-$times)." times).\n";
76     } elsif ($times == 1) {
77         print "Failed to report error $error.\n";
78     } elsif ($times > 0) {
79         print "Failed to report error $error $times times.\n";
80     }
81
82     $failures++ unless $times == 0;    
83 }
84
85 foreach my $warning (keys %warnings) {
86     my $times = $warnings{$warning};
87
88     if ($times == -1) {
89         print "Unexpected warning $warning.\n";
90     } elsif ($times < 0) {
91         print "Unexpected warning $warning (reported ".(-$times)." times).\n";
92     } elsif ($times == 1) {
93         print "Failed to report warning $warning.\n";
94     } elsif ($times > 0) {
95         print "Failed to report warning $warning $times times.\n";
96     }
97
98     $failures++ unless $times == 0;    
99 }
100
101 if ($failures == 0) {
102     exit 0;
103 } else {
104     exit 1;
105 }