WHATSNEW: Update changes since 3.4.0pre2.
[Samba/gbeck.git] / selftest / Subunit.pm
blob05e51da541206ad2c475de4be255fb9c8cc2dc65
1 package Subunit;
3 require Exporter;
4 @ISA = qw(Exporter);
5 @EXPORT_OK = qw(parse_results);
7 use strict;
9 sub parse_results($$$$$)
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;
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|knownfail|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 my $terminated = 0;
30 while(<$fh>) {
31 $msg_ops->control_msg($_);
32 if ($_ eq "]\n") { $terminated = 1; last; } else { $reason .= $_; }
35 unless ($terminated) {
36 $statistics->{TESTS_ERROR}++;
37 $msg_ops->end_test($open_tests, $2, $1, 1, "reason interrupted");
38 return 1;
41 my $result = $1;
42 if ($1 eq "success" or $1 eq "successful") {
43 pop(@$open_tests); #FIXME: Check that popped value == $2
44 if ($expecting_failure->(join(".", @$open_tests) . ".$2")) {
45 $statistics->{TESTS_UNEXPECTED_OK}++;
46 $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
47 $unexpected_ok++;
48 } else {
49 $statistics->{TESTS_EXPECTED_OK}++;
50 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
52 } elsif ($1 eq "failure") {
53 pop(@$open_tests); #FIXME: Check that popped value == $2
54 if ($expecting_failure->(join(".", @$open_tests) . ".$2")) {
55 $statistics->{TESTS_EXPECTED_FAIL}++;
56 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
57 $expected_fail++;
58 } else {
59 $statistics->{TESTS_UNEXPECTED_FAIL}++;
60 $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
61 $unexpected_fail++;
63 } elsif ($1 eq "knownfail") {
64 pop(@$open_tests); #FIXME: Check that popped value == $2
65 $statistics->{TESTS_EXPECTED_FAIL}++;
66 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
67 } elsif ($1 eq "skip") {
68 $statistics->{TESTS_SKIP}++;
69 pop(@$open_tests); #FIXME: Check that popped value == $2
70 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
71 } elsif ($1 eq "error") {
72 $statistics->{TESTS_ERROR}++;
73 pop(@$open_tests); #FIXME: Check that popped value == $2
74 $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
75 $unexpected_err++;
77 } else {
78 $msg_ops->output_msg($_);
82 while ($#$open_tests > $orig_open_len) {
83 $msg_ops->end_test($open_tests, pop(@$open_tests), "error", 1,
84 "was started but never finished!");
85 $statistics->{TESTS_ERROR}++;
86 $unexpected_err++;
89 return 1 if $unexpected_err > 0;
90 return 1 if $unexpected_fail > 0;
91 return 1 if $unexpected_ok > 0 and $expected_fail > 0;
92 return 0 if $unexpected_ok > 0 and $expected_fail == 0;
93 return 0 if $expected_fail > 0;
94 return 1;