s4-heimdal: Fix typos in comment.
[Samba.git] / selftest / Subunit / Filter.pm
blob896721a67bec01593692db8712aaa048283ec7a6
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 next if (/^$/);
19 if (/^(.*?)([ \t]+)\#([\t ]*)(.*?)$/) {
20 push (@ret, [$1, $4]);
21 } else {
22 s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$//;
23 push (@ret, [$_, undef]);
26 close(LF);
27 return @ret;
30 sub find_in_list($$)
32 my ($list, $fullname) = @_;
34 foreach (@$list) {
35 if ($fullname =~ /$$_[0]/) {
36 return ($$_[1]) if ($$_[1]);
37 return "";
41 return undef;
44 sub control_msg()
46 # We regenerate control messages, so ignore this
49 sub report_time($$)
51 my ($self, $time) = @_;
52 Subunit::report_time($time);
55 sub output_msg($$)
57 my ($self, $msg) = @_;
58 unless(defined($self->{output})) {
59 print $msg;
60 } else {
61 $self->{output}.=$msg;
65 sub start_test($$)
67 my ($self, $testname) = @_;
69 if (defined($self->{prefix})) {
70 $testname = $self->{prefix}.$testname;
73 if ($self->{strip_ok_output}) {
74 $self->{output} = "";
77 Subunit::start_test($testname);
80 sub end_test($$$$$)
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) {
89 $result = "xfail";
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")) {
94 $result = "xfail";
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) = @_;
135 my $xfail = 0;
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")) {
142 $result = "xfail";
145 if ($self->{fail_added} > 0 and $result ne "failure") {
146 $result = "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") {
152 $result = "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);
166 sub new {
167 my ($class, $prefix, $expected_failures, $strip_ok_output) = @_;
169 my $self = {
170 prefix => $prefix,
171 expected_failures => $expected_failures,
172 strip_ok_output => $strip_ok_output,
173 xfail_added => 0,
175 bless($self, $class);