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;
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,
46 my ($self, $time) = @_;
47 unless ($self->{start_time}) {
48 $self->{start_time} = $time;
50 $self->{last_time} = $time;
55 sub start_testsuite($$)
57 my ($self, $name) = @_;
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});
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);
75 if ($self->{immediate}) {
84 my ($self, $output) = @_;
86 if ($self->{verbose}) {
90 } elsif (defined($self->{NAME})) {
91 $self->{test_output}->{$self->{NAME}} .= $output;
99 my ($self, $output) = @_;
101 #$self->output_msg($output);
104 sub end_testsuite($$$$$)
106 my ($self, $name, $result, $unexpected, $reason) = @_;
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);
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) {
127 $out .= " " . uc($result) . "\n";
136 my ($self, $parents, $testname) = @_;
138 if ($#$parents == -1) {
139 $self->start_testsuite($testname);
145 my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
147 if ($#$parents == -1) {
148 if ($result eq "skip") {
149 $self->skip_testsuite($testname, $reason);
151 $self->end_testsuite($testname, $result, $unexpected, $reason);
158 unless ($unexpected) {
159 $self->{test_output}->{$self->{NAME}} = "";
160 if (not $self->{immediate}) {
161 if ($result eq "failure") { print "f"; }
162 elsif ($result eq "xfail") { print "X"; }
163 elsif ($result eq "skip") { print "s"; }
164 elsif ($result eq "success") { print "."; }
165 else { print "?($result)"; }
170 my $fullname = join(".", @$parents).".$testname";
172 $append = "UNEXPECTED($result): $testname ($fullname)\n";
174 $self->{test_output}->{$self->{NAME}} .= $append;
176 if ($self->{immediate} and not $self->{verbose}) {
177 print $self->{test_output}->{$self->{NAME}};
178 $self->{test_output}->{$self->{NAME}} = "";
181 if (not $self->{immediate}) {
182 if ($result eq "error") { print "E"; }
183 elsif ($result eq "failure") { print "F"; }
184 elsif ($result eq "success") { print "S"; }
193 open(SUMMARY, ">$self->{summaryfile}");
195 if ($#{$self->{suitesfailed}} > -1) {
196 print SUMMARY "= Failed tests =\n";
198 foreach (@{$self->{suitesfailed}}) {
199 print SUMMARY "== $_ ==\n";
200 print SUMMARY $self->{test_output}->{$_}."\n\n";
206 if (not $self->{immediate} and not $self->{verbose}) {
207 foreach (@{$self->{suitesfailed}}) {
208 print "===============================================================================\n";
210 print $self->{test_output}->{$_};
215 print SUMMARY "= Skipped tests =\n";
216 foreach my $reason (keys %{$self->{skips}}) {
217 print SUMMARY "$reason\n";
218 foreach my $name (@{$self->{skips}->{$reason}}) {
219 print SUMMARY "\t$name\n";
225 print "\nA summary with detailed information can be found in:\n $self->{summaryfile}\n";
227 if ($#{$self->{suitesfailed}} == -1) {
228 my $ok = $self->{statistics}->{TESTS_EXPECTED_OK} +
229 $self->{statistics}->{TESTS_EXPECTED_FAIL};
230 print "\nALL OK ($ok tests in $self->{suites_ok} testsuites)\n";
232 print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in ". ($#{$self->{suitesfailed}}+1) ." testsuites)\n";
237 sub skip_testsuite($$$)
239 my ($self, $name, $reason) = @_;
241 unless (defined($reason)) {
244 push (@{$self->{skips}->{$reason}}, $name);
246 if ($self->{totalsuites}) {
247 $self->{totalsuites}--;