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 sub start_testsuite($$)
48 my ($self, $name) = @_;
51 $self->{NAME} = $name;
52 $self->{START_TIME} = time();
54 my $duration = $self->{START_TIME} - $self->{start_time};
56 $self->{test_output}->{$name} = "" unless($self->{verbose});
59 $out .= "[$self->{index}/$self->{totalsuites} in ".$duration."s";
60 $out .= sprintf(", %d errors", ($#{$self->{suitesfailed}}+1)) if ($#{$self->{suitesfailed}} > -1);
62 if ($self->{immediate}) {
71 my ($self, $output) = @_;
73 if ($self->{verbose}) {
78 $self->{test_output}->{$self->{NAME}} .= $output;
84 my ($self, $output) = @_;
86 $self->output_msg($output);
89 sub end_testsuite($$$$$)
91 my ($self, $name, $result, $unexpected, $reason) = @_;
95 if ($result eq "success" and not defined($reason)) {
96 $reason = "Expected negative exit code, got positive exit code";
98 $self->output_msg("ERROR: $reason\n");
99 push (@{$self->{suitesfailed}}, $name);
101 $self->{suites_ok}++;
104 if ($unexpected and $self->{immediate} and not $self->{verbose}) {
105 $out .= $self->{test_output}->{$name};
108 if (not $self->{immediate}) {
109 if (not $unexpected) {
112 $out .= " " . uc($result) . "\n";
121 my ($self, $parents, $testname) = @_;
123 if ($#$parents == -1) {
124 $self->start_testsuite($testname);
130 my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
132 if ($#$parents == -1) {
133 $self->end_testsuite($testname, $result, $unexpected, $reason);
139 unless ($unexpected) {
140 $self->{test_output}->{$self->{NAME}} = "";
141 if (not $self->{immediate}) {
142 if ($result eq "failure") { print "f"; }
143 elsif ($result eq "skip") { print "s"; }
144 elsif ($result eq "success") { print "."; }
145 else { print "?($result)"; }
150 my $fullname = join(".", @$parents).".$testname";
152 $append = "UNEXPECTED($result): $testname ($fullname)\n";
154 $self->{test_output}->{$self->{NAME}} .= $append;
156 if ($self->{immediate} and not $self->{verbose}) {
157 print $self->{test_output}->{$self->{NAME}};
158 $self->{test_output}->{$self->{NAME}} = "";
161 if (not $self->{immediate}) {
162 if ($result eq "error") { print "E"; }
163 elsif ($result eq "failure") { print "F"; }
164 elsif ($result eq "success") { print "S"; }
173 open(SUMMARY, ">$self->{summaryfile}");
175 if ($#{$self->{suitesfailed}} > -1) {
176 print SUMMARY "= Failed tests =\n";
178 foreach (@{$self->{suitesfailed}}) {
179 print SUMMARY "== $_ ==\n";
180 print SUMMARY $self->{test_output}->{$_}."\n\n";
186 if (not $self->{immediate} and not $self->{verbose}) {
187 foreach (@{$self->{suitesfailed}}) {
188 print "===============================================================================\n";
190 print $self->{test_output}->{$_};
195 print SUMMARY "= Skipped tests =\n";
196 foreach my $reason (keys %{$self->{skips}}) {
197 print SUMMARY "$reason\n";
198 foreach my $name (@{$self->{skips}->{$reason}}) {
199 print SUMMARY "\t$name\n";
205 print "\nA summary with detailed information can be found in:\n $self->{summaryfile}\n";
207 if ($#{$self->{suitesfailed}} == -1) {
208 my $ok = $self->{statistics}->{TESTS_EXPECTED_OK} +
209 $self->{statistics}->{TESTS_EXPECTED_FAIL};
210 print "\nALL OK ($ok tests in $self->{suites_ok} testsuites)\n";
212 print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in ". ($#{$self->{suitesfailed}}+1) ." testsuites)\n";
217 sub skip_testsuite($$)
219 my ($self, $name, $reason) = @_;
221 push (@{$self->{skips}->{$reason}}, $name);
223 $self->{totalsuites}--;