2 # Filter a subunit stream
3 # Copyright (C) Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later
6 package Subunit
::Filter
;
10 sub read_test_regexes
($)
14 open(LF
, "<$name") or die("unable to read $name: $!");
19 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
20 push (@ret, [$1, $4]);
22 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
23 push (@ret, [$_, undef]);
32 my ($list, $fullname) = @_;
35 if ($fullname =~ /$$_[0]/) {
36 return ($$_[1]) if ($$_[1]);
46 # We regenerate control messages, so ignore this
51 my ($self, $time) = @_;
52 Subunit
::report_time
($time);
57 my ($self, $msg) = @_;
58 unless(defined($self->{output
})) {
61 $self->{output
}.=$msg;
67 my ($self, $testname) = @_;
69 if (defined($self->{prefix
})) {
70 $testname = $self->{prefix
}.$testname;
73 if ($self->{strip_ok_output
}) {
77 Subunit
::start_test
($testname);
82 my ($self, $testname, $result, $unexpected, $reason) = @_;
84 if (defined($self->{prefix
})) {
85 $testname = $self->{prefix
}.$testname;
88 if (($result eq "fail" or $result eq "failure") and not $unexpected) {
90 $self->{xfail_added
}++;
92 my $xfail_reason = find_in_list
($self->{expected_failures
}, $testname);
93 if (defined($xfail_reason) and ($result eq "fail" or $result eq "failure")) {
95 $self->{xfail_added
}++;
96 $reason .= $xfail_reason;
99 if ($result eq "fail" or $result eq "failure") {
100 $self->{fail_added
}++;
103 if ($result eq "error") {
104 $self->{error_added
}++;
107 if ($self->{strip_ok_output
}) {
108 unless ($result eq "success" or $result eq "xfail" or $result eq "skip") {
109 print $self->{output
}
112 $self->{output
} = undef;
114 Subunit
::end_test
($testname, $result, $reason);
117 sub skip_testsuite
($;$)
119 my ($self, $name, $reason) = @_;
120 Subunit
::skip_testsuite
($name, $reason);
123 sub start_testsuite
($;$)
125 my ($self, $name) = @_;
126 Subunit
::start_testsuite
($name);
127 $self->{error_added
} = 0;
128 $self->{fail_added
} = 0;
129 $self->{xfail_added
} = 0;
132 sub end_testsuite
($$;$)
134 my ($self, $name, $result, $reason) = @_;
137 $xfail = 1 if ($self->{xfail_added
} > 0);
138 $xfail = 0 if ($self->{fail_added
} > 0);
139 $xfail = 0 if ($self->{error_added
} > 0);
141 if ($xfail and ($result eq "fail" or $result eq "failure")) {
145 if ($self->{fail_added
} > 0 and $result ne "failure") {
147 $reason = "Subunit/Filer Reason" unless defined($reason);
148 $reason .= "\n failures[$self->{fail_added}]";
151 if ($self->{error_added
} > 0 and $result ne "error") {
153 $reason = "Subunit/Filer Reason" unless defined($reason);
154 $reason .= "\n errors[$self->{error_added}]";
157 Subunit
::end_testsuite
($name, $result, $reason);
160 sub testsuite_count
($$)
162 my ($self, $count) = @_;
163 Subunit
::testsuite_count
($count);
167 my ($class, $prefix, $expected_failures, $strip_ok_output) = @_;
171 expected_failures
=> $expected_failures,
172 strip_ok_output
=> $strip_ok_output,
175 bless($self, $class);