s3/vfs_extd_audit: Don't ignore "syslog = 0".
[Samba.git] / selftest / output / plain.pm
blob82a73ab932426c0b9ce194ddfd7037b2eee3869c
1 #!/usr/bin/perl
3 package output::plain;
4 use Exporter;
5 @ISA = qw(Exporter);
7 use FindBin qw($RealBin);
8 use lib "$RealBin/..";
10 use strict;
12 sub new($$$$$$$) {
13 my ($class, $summaryfile, $verbose, $immediate, $statistics, $totaltests) = @_;
14 my $self = {
15 verbose => $verbose,
16 immediate => $immediate,
17 statistics => $statistics,
18 start_time => time(),
19 test_output => {},
20 suitesfailed => [],
21 suites_ok => 0,
22 skips => {},
23 summaryfile => $summaryfile,
24 index => 0,
25 totalsuites => $totaltests,
27 bless($self, $class);
30 sub output_msg($$);
32 sub start_testsuite($$)
34 my ($self, $name) = @_;
36 $self->{index}++;
37 $self->{NAME} = $name;
38 $self->{START_TIME} = time();
40 my $duration = $self->{START_TIME} - $self->{start_time};
42 $self->{test_output}->{$name} = "" unless($self->{verbose});
44 my $out = "";
45 $out .= "[$self->{index}/$self->{totalsuites} in ".$duration."s";
46 $out .= sprintf(", %d errors", ($#{$self->{suitesfailed}}+1)) if ($#{$self->{suitesfailed}} > -1);
47 $out .= "] $name";
48 if ($self->{immediate}) {
49 print "$out\n";
50 } else {
51 print "$out: ";
55 sub output_msg($$)
57 my ($self, $output) = @_;
59 if ($self->{verbose}) {
60 require FileHandle;
61 print $output;
62 STDOUT->flush();
63 } else {
64 $self->{test_output}->{$self->{NAME}} .= $output;
68 sub control_msg($$)
70 my ($self, $output) = @_;
72 $self->output_msg($output);
75 sub end_testsuite($$$$$)
77 my ($self, $name, $result, $unexpected, $reason) = @_;
78 my $out = "";
80 if ($unexpected) {
81 if ($result eq "success" and not defined($reason)) {
82 $reason = "Expected negative exit code, got positive exit code";
84 $self->output_msg("ERROR: $reason\n");
85 push (@{$self->{suitesfailed}}, $name);
86 } else {
87 $self->{suites_ok}++;
90 if ($unexpected and $self->{immediate} and not $self->{verbose}) {
91 $out .= $self->{test_output}->{$name};
94 if (not $self->{immediate}) {
95 if (not $unexpected) {
96 $out .= " ok\n";
97 } else {
98 $out .= " " . uc($result) . "\n";
102 print $out;
105 sub start_test($$$)
107 my ($self, $parents, $testname) = @_;
109 if ($#$parents == -1) {
110 $self->start_testsuite($testname);
114 sub end_test($$$$$)
116 my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
118 if ($#$parents == -1) {
119 $self->end_testsuite($testname, $result, $unexpected, $reason);
120 return;
123 my $append = "";
125 unless ($unexpected) {
126 $self->{test_output}->{$self->{NAME}} = "";
127 if (not $self->{immediate}) {
128 if ($result eq "failure") { print "f"; }
129 elsif ($result eq "skip") { print "s"; }
130 elsif ($result eq "success") { print "."; }
131 else { print "?($result)"; }
133 return;
136 my $fullname = join(".", @$parents).".$testname";
138 $append = "UNEXPECTED($result): $testname ($fullname)\n";
140 $self->{test_output}->{$self->{NAME}} .= $append;
142 if ($self->{immediate} and not $self->{verbose}) {
143 print $self->{test_output}->{$self->{NAME}};
144 $self->{test_output}->{$self->{NAME}} = "";
147 if (not $self->{immediate}) {
148 if ($result eq "error") { print "E"; }
149 elsif ($result eq "failure") { print "F"; }
150 elsif ($result eq "success") { print "S"; }
151 else { print "?"; }
155 sub summary($)
157 my ($self) = @_;
159 open(SUMMARY, ">$self->{summaryfile}");
161 if ($#{$self->{suitesfailed}} > -1) {
162 print SUMMARY "= Failed tests =\n";
164 foreach (@{$self->{suitesfailed}}) {
165 print SUMMARY "== $_ ==\n";
166 print SUMMARY $self->{test_output}->{$_}."\n\n";
169 print SUMMARY "\n";
172 if (not $self->{immediate} and not $self->{verbose}) {
173 foreach (@{$self->{suitesfailed}}) {
174 print "===============================================================================\n";
175 print "FAIL: $_\n";
176 print $self->{test_output}->{$_};
177 print "\n";
181 print SUMMARY "= Skipped tests =\n";
182 foreach my $reason (keys %{$self->{skips}}) {
183 print SUMMARY "$reason\n";
184 foreach my $name (@{$self->{skips}->{$reason}}) {
185 print SUMMARY "\t$name\n";
187 print SUMMARY "\n";
189 close(SUMMARY);
191 print "\nA summary with detailed information can be found in:\n $self->{summaryfile}\n";
193 if ($#{$self->{suitesfailed}} == -1) {
194 my $ok = $self->{statistics}->{TESTS_EXPECTED_OK} +
195 $self->{statistics}->{TESTS_EXPECTED_FAIL};
196 print "\nALL OK ($ok tests in $self->{suites_ok} testsuites)\n";
197 } else {
198 print "\nFAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in ". ($#{$self->{suitesfailed}}+1) ." testsuites)\n";
203 sub skip_testsuite($$)
205 my ($self, $name, $reason) = @_;
207 push (@{$self->{skips}->{$reason}}, $name);
209 $self->{totalsuites}--;