6 use Test::More tests => 14;
9 use TAP::Parser::IteratorFactory;
13 my @lines = ( $string =~ /.*\n/g );
17 my $tap = <<'END_TAP';
19 ok 1 - input file opened
21 not ok first line of the input valid # todo some data
23 ok 3 - read the rest of the file
24 not ok 4 - this is a real failure
25 Bail out! We ran out of foobar.
29 my $factory = TAP::Parser::IteratorFactory->new;
30 my $parser = TAP::Parser->new(
31 { stream => $factory->make_iterator( tap_to_lines($tap) ),
38 my $result = $parser->next();
41 ok $result->is_plan, 'We should have a plan';
43 # a normal, passing test
45 my $test = $parser->next();
48 ok $test->is_test, '... and a test';
50 # junk lines should be preserved
52 my $unknown = $parser->next();
55 ok $unknown->is_unknown, '... and an unknown line';
57 # a failing test, which also happens to have a directive
59 my $failed = $parser->next();
62 ok $failed->is_test, '... and another test';
66 my $comment = $parser->next();
69 ok $comment->is_comment, '... and a comment';
71 # another normal, passing test
73 $test = $parser->next();
76 ok $test->is_test, '... and another test';
80 $failed = $parser->next();
83 ok $failed->is_test, '... and yet another test';
85 # ok 5 # skip we have no description
87 my $bailout = $parser->next();
90 ok $bailout->is_bailout, 'And finally we should have a bailout';
93 is $bailout->as_string, 'We ran out of foobar.',
94 '... and as_string() should return the explanation';
97 is( $bailout->raw, 'Bail out! We ran out of foobar.',
98 '... and raw() should return the explanation'
102 is( $bailout->explanation, 'We ran out of foobar.',
103 '... and it should have the correct explanation'
106 my $more_tap = "1..1\nok 1 - input file opened\n";
108 my $second_parser = TAP::Parser->new(
109 { stream => $factory->make_iterator( [ split( /\n/, $more_tap ) ] ),
113 $result = $second_parser->next();
116 ok $result->is_plan(), "Result is not the leftover line";
118 $result = $second_parser->next();
121 ok $result->is_test(), "Result is a test";
124 ok $result->is_ok(), "The event has passed";