#!/usr/bin/perl -wT
sub
tap_to_lines {
my
$string
=
shift
;
my
@lines
= (
$string
=~ /.*\n/g );
return
\
@lines
;
}
my
$tap
=
<<'END_TAP';
1..4
ok 1 - input file opened
... this is junk
not ok first line of the input valid # todo some data
# this is a comment
ok 3 - read the rest of the file
not ok 4 - this is a real failure
Bail out! We ran out of foobar.
not ok 5
END_TAP
my
$parser
= TAP::Parser->new(
{
iterator
=> TAP::Parser::Iterator::Array->new( tap_to_lines(
$tap
) ),
}
);
my
$result
=
$parser
->
next
();
ok
$result
->is_plan,
'We should have a plan'
;
my
$test
=
$parser
->
next
();
ok
$test
->is_test,
'... and a test'
;
my
$unknown
=
$parser
->
next
();
ok
$unknown
->is_unknown,
'... and an unknown line'
;
my
$failed
=
$parser
->
next
();
ok
$failed
->is_test,
'... and another test'
;
my
$comment
=
$parser
->
next
();
ok
$comment
->is_comment,
'... and a comment'
;
$test
=
$parser
->
next
();
ok
$test
->is_test,
'... and another test'
;
$failed
=
$parser
->
next
();
ok
$failed
->is_test,
'... and yet another test'
;
my
$bailout
=
$parser
->
next
();
ok
$bailout
->is_bailout,
'And finally we should have a bailout'
;
is
$bailout
->as_string,
'We ran out of foobar.'
,
'... and as_string() should return the explanation'
;
is(
$bailout
->raw,
'Bail out! We ran out of foobar.'
,
'... and raw() should return the explanation'
);
is(
$bailout
->explanation,
'We ran out of foobar.'
,
'... and it should have the correct explanation'
);
my
$more_tap
=
"1..1\nok 1 - input file opened\n"
;
my
$second_parser
= TAP::Parser->new(
{
iterator
=>
TAP::Parser::Iterator::Array->new( [
split
( /\n/,
$more_tap
) ] ),
}
);
$result
=
$second_parser
->
next
();
ok
$result
->is_plan(),
"Result is not the leftover line"
;
$result
=
$second_parser
->
next
();
ok
$result
->is_test(),
"Result is a test"
;
ok
$result
->is_ok(),
"The event has passed"
;