1#!/usr/bin/perl -wT 2 3use strict; 4use lib 't/lib'; 5 6use Test::More tests => 33; 7 8use TAP::Parser; 9 10my $tap = <<'END_TAP'; 111..4 12ok 1 - input file opened 13... this is junk 14not ok first line of the input valid # todo some data 15# this is a comment 16ok 3 - read the rest of the file 17not ok 4 - this is a real failure 18Bail out! We ran out of foobar. 19END_TAP 20my $parser = TAP::Parser->new( { tap => $tap } ); 21isa_ok $parser, 'TAP::Parser', 22 '... we should be able to parse bailed out tests'; 23 24my @results; 25while ( my $result = $parser->next ) { 26 push @results => $result; 27} 28 29can_ok $parser, 'passed'; 30is $parser->passed, 3, 31 '... and we shold have the correct number of passed tests'; 32is_deeply [ $parser->passed ], [ 1, 2, 3 ], 33 '... and get a list of the passed tests'; 34 35can_ok $parser, 'failed'; 36is $parser->failed, 1, '... and the correct number of failed tests'; 37is_deeply [ $parser->failed ], [4], '... and get a list of the failed tests'; 38 39can_ok $parser, 'actual_passed'; 40is $parser->actual_passed, 2, 41 '... and we shold have the correct number of actually passed tests'; 42is_deeply [ $parser->actual_passed ], [ 1, 3 ], 43 '... and get a list of the actually passed tests'; 44 45can_ok $parser, 'actual_failed'; 46is $parser->actual_failed, 2, 47 '... and the correct number of actually failed tests'; 48is_deeply [ $parser->actual_failed ], [ 2, 4 ], 49 '... or get a list of the actually failed tests'; 50 51can_ok $parser, 'todo'; 52is $parser->todo, 1, 53 '... and we should have the correct number of TODO tests'; 54is_deeply [ $parser->todo ], [2], '... and get a list of the TODO tests'; 55 56ok !$parser->skipped, 57 '... and we should have the correct number of skipped tests'; 58 59# check the plan 60 61can_ok $parser, 'plan'; 62is $parser->plan, '1..4', '... and we should have the correct plan'; 63is $parser->tests_planned, 4, '... and the correct number of tests'; 64 65# results() is sane? 66 67ok @results, 'The parser should return results'; 68is scalar @results, 8, '... and there should be one for each line'; 69 70# check the test plan 71 72my $result = shift @results; 73ok $result->is_plan, 'We should have a plan'; 74 75# a normal, passing test 76 77my $test = shift @results; 78ok $test->is_test, '... and a test'; 79 80# junk lines should be preserved 81 82my $unknown = shift @results; 83ok $unknown->is_unknown, '... and an unknown line'; 84 85# a failing test, which also happens to have a directive 86 87my $failed = shift @results; 88ok $failed->is_test, '... and another test'; 89 90# comments 91 92my $comment = shift @results; 93ok $comment->is_comment, '... and a comment'; 94 95# another normal, passing test 96 97$test = shift @results; 98ok $test->is_test, '... and another test'; 99 100# a failing test 101 102$failed = shift @results; 103ok $failed->is_test, '... and yet another test'; 104 105# ok 5 # skip we have no description 106# skipped test 107my $bailout = shift @results; 108ok $bailout->is_bailout, 'And finally we should have a bailout'; 109is $bailout->as_string, 'We ran out of foobar.', 110 '... and as_string() should return the explanation'; 111is $bailout->raw, 'Bail out! We ran out of foobar.', 112 '... and raw() should return the explanation'; 113is $bailout->explanation, 'We ran out of foobar.', 114 '... and it should have the correct explanation'; 115