1#!/usr/bin/perl -wT 2 3use strict; 4use lib 't/lib'; 5 6use Test::More tests => 14; 7 8use TAP::Parser; 9use TAP::Parser::IteratorFactory; 10 11sub tap_to_lines { 12 my $string = shift; 13 my @lines = ( $string =~ /.*\n/g ); 14 return \@lines; 15} 16 17my $tap = <<'END_TAP'; 181..4 19ok 1 - input file opened 20... this is junk 21not ok first line of the input valid # todo some data 22# this is a comment 23ok 3 - read the rest of the file 24not ok 4 - this is a real failure 25Bail out! We ran out of foobar. 26not ok 5 27END_TAP 28 29my $factory = TAP::Parser::IteratorFactory->new; 30my $parser = TAP::Parser->new( 31 { stream => $factory->make_iterator( tap_to_lines($tap) ), 32 } 33); 34 35# results() is sane? 36 37# check the test plan 38my $result = $parser->next(); 39 40# TEST 41ok $result->is_plan, 'We should have a plan'; 42 43# a normal, passing test 44 45my $test = $parser->next(); 46 47# TEST 48ok $test->is_test, '... and a test'; 49 50# junk lines should be preserved 51 52my $unknown = $parser->next(); 53 54# TEST 55ok $unknown->is_unknown, '... and an unknown line'; 56 57# a failing test, which also happens to have a directive 58 59my $failed = $parser->next(); 60 61# TEST 62ok $failed->is_test, '... and another test'; 63 64# comments 65 66my $comment = $parser->next(); 67 68# TEST 69ok $comment->is_comment, '... and a comment'; 70 71# another normal, passing test 72 73$test = $parser->next(); 74 75# TEST 76ok $test->is_test, '... and another test'; 77 78# a failing test 79 80$failed = $parser->next(); 81 82# TEST 83ok $failed->is_test, '... and yet another test'; 84 85# ok 5 # skip we have no description 86# skipped test 87my $bailout = $parser->next(); 88 89# TEST 90ok $bailout->is_bailout, 'And finally we should have a bailout'; 91 92# TEST 93is $bailout->as_string, 'We ran out of foobar.', 94 '... and as_string() should return the explanation'; 95 96# TEST 97is( $bailout->raw, 'Bail out! We ran out of foobar.', 98 '... and raw() should return the explanation' 99); 100 101# TEST 102is( $bailout->explanation, 'We ran out of foobar.', 103 '... and it should have the correct explanation' 104); 105 106my $more_tap = "1..1\nok 1 - input file opened\n"; 107 108my $second_parser = TAP::Parser->new( 109 { stream => $factory->make_iterator( [ split( /\n/, $more_tap ) ] ), 110 } 111); 112 113$result = $second_parser->next(); 114 115# TEST 116ok $result->is_plan(), "Result is not the leftover line"; 117 118$result = $second_parser->next(); 119 120# TEST 121ok $result->is_test(), "Result is a test"; 122 123# TEST 124ok $result->is_ok(), "The event has passed"; 125 126