**** Merged from MCS ****
[mono-project.git] / mcs / errors / runtest.pl
blob530e26c9fa6edd2dc85a74316909908840125ab1
1 #!/usr/bin/perl -w
3 use strict;
4 use IPC::Open3;
6 sub remove ($$) {
7 my ($val, $arr) = @_;
8 my $had = 0;
9 my @hasnt = ();
11 for my $v (@$arr) {
12 if ($v == $val) { $had = 1; }
13 else { push @hasnt, $v; }
15 return ($had, \@hasnt);
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;
23 if ($#ARGV != 1) {
24 print STDERR "Usage: $0 testcase.cs testcase.out\n";
25 exit 1;
28 my %errors = ();
29 my %warnings = ();
30 my %lines = ();
32 my $csfile = $ARGV [0];
33 my $mcsout = $ARGV [1];
34 my $input;
36 my $line = 0;
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+),;
45 if ((defined $1) and ($1 eq 'warning')) {
46 push @{$warnings{$2}}, $line+1;
47 } else {
48 push @{$errors{$2}}, $line+1;
51 $lines{$line+1} = $2;
54 close INPUT;
56 open (MCS, "$mcsout") or die
57 "Can't open compiler output file: $!";
59 while (defined ($input = <MCS>)) {
60 chop $input;
61 next unless $input =~ m,\((\d+)\)\s+(warning|error)\s+(CS\d+):,;
62 my $had;
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;
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;
78 print "Expected to find ".$lines{$1}." on line $1, but got $3.\n"
79 if $strict and $lines{$1} ne $3;
82 close MCS;
84 foreach my $error (keys %errors) {
85 print "Failed to report error $error on line $_\n"
86 for @{$errors{$error}};
87 $failures += @{$errors{$error}};
90 foreach my $warning (keys %warnings) {
91 print "Failed to report warning $warning on line $_\n"
92 for @{$warnings{$warning}};
93 $failures += @{$warnings{$warning}};
96 exit ($failures != 0);