bbf0f8f41423c472681cf29844dc878f73ec3515
[kai/samba.git] / source4 / selftest / output / plain.pm
1 #!/usr/bin/perl
2
3 package output::plain;
4 use Exporter;
5 @ISA = qw(Exporter);
6
7 use strict;
8
9 sub new($$$$) {
10         my ($class, $verbose, $immediate, $statistics) = @_;
11         my $self = { 
12                 verbose => $verbose, 
13                 immediate => $immediate, 
14                 statistics => $statistics,
15                 test_output => {},
16                 suitesfailed => [],
17                 start => time()
18         };
19         bless($self, $class);
20 }
21
22 sub output_msg($$$);
23
24 sub start_testsuite($$)
25 {
26         my ($self, $state) = @_;
27         my $out = "";
28
29         my $duration = $state->{START_TIME} - $self->{statistics}->{START_TIME};
30         $out .= "[$state->{INDEX}/$state->{TOTAL} in ".$duration."s";
31         $out .= sprintf(", %d errors", $self->{statistics}->{SUITES_FAIL}) if ($self->{statistics}->{SUITES_FAIL} > 0);
32         $out .= "] $state->{NAME}\n", 
33
34         $self->{test_output}->{$state->{NAME}} = "" unless($self->{verbose});
35
36         $self->output_msg($state, "CMD: $state->{CMD}\n");
37
38         print $out;
39 }
40
41 sub output_msg($$$)
42 {
43         my ($self, $state, $output) = @_;
44
45         if ($self->{verbose}) {
46                 print $output;
47         } else {
48                 $self->{test_output}->{$state->{NAME}} .= $output;
49         }
50 }
51
52 sub control_msg($$$)
53 {
54         my ($self, $state, $output) = @_;
55
56         $self->output_msg($state, $output);
57 }
58
59 sub end_testsuite($$$$$)
60 {
61         my ($self, $state, $expected_ret, $ret, $envlog) = @_;
62         my $out = "";
63
64         if ($ret != $expected_ret) {
65                 $self->output_msg($state, "ERROR: $ret\n");
66         }
67
68         if ($ret != $expected_ret and $self->{immediate} and not $self->{verbose}) {
69                 $out .= $self->{test_output}->{$state->{NAME}};
70         }
71
72         print $out;
73 }
74
75 sub start_test($$)
76 {
77         my ($state, $testname) = @_;
78 }
79
80 sub end_test($$$$$)
81 {
82         my ($state, $testname, $result, $unexpected, $reason) = @_;
83 }
84
85 sub summary($)
86 {
87         my ($self) = @_;
88
89         if (not $self->{immediate} and not $self->{verbose}) {
90                 foreach (@{$self->{suitesfailed}}) {
91                         print "===============================================================================\n";
92                         print "FAIL: $_\n";
93                         print $self->{test_output}->{$_};
94                         print "\n";
95                 }
96         }
97
98         if ($self->{statistics}->{SUITES_FAIL} == 0) {
99                 my $ok = $self->{statistics}->{TESTS_EXPECTED_OK} + 
100                                  $self->{statistics}->{TESTS_EXPECTED_FAIL};
101                 print "ALL OK ($ok tests in $self->{statistics}->{SUITES_OK} testsuites)\n";
102         } else {
103                 print "FAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n";
104         }
105 }
106
107 sub missing_env($$$)
108 {
109         my ($self, $name, $envname) = @_;
110
111         print "FAIL: $name (ENV[$envname] not available!)\n";
112 }
113
114 sub skip_testsuite($$$)
115 {
116         my ($self, $envname, $name, $reason) = @_;
117
118         if ($reason) {
119                 print "SKIPPED: $name [$reason]\n";
120         } else {
121                 print "SKIPPED: $name\n";
122         }
123 }
124
125 1;