selftest/subunit: Remove open_tests argument from parse_results.
[ira/wip.git] / selftest / Subunit / Filter.pm
1 #!/usr/bin/perl
2 # Filter a subunit stream
3 # Copyright (C) Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later
5
6 package Subunit::Filter;
7
8 use strict;
9
10 sub read_test_regexes($)
11 {
12         my ($name) = @_;
13         my @ret = ();
14         open(LF, "<$name") or die("unable to read $name: $!");
15         while (<LF>) { 
16                 chomp; 
17                 next if (/^#/);
18                 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
19                         push (@ret, [$1, $4]);
20                 } else {
21                         s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
22                         push (@ret, [$_, undef]); 
23                 }
24         }
25         close(LF);
26         return @ret;
27 }
28
29 sub find_in_list($$)
30 {
31         my ($list, $fullname) = @_;
32
33         foreach (@$list) {
34                 if ($fullname =~ /$$_[0]/) {
35                          return ($$_[1]) if ($$_[1]);
36                          return "";
37                 }
38         }
39
40         return undef;
41 }
42
43 sub control_msg()
44 {
45         # We regenerate control messages, so ignore this
46 }
47
48 sub report_time($$)
49 {
50         my ($self, $time) = @_;
51         Subunit::report_time($time);
52 }
53
54 sub output_msg($$)
55 {
56         my ($self, $msg) = @_;
57         print $msg;
58 }
59
60 sub start_test($$)
61 {
62         my ($self, $testname) = @_;
63
64         if (defined($self->{prefix})) {
65                 $testname = $self->{prefix}.$testname;
66         }
67
68         Subunit::start_test($testname);
69 }
70
71 sub end_test($$$$$)
72 {
73         my ($self, $testname, $result, $unexpected, $reason) = @_;
74
75         if (defined($self->{prefix})) {
76                 $testname = $self->{prefix}.$testname;
77         }
78
79         if (($result eq "fail" or $result eq "failure") and not $unexpected) { $result = "xfail"; }
80         my $xfail_reason = find_in_list($self->{expected_failures}, $testname);
81         if (defined($xfail_reason) and ($result eq "fail" or $result eq "failure")) {
82                 $result = "xfail";
83                 $reason .= $xfail_reason;
84         }
85
86         Subunit::end_test($testname, $result, $reason);
87 }
88
89 sub skip_testsuite($;$)
90 {
91         Subunit::skip_testsuite(@_);
92 }
93
94 sub start_testsuite($;$)
95 {
96         my ($self, $name) = @_;
97         Subunit::start_testsuite($name);
98 }
99
100 sub end_testsuite($$;$)
101 {
102         my ($self, $name, $result, $reason) = @_;
103         Subunit::end_testsuite($name, $result, $reason);
104 }
105
106 sub testsuite_count($$)
107 {
108         my ($self, $count) = @_;
109         Subunit::testsuite_count($count);
110 }
111
112 sub new {
113         my ($class, $prefix, $expected_failures) = @_;
114
115         my $self = { 
116                 prefix => $prefix,
117                 expected_failures => $expected_failures,
118         };
119         bless($self, $class);
120 }
121
122 1;