1 # Simple Perl module for parsing the Subunit protocol
2 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 @EXPORT_OK = qw(parse_results);
26 sub parse_results
($$$$)
28 my ($msg_ops, $statistics, $fh, $open_tests) = @_;
29 my $unexpected_ok = 0;
30 my $expected_fail = 0;
31 my $unexpected_fail = 0;
32 my $unexpected_err = 0;
33 my $orig_open_len = $#$open_tests;
36 if (/^test: (.+)\n/) {
37 $msg_ops->control_msg($_);
38 $msg_ops->start_test($open_tests, $1);
39 push (@
$open_tests, $1);
40 } elsif (/^time: (\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)Z\n/) {
41 $msg_ops->report_time(mktime
($6, $5, $4, $3, $2, $1));
42 } elsif (/^(success|successful|failure|fail|skip|knownfail|error|xfail): (.*?)( \[)?([ \t]*)\n/) {
43 $msg_ops->control_msg($_);
47 # reason may be specified in next lines
50 $msg_ops->control_msg($_);
51 if ($_ eq "]\n") { $terminated = 1; last; } else { $reason .= $_; }
54 unless ($terminated) {
55 $statistics->{TESTS_ERROR
}++;
56 $msg_ops->end_test($open_tests, $2, $1, 1, "reason interrupted");
61 if ($1 eq "success" or $1 eq "successful") {
62 pop(@
$open_tests); #FIXME: Check that popped value == $2
63 $statistics->{TESTS_EXPECTED_OK
}++;
64 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
65 } elsif ($1 eq "xfail" or $1 eq "knownfail") {
66 pop(@
$open_tests); #FIXME: Check that popped value == $2
67 $statistics->{TESTS_EXPECTED_FAIL
}++;
68 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
70 } elsif ($1 eq "failure" or $1 eq "fail") {
71 pop(@
$open_tests); #FIXME: Check that popped value == $2
72 $statistics->{TESTS_UNEXPECTED_FAIL
}++;
73 $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
75 } elsif ($1 eq "skip") {
76 $statistics->{TESTS_SKIP
}++;
77 pop(@
$open_tests); #FIXME: Check that popped value == $2
78 $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
79 } elsif ($1 eq "error") {
80 $statistics->{TESTS_ERROR
}++;
81 pop(@
$open_tests); #FIXME: Check that popped value == $2
82 $msg_ops->end_test($open_tests, $2, $1, 1, $reason);
86 $msg_ops->output_msg($_);
90 while ($#$open_tests > $orig_open_len) {
91 $msg_ops->end_test($open_tests, pop(@
$open_tests), "error", 1,
92 "was started but never finished!");
93 $statistics->{TESTS_ERROR
}++;
97 return 1 if $unexpected_err > 0;
98 return 1 if $unexpected_fail > 0;
99 return 1 if $unexpected_ok > 0 and $expected_fail > 0;
100 return 0 if $unexpected_ok > 0 and $expected_fail == 0;
101 return 0 if $expected_fail > 0;
108 print "test: $testname\n";
117 print "$result: $name [ $reason ]\n";
119 print "$result: $name\n";
126 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
127 printf "time: %04d-%02d-%02d %02d:%02d:%02dZ\n", $year+1900, $mon, $mday, $hour, $min, $sec;