2 # Plain text output for selftest
3 # Copyright (C) 2008-2009 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
;
21 use FindBin
qw($RealBin);
22 use lib "$RealBin/..";
27 my ($class, $summaryfile, $verbose, $immediate, $statistics, $totaltests) = @_;
30 immediate => $immediate,
31 statistics => $statistics,
37 summaryfile => $summaryfile,
39 totalsuites => $totaltests,
44 sub testsuite_count($$)
46 my ($self, $count) = @_;
47 $self->{totalsuites} = $count;
52 my ($self, $time) = @_;
53 unless ($self->{start_time}) {
54 $self->{start_time} = $time;
56 $self->{last_time} = $time;
61 sub start_testsuite($$)
63 my ($self, $name) = @_;
66 $self->{NAME} = $name;
67 $self->{START_TIME} = $self->{last_time};
69 my $duration = $self->{START_TIME} - $self->{start_time};
71 $self->{test_output}->{$name} = "" unless($self->{verbose});
74 $out .= "[$self->{index}";
75 if ($self->{totalsuites}) {
76 $out .= "/$self->{totalsuites}";
78 $out.= " in ".$duration."s";
79 $out .= sprintf(", %d errors", ($#{$self->{suitesfailed}}+1)) if ($#{$self->{suitesfailed}} > -1);
81 if ($self->{immediate}) {
90 my ($self, $output) = @_;
92 if ($self->{verbose}) {
96 } elsif (defined($self->{NAME})) {
97 $self->{test_output}->{$self->{NAME}} .= $output;
105 my ($self, $output) = @_;
107 #$self->output_msg($output);
110 sub end_testsuite($$$$)
112 my ($self, $name, $result, $reason) = @_;
116 if ($result eq "success" or $result eq "xfail") {
117 $self->{suites_ok}++;
119 $self->output_msg("ERROR: $reason\n");
120 push (@{$self->{suitesfailed}}, $name);
121 if ($self->{immediate} and not $self->{verbose}) {
122 $out .= $self->{test_output}->{$name};
127 if (not $self->{immediate}) {
128 unless($unexpected) {
131 $out .= " " . uc($result) . "\n";
140 my ($self, $testname) = @_;
145 my ($self, $testname, $result, $unexpected, $reason) = @_;
149 unless ($unexpected) {
150 $self->{test_output}->{$self->{NAME}} = "";
151 if (not $self->{immediate}) {
152 if ($result eq "failure") { print "f"; }
153 elsif ($result eq "xfail") { print "X"; }
154 elsif ($result eq "skip") { print "s"; }
155 elsif ($result eq "success") { print "."; }
156 else { print "?($result)"; }
161 $append = "UNEXPECTED($result): $testname\n";
163 $self->{test_output}->{$self->{NAME}} .= $append;
165 if ($self->{immediate} and not $self->{verbose}) {
166 print $self->{test_output}->{$self->{NAME}};
167 $self->{test_output}->{$self->{NAME}} = "";
170 if (not $self->{immediate}) {
171 if ($result eq "error") { print "E"; }
172 elsif ($result eq "failure") { print "F"; }
173 elsif ($result eq "success") { print "S"; }
182 open(SUMMARY, ">$self->{summaryfile}");
184 if ($#{$self->{suitesfailed}} > -1) {
185 print SUMMARY "= Failed tests =\n";
187 foreach (@{$self->{suitesfailed}}) {
188 print SUMMARY "== $_ ==\n";
189 print SUMMARY $self->{test_output}->{$_}."\n\n";
195 if (not $self->{immediate} and not $self->{verbose}) {
196 foreach (@{$self->{suitesfailed}}) {
197 print "===============================================================================\n";
199 print $self->{test_output}->{$_};
204 print SUMMARY "= Skipped tests =\n";
205 foreach my $reason (keys %{$self->{skips}}) {
206 print SUMMARY "$reason\n";
207 foreach my $name (@{$self->{skips}->{$reason}}) {
208 print SUMMARY "\t$name\n";
214 print "\nA summary with detailed information can be found in:\n $self->{summaryfile}\n";
216 if ($#{$self->{suitesfailed}} == -1) {
217 my $ok = $self->{statistics}->{TESTS_EXPECTED_OK} +
218 $self->{statistics}->{TESTS_EXPECTED_FAIL};
219 print "\nALL OK ($ok tests in $self->{suites_ok} testsuites)\n";
221 print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in ". ($#{$self->{suitesfailed}}+1) ." testsuites)\n";
226 sub skip_testsuite($$$)
228 my ($self, $name, $reason) = @_;
230 unless (defined($reason)) {
233 push (@{$self->{skips}->{$reason}}, $name);
235 if ($self->{totalsuites}) {
236 $self->{totalsuites}--;