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);
28 my ($msg_ops, $fh) = @_;
29 my $expected_fail = 0;
33 if (/^test: (.+)\n/) {
34 $msg_ops->control_msg($_);
35 $msg_ops->start_test($1);
36 push (@$open_tests, $1);
37 } elsif (/^(success|successful|failure|fail|skip|knownfail|error|xfail): (.*?)( \[)?([ \t]*)( multipart)?\n/) {
38 $msg_ops->control_msg($_);
44 # reason may be specified in next lines
47 $msg_ops->control_msg($_);
48 if ($_ eq "]\n") { $terminated = 1; last; } else { $reason .= $_; }
51 unless ($terminated) {
52 $msg_ops->end_test($testname, "error",
53 "reason ($result) interrupted\n");
57 if ($result eq "success" or $result eq "successful") {
58 pop(@$open_tests); #FIXME: Check that popped value == $testname
59 $msg_ops->end_test($testname, "success", $reason);
60 } elsif ($result eq "xfail" or $result eq "knownfail") {
61 pop(@$open_tests); #FIXME: Check that popped value == $testname
62 $msg_ops->end_test($testname, "xfail", $reason);
64 } elsif ($result eq "failure" or $result eq "fail") {
65 pop(@$open_tests); #FIXME: Check that popped value == $testname
66 $msg_ops->end_test($testname, "failure", $reason);
67 } elsif ($result eq "skip") {
68 # Allow tests to be skipped without prior announcement of test
69 my $last = pop(@$open_tests);
70 if (defined($last) and $last ne $testname) {
71 push (@$open_tests, $testname);
73 $msg_ops->end_test($testname, "skip", $reason);
74 } elsif ($result eq "error") {
75 pop(@$open_tests); #FIXME: Check that popped value == $testname
76 $msg_ops->end_test($testname, "error", $reason);
79 $msg_ops->output_msg($_);
83 while ($#$open_tests+1 > 0) {
84 $msg_ops->end_test(pop(@$open_tests), "error",
85 "was started but never finished!\n");
92 print "test: $testname\n";
101 print "$result: $name [\n";
103 if (substr($reason, -1, 1) ne "\n") { print "\n"; }
106 print "$result: $name\n";
114 end_test($name, "skip", $reason);
121 end_test($name, "fail", $reason);
124 sub success_test($;$)
128 end_test($name, "success", $reason);
135 end_test($name, "xfail", $reason);
141 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
142 $sec = ($time - int($time) + $sec);
143 my $msg = sprintf("%f", $sec);
144 if (substr($msg, 1, 1) eq ".") {
147 printf "time: %04d-%02d-%02d %02d:%02d:%s\n", $year+1900, $mon+1, $mday, $hour, $min, $msg;
152 print "progress: pop\n";
157 print "progress: push\n";
162 my ($count, $whence) = @_;
164 unless(defined($whence)) {
168 print "progress: $whence$count\n";
171 # The following are Samba extensions:
173 sub start_testsuite($)
176 print "testsuite: $name\n";
179 sub skip_testsuite($;$)
181 my ($name, $reason) = @_;
183 print "skip-testsuite: $name [\n$reason\n]\n";
185 print "skip-testsuite: $name\n";
189 sub end_testsuite($$;$)
195 print "testsuite-$result: $name [\n";
199 print "testsuite-$result: $name\n";