lib/popt: Fix typo in README.
[Samba/gbeck.git] / selftest / Subunit / Filter.pm
blob93b690df8ee7c5db4b1263480c3f8bb56a5e2918
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
6 package Subunit::Filter;
8 use strict;
10 sub read_test_regexes($)
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]);
25 close(LF);
26 return @ret;
29 sub find_in_list($$)
31 my ($list, $fullname) = @_;
33 foreach (@$list) {
34 if ($fullname =~ /$$_[0]/) {
35 return ($$_[1]) if ($$_[1]);
36 return "";
40 return undef;
43 sub control_msg()
45 # We regenerate control messages, so ignore this
48 sub report_time($$)
50 my ($self, $time) = @_;
51 Subunit::report_time($time);
54 sub output_msg($$)
56 my ($self, $msg) = @_;
57 unless(defined($self->{output})) {
58 print $msg;
59 } else {
60 $self->{output}.=$msg;
64 sub start_test($$)
66 my ($self, $testname) = @_;
68 if (defined($self->{prefix})) {
69 $testname = $self->{prefix}.$testname;
72 if ($self->{strip_ok_output}) {
73 $self->{output} = "";
76 Subunit::start_test($testname);
79 sub end_test($$$$$)
81 my ($self, $testname, $result, $unexpected, $reason) = @_;
83 if (defined($self->{prefix})) {
84 $testname = $self->{prefix}.$testname;
87 if (($result eq "fail" or $result eq "failure") and not $unexpected) {
88 $result = "xfail";
89 $self->{xfail_added}++;
91 my $xfail_reason = find_in_list($self->{expected_failures}, $testname);
92 if (defined($xfail_reason) and ($result eq "fail" or $result eq "failure")) {
93 $result = "xfail";
94 $self->{xfail_added}++;
95 $reason .= $xfail_reason;
98 if ($self->{strip_ok_output}) {
99 unless ($result eq "success" or $result eq "xfail" or $result eq "skip") {
100 print $self->{output}
103 $self->{output} = undef;
105 Subunit::end_test($testname, $result, $reason);
108 sub skip_testsuite($;$)
110 my ($self, $name, $reason) = @_;
111 Subunit::skip_testsuite($name, $reason);
114 sub start_testsuite($;$)
116 my ($self, $name) = @_;
117 Subunit::start_testsuite($name);
118 $self->{xfail_added} = 0;
121 sub end_testsuite($$;$)
123 my ($self, $name, $result, $reason) = @_;
124 if ($self->{xfail_added} and ($result eq "fail" or $result eq "failure")) {
125 $result = "xfail";
128 Subunit::end_testsuite($name, $result, $reason);
131 sub testsuite_count($$)
133 my ($self, $count) = @_;
134 Subunit::testsuite_count($count);
137 sub new {
138 my ($class, $prefix, $expected_failures, $strip_ok_output) = @_;
140 my $self = {
141 prefix => $prefix,
142 expected_failures => $expected_failures,
143 strip_ok_output => $strip_ok_output,
144 xfail_added => 0,
146 bless($self, $class);