~percona-core/percona-server/5.1

« back to all changes in this revision

Viewing changes to Percona-Server/mysql-test/lib/Subunit.pm

  • Committer: Stewart Smith
  • Date: 2011-11-24 02:01:50 UTC
  • Revision ID: stewart@flamingspork.com-20111124020150-kotgwlsnl83tlahb
Import Percona Server patch: subunit.patch

=== added file 'mysql-test/lib/Subunit.pm'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Perl module for parsing and generating the Subunit protocol
 
2
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
 
3
#
 
4
#  Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
 
5
#  license at the users choice. A copy of both licenses are available in the
 
6
#  project source as Apache-2.0 and BSD. You may not use this file except in
 
7
#  compliance with one of these two licences.
 
8
#
 
9
#  Unless required by applicable law or agreed to in writing, software
 
10
#  distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
 
11
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 
12
#  license you chose for the specific language governing permissions and
 
13
#  limitations under that license.
 
14
 
 
15
package Subunit;
 
16
use POSIX;
 
17
 
 
18
use vars qw ( $VERSION );
 
19
 
 
20
$VERSION = '0.0.2';
 
21
 
 
22
use strict;
 
23
my $SUBUNIT_OUT= 'test_results.subunit';
 
24
# reset the file
 
25
open(SUBUNITOUT, ">$SUBUNIT_OUT");
 
26
close(SUBUNITOUT);
 
27
 
 
28
sub subunit_start_test($)
 
29
{
 
30
        my ($testname) = @_;
 
31
        open(SUBUNITOUT, ">>$SUBUNIT_OUT");
 
32
        print SUBUNITOUT "test: $testname\n";
 
33
        close(SUBUNITOUT);
 
34
        return;
 
35
}
 
36
 
 
37
sub subunit_end_test($$;$)
 
38
{
 
39
        my $name = shift;
 
40
        my $result = shift;
 
41
        my $reason = shift;
 
42
        open(SUBUNITOUT, ">>$SUBUNIT_OUT");
 
43
        if ($reason) {
 
44
                print SUBUNITOUT "$result: $name [\n";
 
45
                print SUBUNITOUT "$reason\n";
 
46
                print SUBUNITOUT "]\n";
 
47
        } else {
 
48
                print SUBUNITOUT "$result: $name\n";
 
49
        }
 
50
        close(SUBUNITOUT);
 
51
        return;
 
52
}
 
53
 
 
54
sub subunit_skip_test($;$)
 
55
{
 
56
        my $name = shift;
 
57
        my $reason = shift;
 
58
        subunit_end_test($name, "skip", $reason);
 
59
}
 
60
 
 
61
sub subunit_fail_test($;$)
 
62
{
 
63
        my $name = shift;
 
64
        my $reason = shift;
 
65
        subunit_end_test($name, "failure", $reason);
 
66
}
 
67
 
 
68
sub subunit_pass_test($;$)
 
69
{
 
70
        my $name = shift;
 
71
        my $reason = shift;
 
72
        subunit_end_test($name, "success", $reason);
 
73
}
 
74
 
 
75
sub subunit_xfail_test($;$)
 
76
{
 
77
        my $name = shift;
 
78
        my $reason = shift;
 
79
        subunit_end_test($name, "xfail", $reason);
 
80
}
 
81
 
 
82
sub report_time($)
 
83
{
 
84
        my ($time) = @_;
 
85
        my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
 
86
        open(SUBUNITOUT, ">>$SUBUNIT_OUT");
 
87
        printf SUBUNITOUT "time: %04d-%02d-%02d %02d:%02d:%02dZ\n", $year+1900, $mon, $mday, $hour, $min, $sec;
 
88
        close(SUBUNITOUT);
 
89
        return;
 
90
}
 
91
 
 
92
 
 
93
 
 
94
1;