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