Track /etc/gitconfig
[msysgit/mtrensch.git] / lib / perl5 / 5.8.8 / Test / Harness / Point.pm
blob9f82fe9fc98b292172ab3a4d982b512765a128be
1 # -*- Mode: cperl; cperl-indent-level: 4 -*-
2 package Test::Harness::Point;
4 use strict;
5 use vars qw($VERSION);
6 $VERSION = '0.01';
8 =head1 NAME
10 Test::Harness::Point - object for tracking a single test point
12 =head1 SYNOPSIS
14 One Test::Harness::Point object represents a single test point.
16 =head1 CONSTRUCTION
18 =head2 new()
20 my $point = new Test::Harness::Point;
22 Create a test point object.
24 =cut
26 sub new {
27 my $class = shift;
28 my $self = bless {}, $class;
30 return $self;
33 my $test_line_regex = qr/
35 (not\ )? # failure?
36 ok\b
37 (?:\s+(\d+))? # optional test number
38 \s*
39 (.*) # and the rest
40 /ox;
42 =head1 from_test_line( $line )
44 Constructor from a TAP test line, or empty return if the test line
45 is not a test line.
47 =cut
49 sub from_test_line {
50 my $class = shift;
51 my $line = shift or return;
53 # We pulverize the line down into pieces in three parts.
54 my ($not, $number, $extra) = ($line =~ $test_line_regex ) or return;
56 my $point = $class->new;
57 $point->set_number( $number );
58 $point->set_ok( !$not );
60 if ( $extra ) {
61 my ($description,$directive) = split( /(?:[^\\]|^)#/, $extra, 2 );
62 $description =~ s/^- //; # Test::More puts it in there
63 $point->set_description( $description );
64 if ( $directive ) {
65 $point->set_directive( $directive );
67 } # if $extra
69 return $point;
70 } # from_test_line()
72 =head1 ACCESSORS
74 Each of the following fields has a getter and setter method.
76 =over 4
78 =item * ok
80 =item * number
82 =cut
84 sub ok { my $self = shift; $self->{ok} }
85 sub set_ok {
86 my $self = shift;
87 my $ok = shift;
88 $self->{ok} = $ok ? 1 : 0;
90 sub pass {
91 my $self = shift;
93 return ($self->ok || $self->is_todo || $self->is_skip) ? 1 : 0;
96 sub number { my $self = shift; $self->{number} }
97 sub set_number { my $self = shift; $self->{number} = shift }
99 sub description { my $self = shift; $self->{description} }
100 sub set_description {
101 my $self = shift;
102 $self->{description} = shift;
103 $self->{name} = $self->{description}; # history
106 sub directive { my $self = shift; $self->{directive} }
107 sub set_directive {
108 my $self = shift;
109 my $directive = shift;
111 $directive =~ s/^\s+//;
112 $directive =~ s/\s+$//;
113 $self->{directive} = $directive;
115 my ($type,$reason) = ($directive =~ /^\s*(\S+)(?:\s+(.*))?$/);
116 $self->set_directive_type( $type );
117 $reason = "" unless defined $reason;
118 $self->{directive_reason} = $reason;
120 sub set_directive_type {
121 my $self = shift;
122 $self->{directive_type} = lc shift;
123 $self->{type} = $self->{directive_type}; # History
125 sub set_directive_reason {
126 my $self = shift;
127 $self->{directive_reason} = shift;
129 sub directive_type { my $self = shift; $self->{directive_type} }
130 sub type { my $self = shift; $self->{directive_type} }
131 sub directive_reason{ my $self = shift; $self->{directive_reason} }
132 sub reason { my $self = shift; $self->{directive_reason} }
133 sub is_todo {
134 my $self = shift;
135 my $type = $self->directive_type;
136 return $type && ( $type eq 'todo' );
138 sub is_skip {
139 my $self = shift;
140 my $type = $self->directive_type;
141 return $type && ( $type eq 'skip' );
144 sub diagnostics {
145 my $self = shift;
146 return @{$self->{diagnostics}} if wantarray;
147 return join( "\n", @{$self->{diagnostics}} );
149 sub add_diagnostic { my $self = shift; push @{$self->{diagnostics}}, @_ }