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