7 use Test::More tests => 294;
13 use TAP::Parser::IteratorFactory;
18 while ( defined( my $result = $parser->next ) ) {
19 push @results => $result;
24 my ( $PARSER, $PLAN, $PRAGMA, $TEST, $COMMENT, $BAILOUT, $UNKNOWN, $YAML, $VERSION ) = qw(
26 TAP::Parser::Result::Plan
27 TAP::Parser::Result::Pragma
28 TAP::Parser::Result::Test
29 TAP::Parser::Result::Comment
30 TAP::Parser::Result::Bailout
31 TAP::Parser::Result::Unknown
32 TAP::Parser::Result::YAML
33 TAP::Parser::Result::Version
36 my $factory = TAP::Parser::IteratorFactory->new;
38 my $tap = <<'END_TAP';
41 ok 1 - input file opened
43 not ok first line of the input valid # todo some data
45 ok 3 - read the rest of the file
46 not ok 4 - this is a real failure
49 ok 5 # skip we have no description
50 ok 6 - you shall not pass! # TODO should have failed
51 not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
54 can_ok $PARSER, 'new';
55 my $parser = $PARSER->new( { tap => $tap } );
56 isa_ok $parser, $PARSER, '... and the object it returns';
58 ok $ENV{TAP_VERSION}, 'TAP_VERSION env variable should be set';
62 my @results = _get_results($parser);
63 is scalar @results, 12, '... and there should be one for each line';
65 my $version = shift @results;
66 isa_ok $version, $VERSION;
67 is $version->version, '13', '... and the version should be 13';
71 my $result = shift @results;
72 isa_ok $result, $PLAN;
73 can_ok $result, 'type';
74 is $result->type, 'plan', '... and it should report the correct type';
75 ok $result->is_plan, '... and it should identify itself as a plan';
76 is $result->plan, '1..7', '... and identify the plan';
77 ok !$result->directive, '... and this plan should not have a directive';
78 ok !$result->explanation, '... or a directive explanation';
79 is $result->as_string, '1..7',
80 '... and have the correct string representation';
81 is $result->raw, '1..7', '... and raw() should return the original line';
83 # a normal, passing test
85 my $test = shift @results;
87 is $test->type, 'test', '... and it should report the correct type';
88 ok $test->is_test, '... and it should identify itself as a test';
89 is $test->ok, 'ok', '... and it should have the correct ok()';
90 ok $test->is_ok, '... and the correct boolean version of is_ok()';
91 ok $test->is_actual_ok,
92 '... and the correct boolean version of is_actual_ok()';
93 is $test->number, 1, '... and have the correct test number';
94 is $test->description, '- input file opened',
95 '... and the correct description';
96 ok !$test->directive, '... and not have a directive';
97 ok !$test->explanation, '... or a directive explanation';
98 ok !$test->has_skip, '... and it is not a SKIPped test';
99 ok !$test->has_todo, '... nor a TODO test';
100 is $test->as_string, 'ok 1 - input file opened',
101 '... and its string representation should be correct';
102 is $test->raw, 'ok 1 - input file opened',
103 '... and raw() should return the original line';
105 # junk lines should be preserved
107 my $unknown = shift @results;
108 isa_ok $unknown, $UNKNOWN;
109 is $unknown->type, 'unknown', '... and it should report the correct type';
110 ok $unknown->is_unknown, '... and it should identify itself as unknown';
111 is $unknown->as_string, '... this is junk',
112 '... and its string representation should be returned verbatim';
113 is $unknown->raw, '... this is junk',
114 '... and raw() should return the original line';
116 # a failing test, which also happens to have a directive
118 my $failed = shift @results;
119 isa_ok $failed, $TEST;
120 is $failed->type, 'test', '... and it should report the correct type';
121 ok $failed->is_test, '... and it should identify itself as a test';
122 is $failed->ok, 'not ok', '... and it should have the correct ok()';
123 ok $failed->is_ok, '... and TODO tests should always pass';
124 ok !$failed->is_actual_ok,
125 '... and the correct boolean version of is_actual_ok ()';
126 is $failed->number, 2, '... and have the correct failed number';
127 is $failed->description, 'first line of the input valid',
128 '... and the correct description';
129 is $failed->directive, 'TODO', '... and should have the correct directive';
130 is $failed->explanation, 'some data',
131 '... and the correct directive explanation';
132 ok !$failed->has_skip, '... and it is not a SKIPped failed';
133 ok $failed->has_todo, '... but it is a TODO succeeded';
134 is $failed->as_string,
135 'not ok 2 first line of the input valid # TODO some data',
136 '... and its string representation should be correct';
137 is $failed->raw, 'not ok first line of the input valid # todo some data',
138 '... and raw() should return the original line';
142 my $comment = shift @results;
143 isa_ok $comment, $COMMENT;
144 is $comment->type, 'comment', '... and it should report the correct type';
145 ok $comment->is_comment, '... and it should identify itself as a comment';
146 is $comment->comment, 'this is a comment',
147 '... and you should be able to fetch the comment';
148 is $comment->as_string, '# this is a comment',
149 '... and have the correct string representation';
150 is $comment->raw, '# this is a comment',
151 '... and raw() should return the original line';
153 # another normal, passing test
155 $test = shift @results;
157 is $test->type, 'test', '... and it should report the correct type';
158 ok $test->is_test, '... and it should identify itself as a test';
159 is $test->ok, 'ok', '... and it should have the correct ok()';
160 ok $test->is_ok, '... and the correct boolean version of is_ok()';
161 ok $test->is_actual_ok,
162 '... and the correct boolean version of is_actual_ok()';
163 is $test->number, 3, '... and have the correct test number';
164 is $test->description, '- read the rest of the file',
165 '... and the correct description';
166 ok !$test->directive, '... and not have a directive';
167 ok !$test->explanation, '... or a directive explanation';
168 ok !$test->has_skip, '... and it is not a SKIPped test';
169 ok !$test->has_todo, '... nor a TODO test';
170 is $test->as_string, 'ok 3 - read the rest of the file',
171 '... and its string representation should be correct';
172 is $test->raw, 'ok 3 - read the rest of the file',
173 '... and raw() should return the original line';
177 $failed = shift @results;
178 isa_ok $failed, $TEST;
179 is $failed->type, 'test', '... and it should report the correct type';
180 ok $failed->is_test, '... and it should identify itself as a test';
181 is $failed->ok, 'not ok', '... and it should have the correct ok()';
182 ok !$failed->is_ok, '... and the tests should not have passed';
183 ok !$failed->is_actual_ok,
184 '... and the correct boolean version of is_actual_ok ()';
185 is $failed->number, 4, '... and have the correct failed number';
186 is $failed->description, '- this is a real failure',
187 '... and the correct description';
188 ok !$failed->directive, '... and should have no directive';
189 ok !$failed->explanation, '... and no directive explanation';
190 ok !$failed->has_skip, '... and it is not a SKIPped failed';
191 ok !$failed->has_todo, '... and not a TODO test';
192 is $failed->as_string, 'not ok 4 - this is a real failure',
193 '... and its string representation should be correct';
194 is $failed->raw, 'not ok 4 - this is a real failure',
195 '... and raw() should return the original line';
198 my $yaml = shift @results;
200 is $yaml->type, 'yaml', '... and it should report the correct type';
201 ok $yaml->is_yaml, '... and it should identify itself as yaml';
202 is_deeply $yaml->data, 'YAML!', '... and data should be correct';
204 # ok 5 # skip we have no description
207 $test = shift @results;
209 is $test->type, 'test', '... and it should report the correct type';
210 ok $test->is_test, '... and it should identify itself as a test';
211 is $test->ok, 'ok', '... and it should have the correct ok()';
212 ok $test->is_ok, '... and the correct boolean version of is_ok()';
213 ok $test->is_actual_ok,
214 '... and the correct boolean version of is_actual_ok()';
215 is $test->number, 5, '... and have the correct test number';
216 ok !$test->description, '... and skipped tests have no description';
217 is $test->directive, 'SKIP', '... and the correct directive';
218 is $test->explanation, 'we have no description',
219 '... but we should have an explanation';
220 ok $test->has_skip, '... and it is a SKIPped test';
221 ok !$test->has_todo, '... but not a TODO test';
222 is $test->as_string, 'ok 5 # SKIP we have no description',
223 '... and its string representation should be correct';
224 is $test->raw, 'ok 5 # skip we have no description',
225 '... and raw() should return the original line';
227 # a failing test, which also happens to have a directive
228 # ok 6 - you shall not pass! # TODO should have failed
230 my $bonus = shift @results;
231 isa_ok $bonus, $TEST;
232 can_ok $bonus, 'todo_passed';
233 is $bonus->type, 'test', 'TODO tests should parse correctly';
234 ok $bonus->is_test, '... and it should identify itself as a test';
235 is $bonus->ok, 'ok', '... and it should have the correct ok()';
236 ok $bonus->is_ok, '... and TODO tests should not always pass';
237 ok $bonus->is_actual_ok,
238 '... and the correct boolean version of is_actual_ok ()';
239 is $bonus->number, 6, '... and have the correct failed number';
240 is $bonus->description, '- you shall not pass!',
241 '... and the correct description';
242 is $bonus->directive, 'TODO', '... and should have the correct directive';
243 is $bonus->explanation, 'should have failed',
244 '... and the correct directive explanation';
245 ok !$bonus->has_skip, '... and it is not a SKIPped failed';
246 ok $bonus->has_todo, '... but it is a TODO succeeded';
247 is $bonus->as_string, 'ok 6 - you shall not pass! # TODO should have failed',
248 '... and its string representation should be correct';
249 is $bonus->raw, 'ok 6 - you shall not pass! # TODO should have failed',
250 '... and raw() should return the original line';
251 ok $bonus->todo_passed,
252 '... todo_bonus() should pass for TODO tests which unexpectedly succeed';
254 # not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
256 my $passed = shift @results;
257 isa_ok $passed, $TEST;
258 can_ok $passed, 'todo_passed';
259 is $passed->type, 'test', 'TODO tests should parse correctly';
260 ok $passed->is_test, '... and it should identify itself as a test';
261 is $passed->ok, 'not ok', '... and it should have the correct ok()';
262 ok $passed->is_ok, '... and TODO tests should always pass';
263 ok !$passed->is_actual_ok,
264 '... and the correct boolean version of is_actual_ok ()';
265 is $passed->number, 7, '... and have the correct passed number';
266 is $passed->description, '- Gandalf wins. Game over.',
267 '... and the correct description';
268 is $passed->directive, 'TODO', '... and should have the correct directive';
269 is $passed->explanation, "'bout time!",
270 '... and the correct directive explanation';
271 ok !$passed->has_skip, '... and it is not a SKIPped passed';
272 ok $passed->has_todo, '... but it is a TODO succeeded';
273 is $passed->as_string,
274 "not ok 7 - Gandalf wins. Game over. # TODO 'bout time!",
275 '... and its string representation should be correct';
276 is $passed->raw, "not ok 7 - Gandalf wins. Game over. # TODO 'bout time!",
277 '... and raw() should return the original line';
278 ok !$passed->todo_passed,
279 '... todo_passed() should not pass for TODO tests which failed';
283 can_ok $parser, 'passed';
284 is $parser->passed, 6,
285 '... and we should have the correct number of passed tests';
286 is_deeply [ $parser->passed ], [ 1, 2, 3, 5, 6, 7 ],
287 '... and get a list of the passed tests';
289 can_ok $parser, 'failed';
290 is $parser->failed, 1, '... and the correct number of failed tests';
291 is_deeply [ $parser->failed ], [4], '... and get a list of the failed tests';
293 can_ok $parser, 'actual_passed';
294 is $parser->actual_passed, 4,
295 '... and we should have the correct number of actually passed tests';
296 is_deeply [ $parser->actual_passed ], [ 1, 3, 5, 6 ],
297 '... and get a list of the actually passed tests';
299 can_ok $parser, 'actual_failed';
300 is $parser->actual_failed, 3,
301 '... and the correct number of actually failed tests';
302 is_deeply [ $parser->actual_failed ], [ 2, 4, 7 ],
303 '... or get a list of the actually failed tests';
305 can_ok $parser, 'todo';
307 '... and we should have the correct number of TODO tests';
308 is_deeply [ $parser->todo ], [ 2, 6, 7 ],
309 '... and get a list of the TODO tests';
311 can_ok $parser, 'skipped';
312 is $parser->skipped, 1,
313 '... and we should have the correct number of skipped tests';
314 is_deeply [ $parser->skipped ], [5],
315 '... and get a list of the skipped tests';
319 can_ok $parser, 'plan';
320 is $parser->plan, '1..7', '... and we should have the correct plan';
321 is $parser->tests_planned, 7, '... and the correct number of tests';
323 # "Unexpectedly succeeded"
324 can_ok $parser, 'todo_passed';
325 is scalar $parser->todo_passed, 1,
326 '... and it should report the number of tests which unexpectedly succeeded';
327 is_deeply [ $parser->todo_passed ], [6],
328 '... or *which* tests unexpectedly succeeded';
331 # Bug report from Torsten Schoenfeld
332 # Makes sure parser can handle blank lines
337 ok 1 - input file opened
340 ok 2 - read the rest of the file
343 my $aref = [ split /\n/ => $tap ];
345 can_ok $PARSER, 'new';
346 $parser = $PARSER->new( { stream => $factory->make_iterator($aref) } );
347 isa_ok $parser, $PARSER, '... and calling it should succeed';
351 ok @results = _get_results($parser), 'The parser should return results';
352 is scalar @results, 5, '... and there should be one for each line';
354 # check the test plan
356 $result = shift @results;
357 isa_ok $result, $PLAN;
358 can_ok $result, 'type';
359 is $result->type, 'plan', '... and it should report the correct type';
360 ok $result->is_plan, '... and it should identify itself as a plan';
361 is $result->plan, '1..2', '... and identify the plan';
362 is $result->as_string, '1..2',
363 '... and have the correct string representation';
364 is $result->raw, '1..2', '... and raw() should return the original line';
366 # a normal, passing test
368 $test = shift @results;
370 is $test->type, 'test', '... and it should report the correct type';
371 ok $test->is_test, '... and it should identify itself as a test';
372 is $test->ok, 'ok', '... and it should have the correct ok()';
373 ok $test->is_ok, '... and the correct boolean version of is_ok()';
374 ok $test->is_actual_ok,
375 '... and the correct boolean version of is_actual_ok()';
376 is $test->number, 1, '... and have the correct test number';
377 is $test->description, '- input file opened',
378 '... and the correct description';
379 ok !$test->directive, '... and not have a directive';
380 ok !$test->explanation, '... or a directive explanation';
381 ok !$test->has_skip, '... and it is not a SKIPped test';
382 ok !$test->has_todo, '... nor a TODO test';
383 is $test->as_string, 'ok 1 - input file opened',
384 '... and its string representation should be correct';
385 is $test->raw, 'ok 1 - input file opened',
386 '... and raw() should return the original line';
388 # junk lines should be preserved
390 $unknown = shift @results;
391 isa_ok $unknown, $UNKNOWN;
392 is $unknown->type, 'unknown', '... and it should report the correct type';
393 ok $unknown->is_unknown, '... and it should identify itself as unknown';
394 is $unknown->as_string, '',
395 '... and its string representation should be returned verbatim';
396 is $unknown->raw, '', '... and raw() should return the original line';
398 # ... and the second empty line
400 $unknown = shift @results;
401 isa_ok $unknown, $UNKNOWN;
402 is $unknown->type, 'unknown', '... and it should report the correct type';
403 ok $unknown->is_unknown, '... and it should identify itself as unknown';
404 is $unknown->as_string, '',
405 '... and its string representation should be returned verbatim';
406 is $unknown->raw, '', '... and raw() should return the original line';
410 $test = shift @results;
412 is $test->type, 'test', '... and it should report the correct type';
413 ok $test->is_test, '... and it should identify itself as a test';
414 is $test->ok, 'ok', '... and it should have the correct ok()';
415 ok $test->is_ok, '... and the correct boolean version of is_ok()';
416 ok $test->is_actual_ok,
417 '... and the correct boolean version of is_actual_ok()';
418 is $test->number, 2, '... and have the correct test number';
419 is $test->description, '- read the rest of the file',
420 '... and the correct description';
421 ok !$test->directive, '... and not have a directive';
422 ok !$test->explanation, '... or a directive explanation';
423 ok !$test->has_skip, '... and it is not a SKIPped test';
424 ok !$test->has_todo, '... nor a TODO test';
425 is $test->as_string, 'ok 2 - read the rest of the file',
426 '... and its string representation should be correct';
427 is $test->raw, 'ok 2 - read the rest of the file',
428 '... and raw() should return the original line';
430 is scalar $parser->passed, 2,
431 'Empty junk lines should not affect the correct number of tests passed';
433 # Check source => "tap content"
434 can_ok $PARSER, 'new';
435 $parser = $PARSER->new( { source => "1..1\nok 1\n" } );
436 isa_ok $parser, $PARSER, '... and calling it should succeed';
437 ok @results = _get_results($parser), 'The parser should return results';
438 is( scalar @results, 2, "Got two lines of TAP" );
440 # Check source => [array]
441 can_ok $PARSER, 'new';
442 $parser = $PARSER->new( { source => [ "1..1", "ok 1" ] } );
443 isa_ok $parser, $PARSER, '... and calling it should succeed';
444 ok @results = _get_results($parser), 'The parser should return results';
445 is( scalar @results, 2, "Got two lines of TAP" );
447 # Check source => $filehandle
448 can_ok $PARSER, 'new';
449 open my $fh, 't/data/catme.1';
450 $parser = $PARSER->new( { source => $fh } );
451 isa_ok $parser, $PARSER, '... and calling it should succeed';
452 ok @results = _get_results($parser), 'The parser should return results';
453 is( scalar @results, 2, "Got two lines of TAP" );
457 # set a spool to write to
458 tie local *SPOOL, 'IO::c55Capture';
460 my $tap = <<'END_TAP';
463 ok 1 - input file opened
465 not ok first line of the input valid # todo some data
467 ok 3 - read the rest of the file
468 not ok 4 - this is a real failure
471 ok 5 # skip we have no description
472 ok 6 - you shall not pass! # TODO should have failed
473 not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
477 my $parser = $PARSER->new(
483 _get_results($parser);
485 my @spooled = tied(*SPOOL)->dump();
487 is @spooled, 24, 'coverage testing for spool attribute of parser';
488 is join( '', @spooled ), $tap, "spooled tap matches";
492 my $parser = $PARSER->new(
498 $parser->callback( 'ALL', sub { } );
500 _get_results($parser);
502 my @spooled = tied(*SPOOL)->dump();
504 is @spooled, 24, 'coverage testing for spool attribute of parser';
505 is join( '', @spooled ), $tap, "spooled tap matches";
511 # _initialize coverage
513 my $x = bless [], 'kjsfhkjsdhf';
518 local $SIG{__DIE__} = sub { push @die, @_ };
523 is @die, 1, 'coverage testing for _initialize';
525 like pop @die, qr/PANIC:\s+could not determine stream at/,
526 '...and it failed as expected';
531 local $SIG{__DIE__} = sub { push @die, @_ };
534 { stream => 'stream',
536 source => 'source', # only one of these is allowed
541 is @die, 1, 'coverage testing for _initialize';
544 qr/You may only choose one of 'exec', 'stream', 'tap' or 'source'/,
545 '...and it failed as expected';
550 # coverage of todo_failed
552 my $tap = <<'END_TAP';
555 ok 1 - input file opened
557 not ok first line of the input valid # todo some data
559 ok 3 - read the rest of the file
560 not ok 4 - this is a real failure
563 ok 5 # skip we have no description
564 ok 6 - you shall not pass! # TODO should have failed
565 not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
568 my $parser = $PARSER->new( { tap => $tap } );
570 _get_results($parser);
575 local $SIG{__WARN__} = sub { push @warn, @_ };
577 $parser->todo_failed;
580 is @warn, 1, 'coverage testing of todo_failed';
583 qr/"todo_failed" is deprecated. Please use "todo_passed". See the docs[.]/,
584 '..and failed as expected'
589 # coverage testing for T::P::_initialize
591 # coverage of the source argument paths
593 # ref argument to source
595 my $parser = TAP::Parser->new( { source => [ split /$/, $tap ] } );
597 isa_ok $parser, 'TAP::Parser';
599 isa_ok $parser->_stream, 'TAP::Parser::Iterator::Array';
601 # uncategorisable argument to source
605 local $SIG{__DIE__} = sub { push @die, @_ };
607 $parser = TAP::Parser->new( { source => 'nosuchfile' } );
610 is @die, 1, 'uncategorisable source';
612 like pop @die, qr/Cannot determine source for nosuchfile/,
613 '... and we died as expected';
618 # coverage test of perl source with switches
620 my $parser = TAP::Parser->new(
621 { source => File::Spec->catfile(
629 isa_ok $parser, 'TAP::Parser';
631 isa_ok $parser->_stream, 'TAP::Parser::Iterator::Process';
633 # Workaround for Mac OS X problem wrt closing the iterator without
640 # coverage testing for TAP::Parser::has_problems
642 # we're going to need to test lots of fragments of tap
643 # to cover all the different boolean tests
645 # currently covered are no problems and failed, so let's next test
648 my $tap = <<'END_TAP';
651 ok 1 - input file opened
652 ok 2 - Gandalf wins. Game over. # TODO 'bout time!
655 my $parser = TAP::Parser->new( { tap => $tap } );
657 _get_results($parser);
659 ok !$parser->failed, 'parser didnt fail';
660 ok $parser->todo_passed, '... and todo_passed is true';
662 ok !$parser->has_problems, '... and has_problems is false';
672 $parser = TAP::Parser->new( { tap => $tap } );
674 _get_results($parser);
676 ok !$parser->failed, 'parser didnt fail';
677 ok !$parser->todo_passed, '... and todo_passed is false';
678 ok $parser->parse_errors, '... and parse_errors is true';
680 ok $parser->has_problems, '... and has_problems';
682 # Now wait and exit are hard to do in an OS platform-independent way, so
683 # we won't even bother
688 ok 1 - input file opened
692 $parser = TAP::Parser->new( { tap => $tap } );
694 _get_results($parser);
698 ok !$parser->failed, 'parser didnt fail';
699 ok !$parser->todo_passed, '... and todo_passed is false';
700 ok !$parser->parse_errors, '... and parse_errors is false';
702 ok $parser->wait, '... and wait is set';
704 ok $parser->has_problems, '... and has_problems';
706 # and use the same for exit
711 ok !$parser->failed, 'parser didnt fail';
712 ok !$parser->todo_passed, '... and todo_passed is false';
713 ok !$parser->parse_errors, '... and parse_errors is false';
714 ok !$parser->wait, '... and wait is not set';
716 ok $parser->exit, '... and exit is set';
718 ok $parser->has_problems, '... and has_problems';
723 # coverage testing of the version states
725 my $tap = <<'END_TAP';
728 ok 1 - input file opened
732 my $parser = TAP::Parser->new( { tap => $tap } );
734 _get_results($parser);
736 my @errors = $parser->parse_errors;
738 is @errors, 1, 'test too low version number';
741 qr/Explicit TAP version must be at least 13. Got version 12/,
742 '... and trapped expected version error';
744 # now too high a version
748 ok 1 - input file opened
752 $parser = TAP::Parser->new( { tap => $tap } );
754 _get_results($parser);
756 @errors = $parser->parse_errors;
758 is @errors, 1, 'test too high version number';
761 qr/TAP specified version 14 but we don't know about versions later than 13/,
762 '... and trapped expected version error';
767 # coverage testing of TAP version in the wrong place
769 my $tap = <<'END_TAP';
771 ok 1 - input file opened
776 my $parser = TAP::Parser->new( { tap => $tap } );
778 _get_results($parser);
780 my @errors = $parser->parse_errors;
782 is @errors, 1, 'test TAP version number in wrong place';
785 qr/If TAP version is present it must be the first line of output/,
786 '... and trapped expected version error';
792 # we're going to bash the internals a bit (but using the API as
793 # much as possible) to force grammar->tokenise() to fail
795 # firstly we'll create a stream that dies when its next_raw method is called
797 package TAP::Parser::Iterator::Dies;
802 @ISA = qw(TAP::Parser::Iterator);
805 die 'this is the dying iterator';
808 # required as part of the TPI interface
814 # now build a standard parser
816 my $tap = <<'END_TAP';
818 ok 1 - input file opened
823 my $parser = TAP::Parser->new( { tap => $tap } );
825 # build a dying stream
826 my $stream = TAP::Parser::Iterator::Dies->new;
828 # now replace the stream - we're forced to us an T::P intenal
830 $parser->_stream($stream);
832 # build a new grammar
833 my $grammar = TAP::Parser::Grammar->new(
839 # replace our grammar with this new one
840 $parser->_grammar($grammar);
842 # now call next on the parser, and the grammar should die
843 my $result = $parser->next; # will die in iterator
845 is $result, undef, 'iterator dies';
847 my @errors = $parser->parse_errors;
848 is @errors, 2, '...and caught expected errrors';
850 like shift @errors, qr/this is the dying iterator/,
851 '...and it was what we expected';
854 # Do it all again with callbacks to exercise the other code path in
855 # the unrolled iterator
857 my $parser = TAP::Parser->new( { tap => $tap } );
859 $parser->callback( 'ALL', sub { } );
861 # build a dying stream
862 my $stream = TAP::Parser::Iterator::Dies->new;
864 # now replace the stream - we're forced to us an T::P intenal
866 $parser->_stream($stream);
868 # build a new grammar
869 my $grammar = TAP::Parser::Grammar->new(
875 # replace our grammar with this new one
876 $parser->_grammar($grammar);
878 # now call next on the parser, and the grammar should die
879 my $result = $parser->next; # will die in iterator
881 is $result, undef, 'iterator dies';
883 my @errors = $parser->parse_errors;
884 is @errors, 2, '...and caught expected errrors';
886 like shift @errors, qr/this is the dying iterator/,
887 '...and it was what we expected';
893 # coverage testing of TAP::Parser::_next_state
895 package TAP::Parser::WithBrokenState;
898 @ISA = qw( TAP::Parser );
900 sub _make_state_table {
901 return { INIT => { plan => { goto => 'FOO' } } };
906 my $tap = <<'END_TAP';
908 ok 1 - input file opened
912 my $parser = TAP::Parser::WithBrokenState->new( { tap => $tap } );
917 local $SIG{__DIE__} = sub { push @die, @_ };
923 is @die, 1, 'detect broken state machine';
925 like pop @die, qr/Illegal state: FOO/,
926 '...and the message is as we expect';
931 # coverage testing of TAP::Parser::_iter
933 package TAP::Parser::WithBrokenIter;
936 @ISA = qw( TAP::Parser );
942 my $tap = <<'END_TAP';
944 ok 1 - input file opened
948 my $parser = TAP::Parser::WithBrokenIter->new( { tap => $tap } );
953 local $SIG{__WARN__} = sub { };
954 local $SIG{__DIE__} = sub { push @die, @_ };
959 is @die, 1, 'detect broken iter';
961 like pop @die, qr/Can't use/, '...and the message is as we expect';
966 # http://markmail.org/message/rkxbo6ft7yorgnzb
967 skip "Crashes on older Perls", 2 if $] <= 5.008004 || $] == 5.009;
969 # coverage testing of TAP::Parser::_finish
971 my $tap = <<'END_TAP';
973 ok 1 - input file opened
977 my $parser = TAP::Parser->new( { tap => $tap } );
979 $parser->tests_run(999);
984 local $SIG{__DIE__} = sub { push @die, @_ };
986 _get_results $parser;
989 is @die, 1, 'detect broken test counts';
992 qr/Panic: planned test count [(]1001[)] did not equal sum of passed [(]0[)] and failed [(]2[)] tests!/,
993 '...and the message is as we expect';
998 # Sanity check on state table
1000 my $parser = TAP::Parser->new( { tap => "1..1\nok 1\n" } );
1001 my $state_table = $parser->_make_state_table;
1002 my @states = sort keys %$state_table;
1003 my @expect = sort qw(
1004 bailout comment plan pragma test unknown version yaml
1007 my %reachable = ( INIT => 1 );
1009 for my $name (@states) {
1010 my $state = $state_table->{$name};
1011 my @can_handle = sort keys %$state;
1012 is_deeply \@can_handle, \@expect, "token types handled in $name";
1013 for my $type (@can_handle) {
1016 map { $state->{$type}->{$_} } qw(goto continue);
1020 is_deeply [ sort keys %reachable ], [@states], "all states reachable";
1025 # exit, wait, ignore_exit interactions
1038 for my $t (@truth) {
1039 my ( $wait, $exit, $ignore_exit, $has_problems ) = @$t;
1040 my $test_parser = sub {
1042 $parser->wait($wait);
1043 $parser->exit($exit);
1044 ok $has_problems ? $parser->has_problems : !$parser->has_problems,
1045 "exit=$exit, wait=$wait, ignore=$ignore_exit";
1048 my $parser = TAP::Parser->new( { tap => "1..1\nok 1\n" } );
1049 $parser->ignore_exit($ignore_exit);
1050 $test_parser->($parser);
1054 { tap => "1..1\nok 1\n", ignore_exit => $ignore_exit }