selftest/subunit: Remove prefix command.
[Samba/ekacnet.git] / selftest / output / plain.pm
blob2427136073f76241ce545f5b507e2f61d6bdbb26
1 #!/usr/bin/perl
2 # Plain text output for selftest
3 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package output::plain;
18 use Exporter;
19 @ISA = qw(Exporter);
21 use FindBin qw($RealBin);
22 use lib "$RealBin/..";
24 use strict;
26 sub new($$$$$$$) {
27 my ($class, $summaryfile, $verbose, $immediate, $statistics, $totaltests) = @_;
28 my $self = {
29 verbose => $verbose,
30 immediate => $immediate,
31 statistics => $statistics,
32 start_time => undef,
33 test_output => {},
34 suitesfailed => [],
35 suites_ok => 0,
36 skips => {},
37 summaryfile => $summaryfile,
38 index => 0,
39 totalsuites => $totaltests,
41 bless($self, $class);
44 sub report_time($$)
46 my ($self, $time) = @_;
47 unless ($self->{start_time}) {
48 $self->{start_time} = $time;
50 $self->{last_time} = $time;
53 sub output_msg($$);
55 sub start_testsuite($$)
57 my ($self, $name) = @_;
59 $self->{index}++;
60 $self->{NAME} = $name;
61 $self->{START_TIME} = $self->{last_time};
63 my $duration = $self->{START_TIME} - $self->{start_time};
65 $self->{test_output}->{$name} = "" unless($self->{verbose});
67 my $out = "";
68 $out .= "[$self->{index}";
69 if ($self->{totalsuites}) {
70 $out .= "/$self->{totalsuites}";
72 $out.= " in ".$duration."s";
73 $out .= sprintf(", %d errors", ($#{$self->{suitesfailed}}+1)) if ($#{$self->{suitesfailed}} > -1);
74 $out .= "] $name";
75 if ($self->{immediate}) {
76 print "$out\n";
77 } else {
78 print "$out: ";
82 sub output_msg($$)
84 my ($self, $output) = @_;
86 if ($self->{verbose}) {
87 require FileHandle;
88 print $output;
89 STDOUT->flush();
90 } elsif (defined($self->{NAME})) {
91 $self->{test_output}->{$self->{NAME}} .= $output;
92 } else {
93 print $output;
97 sub control_msg($$)
99 my ($self, $output) = @_;
101 #$self->output_msg($output);
104 sub end_testsuite($$$$$)
106 my ($self, $name, $result, $unexpected, $reason) = @_;
107 my $out = "";
109 if ($unexpected) {
110 if ($result eq "success" and not defined($reason)) {
111 $reason = "Expected negative exit code, got positive exit code";
113 $self->output_msg("ERROR: $reason\n");
114 push (@{$self->{suitesfailed}}, $name);
115 } else {
116 $self->{suites_ok}++;
119 if ($unexpected and $self->{immediate} and not $self->{verbose}) {
120 $out .= $self->{test_output}->{$name};
123 if (not $self->{immediate}) {
124 if (not $unexpected) {
125 $out .= " ok\n";
126 } else {
127 $out .= " " . uc($result) . "\n";
131 print $out;
134 sub start_test($$$)
136 my ($self, $testname) = @_;
139 sub end_test($$$$$)
141 my ($self, $testname, $result, $unexpected, $reason) = @_;
143 my $append = "";
145 unless ($unexpected) {
146 $self->{test_output}->{$self->{NAME}} = "";
147 if (not $self->{immediate}) {
148 if ($result eq "failure") { print "f"; }
149 elsif ($result eq "xfail") { print "X"; }
150 elsif ($result eq "skip") { print "s"; }
151 elsif ($result eq "success") { print "."; }
152 else { print "?($result)"; }
154 return;
157 $append = "UNEXPECTED($result): $testname\n";
159 $self->{test_output}->{$self->{NAME}} .= $append;
161 if ($self->{immediate} and not $self->{verbose}) {
162 print $self->{test_output}->{$self->{NAME}};
163 $self->{test_output}->{$self->{NAME}} = "";
166 if (not $self->{immediate}) {
167 if ($result eq "error") { print "E"; }
168 elsif ($result eq "failure") { print "F"; }
169 elsif ($result eq "success") { print "S"; }
170 else { print "?"; }
174 sub summary($)
176 my ($self) = @_;
178 open(SUMMARY, ">$self->{summaryfile}");
180 if ($#{$self->{suitesfailed}} > -1) {
181 print SUMMARY "= Failed tests =\n";
183 foreach (@{$self->{suitesfailed}}) {
184 print SUMMARY "== $_ ==\n";
185 print SUMMARY $self->{test_output}->{$_}."\n\n";
188 print SUMMARY "\n";
191 if (not $self->{immediate} and not $self->{verbose}) {
192 foreach (@{$self->{suitesfailed}}) {
193 print "===============================================================================\n";
194 print "FAIL: $_\n";
195 print $self->{test_output}->{$_};
196 print "\n";
200 print SUMMARY "= Skipped tests =\n";
201 foreach my $reason (keys %{$self->{skips}}) {
202 print SUMMARY "$reason\n";
203 foreach my $name (@{$self->{skips}->{$reason}}) {
204 print SUMMARY "\t$name\n";
206 print SUMMARY "\n";
208 close(SUMMARY);
210 print "\nA summary with detailed information can be found in:\n $self->{summaryfile}\n";
212 if ($#{$self->{suitesfailed}} == -1) {
213 my $ok = $self->{statistics}->{TESTS_EXPECTED_OK} +
214 $self->{statistics}->{TESTS_EXPECTED_FAIL};
215 print "\nALL OK ($ok tests in $self->{suites_ok} testsuites)\n";
216 } else {
217 print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in ". ($#{$self->{suitesfailed}}+1) ." testsuites)\n";
222 sub skip_testsuite($$$)
224 my ($self, $name, $reason) = @_;
226 unless (defined($reason)) {
227 $reason = "UNKNOWN";
229 push (@{$self->{skips}->{$reason}}, $name);
231 if ($self->{totalsuites}) {
232 $self->{totalsuites}--;