Fix and test python scripts and kerberos
[samba.git] / source4 / selftest / Subunit.pm
1 package Subunit;
2
3 require Exporter;
4 @ISA = qw(Exporter);
5 @EXPORT_OK = qw(parse_results);
6
7 use strict;
8
9 sub parse_results($$$$$)
10 {
11         my ($msg_ops, $statistics, $fh, $expecting_failure, $open_tests) = @_;
12         my $unexpected_ok = 0;
13         my $expected_fail = 0;
14         my $unexpected_fail = 0;
15         my $unexpected_err = 0;
16         my $orig_open_len = $#$open_tests;
17
18         while(<$fh>) {
19                 if (/^test: (.+)\n/) {
20                         $msg_ops->control_msg($_);
21                         $msg_ops->start_test($open_tests, $1);
22                         push (@$open_tests, $1);
23                 } elsif (/^(success|successful|failure|skip|error): (.*?)( \[)?([ \t]*)\n/) {
24                         $msg_ops->control_msg($_);
25                         my $reason = undef;
26                         if ($3) {
27                                 $reason = "";
28                                 # reason may be specified in next lines
29                                 while(<$fh>) {
30                                         $msg_ops->control_msg($_);
31                                         if ($_ eq "]\n") { last; } else { $reason .= $_; }
32                                 }
33                         }
34                         my $result = $1;
35                         if ($1 eq "success" or $1 eq "successful") {
36                                 pop(@$open_tests); #FIXME: Check that popped value == $2
37                                 if ($expecting_failure->(join(".", @$open_tests) . ".$2")) {
38                                         $statistics->{TESTS_UNEXPECTED_OK}++;
39                                         $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
40                                         $unexpected_ok++;
41                                 } else {
42                                         $statistics->{TESTS_EXPECTED_OK}++;
43                                         $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
44                                 }
45                         } elsif ($1 eq "failure") {
46                                 pop(@$open_tests); #FIXME: Check that popped value == $2
47                                 if ($expecting_failure->(join(".", @$open_tests) . ".$2")) {
48                                         $statistics->{TESTS_EXPECTED_FAIL}++;
49                                         $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
50                                         $expected_fail++;
51                                 } else {
52                                         $statistics->{TESTS_UNEXPECTED_FAIL}++;
53                                         $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
54                                         $unexpected_fail++;
55                                 }
56                         } elsif ($1 eq "skip") {
57                                 $statistics->{TESTS_SKIP}++;
58                                 pop(@$open_tests); #FIXME: Check that popped value == $2
59                                 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
60                         } elsif ($1 eq "error") {
61                                 $statistics->{TESTS_ERROR}++;
62                                 pop(@$open_tests); #FIXME: Check that popped value == $2
63                                 $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
64                                 $unexpected_err++;
65                         }
66                 } else {
67                         $msg_ops->output_msg($_);
68                 }
69         }
70
71         while ($#$open_tests > $orig_open_len) {
72                 $msg_ops->end_test($open_tests, pop(@$open_tests), "error", 1,
73                                    "was started but never finished!");
74                 $statistics->{TESTS_ERROR}++;
75                 $unexpected_err++;
76         }
77
78         return 1 if $unexpected_err > 0;
79         return 1 if $unexpected_fail > 0;
80         return 1 if $unexpected_ok > 0 and $expected_fail > 0;
81         return 0 if $unexpected_ok > 0 and $expected_fail == 0;
82         return 0 if $expected_fail > 0;
83         return 1;
84 }
85
86 1;