s4-smbtorture: perform the ntsvcs devicelist tests against the Spooler service.
[Samba/gbeck.git] / selftest / output / plain.pm
blob5312a9e27b3416463b47d7f9f057dd737293592f
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 => time(),
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 output_msg($$);
46 sub start_testsuite($$)
48 my ($self, $name) = @_;
50 $self->{index}++;
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});
58 my $out = "";
59 $out .= "[$self->{index}/$self->{totalsuites} in ".$duration."s";
60 $out .= sprintf(", %d errors", ($#{$self->{suitesfailed}}+1)) if ($#{$self->{suitesfailed}} > -1);
61 $out .= "] $name";
62 if ($self->{immediate}) {
63 print "$out\n";
64 } else {
65 print "$out: ";
69 sub output_msg($$)
71 my ($self, $output) = @_;
73 if ($self->{verbose}) {
74 require FileHandle;
75 print $output;
76 STDOUT->flush();
77 } else {
78 $self->{test_output}->{$self->{NAME}} .= $output;
82 sub control_msg($$)
84 my ($self, $output) = @_;
86 $self->output_msg($output);
89 sub end_testsuite($$$$$)
91 my ($self, $name, $result, $unexpected, $reason) = @_;
92 my $out = "";
94 if ($unexpected) {
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);
100 } else {
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) {
110 $out .= " ok\n";
111 } else {
112 $out .= " " . uc($result) . "\n";
116 print $out;
119 sub start_test($$$)
121 my ($self, $parents, $testname) = @_;
123 if ($#$parents == -1) {
124 $self->start_testsuite($testname);
128 sub end_test($$$$$)
130 my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
132 if ($#$parents == -1) {
133 $self->end_testsuite($testname, $result, $unexpected, $reason);
134 return;
137 my $append = "";
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)"; }
147 return;
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"; }
165 else { print "?"; }
169 sub summary($)
171 my ($self) = @_;
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";
183 print SUMMARY "\n";
186 if (not $self->{immediate} and not $self->{verbose}) {
187 foreach (@{$self->{suitesfailed}}) {
188 print "===============================================================================\n";
189 print "FAIL: $_\n";
190 print $self->{test_output}->{$_};
191 print "\n";
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";
201 print SUMMARY "\n";
203 close(SUMMARY);
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";
211 } else {
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}--;