6 use Test::More tests => 23;
10 my $plan_line = 'TAP::Parser::Result::Plan';
11 my $test_line = 'TAP::Parser::Result::Test';
14 my $parser = TAP::Parser->new( { tap => shift } );
21 my $parser = _parser(<<'END_TAP');
22 ok 1 - input file opened
23 not ok 2 - first line of the input valid # todo some data
24 ok 3 - read the rest of the file
26 # comments are allowed after an ending plan
29 can_ok $parser, 'parse_errors';
30 ok !$parser->parse_errors,
31 '... comments should be allowed after a terminating plan';
33 $parser = _parser(<<'END_TAP');
34 ok 1 - input file opened
35 not ok 2 - first line of the input valid # todo some data
36 ok 3 - read the rest of the file
42 can_ok $parser, 'parse_errors';
43 is scalar $parser->parse_errors, 2, '... and we should have two parse errors';
45 is [ $parser->parse_errors ]->[0],
46 'Plan (1..3) must be at the beginning or end of the TAP output',
47 '... telling us that our plan was misplaced';
48 is [ $parser->parse_errors ]->[1],
49 'Bad plan. You planned 3 tests but ran 4.',
50 '... and telling us we ran the wrong number of tests.';
52 $parser = _parser(<<'END_TAP');
53 ok 1 - input file opened
54 not ok 2 - first line of the input valid # todo some data
55 ok 3 - read the rest of the file
60 ok !$parser->parse_errors, '... but test plan-like data can be in a comment';
62 $parser = _parser(<<'END_TAP');
63 ok 1 - input file opened
64 not ok 2 - first line of the input valid # todo some data
65 ok 3 - read the rest of the file 1..5
69 ok !$parser->parse_errors, '... or a description';
71 $parser = _parser(<<'END_TAP');
72 ok 1 - input file opened
73 not ok 2 - first line of the input valid # todo 1..4
74 ok 3 - read the rest of the file
78 ok !$parser->parse_errors, '... or a directive';
80 # test numbers included?
82 $parser = _parser(<<'END_TAP');
84 ok 1 - input file opened
85 not ok 2 - first line of the input valid # todo some data
86 ok read the rest of the file
89 eval { $parser->run };
90 ok !$@, 'We can mix and match the presence of test numbers';
92 $parser = _parser(<<'END_TAP');
94 ok 1 - input file opened
95 not ok 2 - first line of the input valid # todo some data
96 ok 2 read the rest of the file
99 is + ( $parser->parse_errors )[0],
100 'Tests out of sequence. Found (2) but expected (3)',
101 '... and if the numbers are there, they cannot be out of sequence';
103 $parser = _parser(<<'END_TAP');
104 ok 1 - input file opened
105 not ok 2 - first line of the input valid # todo some data
106 ok 2 read the rest of the file
109 is $parser->parse_errors, 2,
110 'Having two errors in the TAP should result in two errors (duh)';
112 'Tests out of sequence. Found (2) but expected (3)',
113 'No plan found in TAP output'
115 is_deeply [ $parser->parse_errors ], $expected,
116 '... and they should be the correct errors';
118 $parser = _parser(<<'END_TAP');
119 ok 1 - input file opened
120 not ok 2 - first line of the input valid # todo some data
121 ok 3 read the rest of the file
124 is $parser->parse_errors, 1, 'Having no plan should cause an error';
125 is + ( $parser->parse_errors )[0], 'No plan found in TAP output',
126 '... with a correct error message';
128 $parser = _parser(<<'END_TAP');
130 ok 1 - input file opened
131 not ok 2 - first line of the input valid # todo some data
132 ok 3 read the rest of the file
136 is $parser->parse_errors, 1,
137 'Having more than one plan should cause an error';
138 is + ( $parser->parse_errors )[0], 'More than one plan found in TAP output',
139 '... with a correct error message';
141 can_ok $parser, 'is_good_plan';
142 $parser = _parser(<<'END_TAP');
144 ok 1 - input file opened
145 not ok 2 - first line of the input valid # todo some data
146 ok 3 read the rest of the file
149 is $parser->parse_errors, 1,
150 'Having the wrong number of planned tests is a parse error';
151 is + ( $parser->parse_errors )[0],
152 'Bad plan. You planned 2 tests but ran 3.',
153 '... with a correct error message';
155 # XXX internals: plan will not set to true if defined
156 $parser->is_good_plan(undef);
157 $parser = _parser(<<'END_TAP');
158 ok 1 - input file opened
162 ok $parser->is_good_plan,
163 '... and it should return true if the plan is correct';
165 # TAP::Parser coverage tests
173 local $SIG{__WARN__} = sub { push @warn, @_ };
178 is @warn, 1, 'coverage testing of good_plan';
181 qr/good_plan[(][)] is deprecated. Please use "is_good_plan[(][)]"/,
182 '...and it fell-back like we expected';