4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
15 use Test::More tests => 147;
18 use_ok('Test::Harness::Straps');
20 my $strap = Test::Harness::Straps->new;
21 ok( defined $strap && $strap->isa("Test::Harness::Straps"), 'new()' );
24 ### Testing _is_comment()
27 ok( !$strap->_is_comment("foo", \$comment), '_is_comment(), not a comment' );
28 ok( !defined $comment, ' no comment set' );
30 ok( !$strap->_is_comment("f # oo", \$comment), ' not a comment with #' );
31 ok( !defined $comment, ' no comment set' );
34 "# stuff and things # and stuff" =>
35 ' stuff and things # and stuff',
36 " # more things " => ' more things ',
40 while( my($line, $line_comment) = each %comments ) {
41 my $strap = Test::Harness::Straps->new;
43 my $name = substr($line, 0, 20);
44 ok( $strap->_is_comment($line, \$comment), " comment '$name'" );
45 is( $comment, $line_comment, ' right comment set' );
50 ### Testing _is_header()
52 my @not_headers = (' 1..2',
60 foreach my $unheader (@not_headers) {
61 my $strap = Test::Harness::Straps->new;
63 ok( !$strap->_is_header($unheader),
64 "_is_header(), not a header '$unheader'" );
66 ok( (!grep { exists $strap->{$_} } qw(max todo skip_all)),
67 " max, todo and skip_all are not set" );
71 my @attribs = qw(max skip_all todo);
73 '1..2' => { max => 2 },
74 '1..1' => { max => 1 },
78 '1..0 # Skipped: no leverage found' => { max => 0,
79 skip_all => 'no leverage found',
81 '1..4 # Skipped: no leverage found' => { max => 4,
82 skip_all => 'no leverage found',
84 '1..0 # skip skip skip because' => { max => 0,
85 skip_all => 'skip skip because',
87 '1..10 todo 2 4 10' => { max => 10,
93 '1..10 todo' => { max => 10 },
94 '1..192 todo 4 2 13 192 # Skip skip skip because' =>
101 skip_all => 'skip skip because'
105 while( my($header, $expect) = each %headers ) {
106 my $strap = Test::Harness::Straps->new;
108 ok( $strap->_is_header($header), "_is_header() is a header '$header'" );
110 is( $strap->{skip_all}, $expect->{skip_all}, ' skip_all set right' )
111 if defined $expect->{skip_all};
113 ok( eq_set( [map $strap->{$_}, grep defined $strap->{$_}, @attribs],
114 [map $expect->{$_}, grep defined $expect->{$_}, @attribs] ),
115 ' the right attributes are there' );
120 ### Testing _is_test()
123 'ok' => { 'ok' => 1 },
124 'not ok' => { 'ok' => 0 },
126 'ok 1' => { 'ok' => 1, number => 1 },
127 'not ok 1' => { 'ok' => 0, number => 1 },
129 'ok 2938' => { 'ok' => 1, number => 2938 },
131 'ok 1066 - and all that' => { 'ok' => 1,
133 name => "- and all that" },
134 'not ok 42 - universal constant' =>
137 name => '- universal constant',
139 'not ok 23 # TODO world peace' => { 'ok' => 0,
142 reason => 'world peace'
144 'ok 11 - have life # TODO get a life' =>
147 name => '- have life',
149 reason => 'get a life'
151 'not ok # TODO' => { 'ok' => 0,
155 'ok # skip' => { 'ok' => 1,
158 'not ok 11 - this is \# all the name # skip this is not'
161 name => '- this is \# all the name',
163 reason => 'this is not'
165 "ok 42 - _is_header() is a header '1..192 todo 4 2 13 192 \\# Skip skip skip because"
168 name => "- _is_header() is a header '1..192 todo 4 2 13 192 \\# Skip skip skip because",
172 while( my($line, $expect) = each %tests ) {
174 ok( $strap->_is_test($line, \%test), "_is_test() spots '$line'" );
176 foreach my $type (qw(ok number name type reason)) {
177 cmp_ok( $test{$type}, 'eq', $expect->{$type}, " $type" );
186 foreach my $line (@untests) {
187 my $strap = Test::Harness::Straps->new;
189 ok( !$strap->_is_test($line, \%test), "_is_test() disregards '$line'" );
191 # is( keys %test, 0 ) won't work in 5.004 because it's undef.
192 ok( !keys %test, ' and produces no test info' );
196 ### Test _is_bail_out()
199 'Bail out!' => undef,
200 'Bail out! Wing on fire.' => 'Wing on fire.',
201 'BAIL OUT!' => undef,
202 'bail out! - Out of coffee' => '- Out of coffee',
205 while( my($line, $expect) = each %bails ) {
206 my $strap = Test::Harness::Straps->new;
208 ok( $strap->_is_bail_out($line, \$reason), "_is_bail_out() spots '$line'");
209 is( $reason, $expect, ' with the right reason' );
219 foreach my $line (@unbails) {
220 my $strap = Test::Harness::Straps->new;
223 ok( !$strap->_is_bail_out($line, \$reason),
224 "_is_bail_out() ignores '$line'" );
225 is( $reason, undef, ' and gives no reason' );