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+)\n/) {
40 $msg_ops->report_time(mktime
($6, $5, $4, $3, $2-1, $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,
58 "reason ($result) interrupted");
62 if ($result eq "success" or $result eq "successful") {
63 pop(@
$open_tests); #FIXME: Check that popped value == $testname
64 $statistics->{TESTS_EXPECTED_OK
}++;
65 $msg_ops->end_test($testname, "success", 0, $reason);
66 } elsif ($result eq "xfail" or $result eq "knownfail") {
67 pop(@
$open_tests); #FIXME: Check that popped value == $testname
68 $statistics->{TESTS_EXPECTED_FAIL
}++;
69 $msg_ops->end_test($testname, "xfail", 0, $reason);
71 } elsif ($result eq "failure" or $result eq "fail") {
72 pop(@
$open_tests); #FIXME: Check that popped value == $testname
73 $statistics->{TESTS_UNEXPECTED_FAIL
}++;
74 $msg_ops->end_test($testname, "failure", 1, $reason);
76 } elsif ($result eq "skip") {
77 $statistics->{TESTS_SKIP
}++;
78 # Allow tests to be skipped without prior announcement of test
79 my $last = pop(@
$open_tests);
80 if (defined($last) and $last ne $testname) {
81 push (@
$open_tests, $testname);
83 $msg_ops->end_test($testname, "skip", 0, $reason);
84 } elsif ($result eq "error") {
85 $statistics->{TESTS_ERROR
}++;
86 pop(@
$open_tests); #FIXME: Check that popped value == $testname
87 $msg_ops->end_test($testname, "error", 1, $reason);
89 } elsif ($result eq "skip-testsuite") {
90 $msg_ops->skip_testsuite($testname);
91 } elsif ($result eq "testsuite-success") {
92 $msg_ops->end_testsuite($testname, "success", $reason);
93 } elsif ($result eq "testsuite-failure") {
94 $msg_ops->end_testsuite($testname, "failure", $reason);
95 } elsif ($result eq "testsuite-xfail") {
96 $msg_ops->end_testsuite($testname, "xfail", $reason);
97 } elsif ($result eq "testsuite-error") {
98 $msg_ops->end_testsuite($testname, "error", $reason);
100 } elsif (/^testsuite: (.*)\n/) {
101 $msg_ops->start_testsuite($1);
102 } elsif (/^testsuite-count: (\d+)\n/) {
103 $msg_ops->testsuite_count($1);
105 $msg_ops->output_msg($_);
109 while ($#$open_tests+1 > 0) {
110 $msg_ops->end_test(pop(@
$open_tests), "error", 1,
111 "was started but never finished!");
112 $statistics->{TESTS_ERROR
}++;
116 return 1 if $unexpected_err > 0;
117 return 1 if $unexpected_fail > 0;
124 print "test: $testname\n";
133 print "$result: $name [\n";
137 print "$result: $name\n";
145 end_test
($name, "skip", $reason);
152 end_test
($name, "fail", $reason);
155 sub success_test
($;$)
159 end_test
($name, "success", $reason);
166 end_test
($name, "xfail", $reason);
172 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
173 printf "time: %04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec;
176 # The following are Samba extensions:
178 sub start_testsuite
($)
181 print "testsuite: $name\n";
184 sub skip_testsuite
($;$)
186 my ($name, $reason) = @_;
188 print "skip-testsuite: $name [\n$reason\n]\n";
190 print "skip-testsuite: $name\n";
194 sub end_testsuite
($$;$)
200 print "testsuite-$result: $name [\n";
204 print "testsuite-$result: $name\n";
208 sub testsuite_count
($)
211 print "testsuite-count: $count\n";