1 # Perl module for parsing and generating the Subunit protocol
2 # Copyright (C) 2008-2009 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) = @_;
29 my $expected_fail = 0;
30 my $unexpected_fail = 0;
31 my $unexpected_err = 0;
35 if (/^test: (.+)\n/) {
36 $msg_ops->control_msg($_);
37 $msg_ops->start_test($1);
38 push (@$open_tests, $1);
39 } elsif (/^time: (\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)Z\n/) {
40 $msg_ops->report_time(mktime($6, $5, $4, $3, $2, $1-1900));
41 } elsif (/^(success|successful|failure|fail|skip|knownfail|error|xfail|skip-testsuite|testsuite-failure|testsuite-xfail|testsuite-success|testsuite-error): (.*?)( \[)?([ \t]*)\n/) {
42 $msg_ops->control_msg($_);
48 # reason may be specified in next lines
51 $msg_ops->control_msg($_);
52 if ($_ eq "]\n") { $terminated = 1; last; } else { $reason .= $_; }
55 unless ($terminated) {
56 $statistics->{TESTS_ERROR}++;
57 $msg_ops->end_test($testname, "error", 1, "reason ($result) interrupted");
61 if ($result eq "success" or $result eq "successful") {
62 pop(@$open_tests); #FIXME: Check that popped value == $testname
63 $statistics->{TESTS_EXPECTED_OK}++;
64 $msg_ops->end_test($testname, $result, 0, $reason);
65 } elsif ($result eq "xfail" or $result eq "knownfail") {
66 pop(@$open_tests); #FIXME: Check that popped value == $testname
67 $statistics->{TESTS_EXPECTED_FAIL}++;
68 $msg_ops->end_test($testname, $result, 0, $reason);
70 } elsif ($result eq "failure" or $result eq "fail") {
71 pop(@$open_tests); #FIXME: Check that popped value == $testname
72 $statistics->{TESTS_UNEXPECTED_FAIL}++;
73 $msg_ops->end_test($testname, $result, 1, $reason);
75 } elsif ($result eq "skip") {
76 $statistics->{TESTS_SKIP}++;
77 my $last = pop(@$open_tests);
78 if (defined($last) and $last ne $testname) {
79 push (@$open_tests, $testname);
81 $msg_ops->end_test($testname, $result, 0, $reason);
82 } elsif ($result eq "error") {
83 $statistics->{TESTS_ERROR}++;
84 pop(@$open_tests); #FIXME: Check that popped value == $testname
85 $msg_ops->end_test($testname, $result, 1, $reason);
87 } elsif ($result eq "skip-testsuite") {
88 $msg_ops->skip_testsuite($testname);
89 } elsif ($result eq "testsuite-success") {
90 $msg_ops->end_testsuite($testname, "success", $reason);
91 } elsif ($result eq "testsuite-failure") {
92 $msg_ops->end_testsuite($testname, "failure", $reason);
93 } elsif ($result eq "testsuite-xfail") {
94 $msg_ops->end_testsuite($testname, "xfail", $reason);
95 } elsif ($result eq "testsuite-error") {
96 $msg_ops->end_testsuite($testname, "error", $reason);
98 } elsif (/^testsuite: (.*)\n/) {
99 $msg_ops->start_testsuite($1);
100 } elsif (/^testsuite-count: (\d+)\n/) {
101 $msg_ops->testsuite_count($1);
103 $msg_ops->output_msg($_);
107 while ($#$open_tests+1 > 0) {
108 $msg_ops->end_test(pop(@$open_tests), "error", 1,
109 "was started but never finished!");
110 $statistics->{TESTS_ERROR}++;
114 return 1 if $unexpected_err > 0;
115 return 1 if $unexpected_fail > 0;
122 print "test: $testname\n";
131 print "$result: $name [\n";
135 print "$result: $name\n";
143 end_test($name, "skip", $reason);
150 end_test($name, "fail", $reason);
153 sub success_test($;$)
157 end_test($name, "success", $reason);
164 end_test($name, "xfail", $reason);
170 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
171 printf "time: %04d-%02d-%02d %02d:%02d:%02dZ\n", $year+1900, $mon, $mday, $hour, $min, $sec;
174 # The following are Samba extensions:
176 sub start_testsuite($)
179 print "testsuite: $name\n";
182 sub skip_testsuite($;$)
184 my ($name, $reason) = @_;
186 print "skip-testsuite: $name [\n$reason\n]\n";
188 print "skip-testsuite: $name\n";
192 sub end_testsuite($$;$)
198 print "testsuite-$result: $name [\n";
202 print "testsuite-$result: $name\n";
206 sub testsuite_count($)
209 print "testsuite-count: $count\n";