r24339: Move output functions to separate files.
[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 end_testsuite($$$$$)
53 {
54         my ($self, $state, $expected_ret, $ret, $envlog) = @_;
55         my $out = "";
56
57         if ($ret != $expected_ret) {
58                 $self->output_msg($state, "ERROR: $ret\n");
59         }
60
61         if ($ret != $expected_ret and $self->{immediate} and not $self->{verbose}) {
62                 $out .= $self->{test_output}->{$state->{NAME}};
63         }
64
65         print $out;
66 }
67
68 sub start_test($$)
69 {
70         my ($state, $testname) = @_;
71 }
72
73 sub end_test($$$$)
74 {
75         my ($state, $testname, $result, $unexpected) = @_;
76 }
77
78 sub summary($)
79 {
80         my ($self) = @_;
81
82         if (not $self->{immediate} and not $self->{verbose}) {
83                 foreach (@{$self->{suitesfailed}}) {
84                         print "===============================================================================\n";
85                         print "FAIL: $_\n";
86                         print $self->{test_output}->{$_};
87                         print "\n";
88                 }
89         }
90
91         print "FAILED ($self->{statistics}->{TESTS_UNEXPECTED_FAIL} failures and $self->{statistics}->{TESTS_ERROR} errors in $self->{statistics}->{SUITES_FAIL} testsuites)\n";
92 }
93
94 sub missing_env($$$)
95 {
96         my ($self, $name, $envname) = @_;
97
98         print "FAIL: $name (ENV[$envname] not available!)\n";
99 }
100
101 1;