6 use Test::More tests => 79;
9 use TAP::Parser::IteratorFactory;
10 use TAP::Parser::Aggregator;
12 my $tap = <<'END_TAP';
14 ok 1 - input file opened
16 not ok first line of the input valid # todo some data
18 ok 3 - read the rest of the file
19 not ok 4 - this is a real failure
20 ok 5 # skip we have no description
23 my $factory = TAP::Parser::IteratorFactory->new;
24 my $stream = $factory->make_iterator( [ split /\n/ => $tap ] );
25 isa_ok $stream, 'TAP::Parser::Iterator';
27 my $parser1 = TAP::Parser->new( { stream => $stream } );
28 isa_ok $parser1, 'TAP::Parser';
34 ok 1 - gentlemen, start your engines
35 not ok first line of the input valid # todo some data
37 ok 3 - read the rest of the file
38 not ok 4 - this is a real failure
40 ok 6 - you shall not pass! # TODO should have failed
41 not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
44 my $parser2 = TAP::Parser->new( { tap => $tap } );
45 isa_ok $parser2, 'TAP::Parser';
48 can_ok 'TAP::Parser::Aggregator', 'new';
49 my $agg = TAP::Parser::Aggregator->new;
50 isa_ok $agg, 'TAP::Parser::Aggregator';
53 ok $agg->add( 'tap1', $parser1 ), '... and calling it should succeed';
54 ok $agg->add( 'tap2', $parser2 ), '... even if we add more than one parser';
55 eval { $agg->add( 'tap1', $parser1 ) };
56 like $@, qr/^You already have a parser for \Q(tap1)/,
57 '... but trying to reuse a description should be fatal';
59 can_ok $agg, 'parsers';
60 is scalar $agg->parsers, 2,
61 '... and it should report how many parsers it has';
62 is_deeply [ $agg->parsers ], [ $parser1, $parser2 ],
63 '... or which parsers it has';
64 is_deeply $agg->parsers('tap2'), $parser2, '... or reporting a single parser';
65 is_deeply [ $agg->parsers(qw(tap2 tap1)) ], [ $parser2, $parser1 ],
68 # test aggregate results
70 can_ok $agg, 'passed';
72 '... and we should have the correct number of passed tests';
73 is_deeply [ $agg->passed ], [qw(tap1 tap2)],
74 '... and be able to get their descriptions';
76 can_ok $agg, 'failed';
78 '... and we should have the correct number of failed tests';
79 is_deeply [ $agg->failed ], [qw(tap1 tap2)],
80 '... and be able to get their descriptions';
83 is $agg->todo, 4, '... and we should have the correct number of todo tests';
84 is_deeply [ $agg->todo ], [qw(tap1 tap2)],
85 '... and be able to get their descriptions';
87 can_ok $agg, 'skipped';
89 '... and we should have the correct number of skipped tests';
90 is_deeply [ $agg->skipped ], [qw(tap1)],
91 '... and be able to get their descriptions';
93 can_ok $agg, 'parse_errors';
94 is $agg->parse_errors, 0, '... and the correct number of parse errors';
95 is_deeply [ $agg->parse_errors ], [],
96 '... and be able to get their descriptions';
98 can_ok $agg, 'todo_passed';
99 is $agg->todo_passed, 1,
100 '... and the correct number of unexpectedly succeeded tests';
101 is_deeply [ $agg->todo_passed ], [qw(tap2)],
102 '... and be able to get their descriptions';
104 can_ok $agg, 'total';
105 is $agg->total, $agg->passed + $agg->failed,
106 '... and we should have the correct number of total tests';
108 can_ok $agg, 'has_problems';
109 ok $agg->has_problems, '... and it should report true if there are problems';
111 can_ok $agg, 'has_errors';
112 ok $agg->has_errors, '... and it should report true if there are errors';
114 can_ok $agg, 'get_status';
115 is $agg->get_status, 'FAIL', '... and it should tell us the tests failed';
117 can_ok $agg, 'all_passed';
118 ok !$agg->all_passed, '... and it should tell us not all tests passed';
124 # currently the $agg object has descriptions tap1 and tap2
125 # call _get_parsers with another description.
126 # $agg will call its _croak method
130 local $SIG{__DIE__} = sub { push @die, @_ };
132 $agg->_get_parsers('no_such_parser_for');
136 'coverage tests for missing parsers... and we caught just one death message';
138 qr/^A parser for \(no_such_parser_for\) could not be found at /,
139 '... and it was the expected death message';
141 # _get_parsers in scalar context
143 my $gp = $agg->_get_parsers(qw(tap1 tap2))
144 ; # should return ref to array containing parsers for tap1 and tap2
147 'coverage tests for _get_parser in scalar context... and we got the right number of parsers';
148 isa_ok( $_, 'TAP::Parser' ) foreach (@$gp);
151 # todo_failed - this is a deprecated method, so it (and these tests)
152 # can be removed eventually. However, it is showing up in the coverage
157 local $SIG{__WARN__} = sub { push @warn, @_ };
162 # check the warning, making sure to capture the fullstops correctly (not
163 # as "any char" matches)
165 'coverage tests for deprecated todo_failed... and just one warning caught';
167 qr/^"todo_failed" is deprecated[.] Please use "todo_passed"[.] See the docs[.] at/,
168 '... and it was the expected warning';
171 # this has a large number of conditions 'OR'd together, so the tests get
172 # a little complicated here
174 # currently, we have covered the cases of failed() being true and none
175 # of the summary methods failing
177 # we need to set up test cases for
178 # 1. !failed && todo_passed
179 # 2. !failed && !todo_passed && parse_errors
180 # 3. !failed && !todo_passed && !parse_errors && exit
181 # 4. !failed && !todo_passed && !parse_errors && !exit && wait
183 # note there is nothing wrong per se with the has_problems logic, these
184 # are simply coverage tests
186 # 1. !failed && todo_passed
188 $agg = TAP::Parser::Aggregator->new();
189 isa_ok $agg, 'TAP::Parser::Aggregator';
193 ok 1 - you shall not pass! # TODO should have failed
196 my $parser3 = TAP::Parser->new( { tap => $tap } );
197 isa_ok $parser3, 'TAP::Parser';
200 $agg->add( 'tap3', $parser3 );
203 'coverage tests for !failed && todo_passed... and we should have the correct number of passed tests';
205 '... and we should have the correct number of failed tests';
206 is $agg->todo_passed, 1,
207 '... and the correct number of unexpectedly succeeded tests';
208 ok $agg->has_problems,
209 '... and it should report true that there are problems';
210 is $agg->get_status, 'PASS', '... and the status should be passing';
211 ok !$agg->has_errors, '.... but it should not report any errors';
212 ok $agg->all_passed, '... bonus tests should be passing tests, too';
214 # 2. !failed && !todo_passed && parse_errors
216 $agg = TAP::Parser::Aggregator->new();
222 my $parser4 = TAP::Parser->new( { tap => $tap } );
223 isa_ok $parser4, 'TAP::Parser';
226 $agg->add( 'tap4', $parser4 );
229 'coverage tests for !failed && !todo_passed && parse_errors... and we should have the correct number of passed tests';
231 '... and we should have the correct number of failed tests';
232 is $agg->todo_passed, 0,
233 '... and the correct number of unexpectedly succeeded tests';
234 is $agg->parse_errors, 1, '... and the correct number of parse errors';
235 ok $agg->has_problems,
236 '... and it should report true that there are problems';
238 # 3. !failed && !todo_passed && !parse_errors && exit
239 # now this is a little harder to emulate cleanly through creating tap
240 # fragments and parsing, as exit and wait collect OS-status codes.
241 # so we'll get a little funky with $agg and push exit and wait descriptions
242 # in it - not very friendly to internal rep changes.
244 $agg = TAP::Parser::Aggregator->new();
248 ok 1 - you shall not pass!
251 my $parser5 = TAP::Parser->new( { tap => $tap } );
254 $agg->add( 'tap', $parser5 );
256 push @{ $agg->{descriptions_for_exit} }, 'one possible reason';
260 'coverage tests for !failed && !todo_passed && !parse_errors... and we should have the correct number of passed tests';
262 '... and we should have the correct number of failed tests';
263 is $agg->todo_passed, 0,
264 '... and the correct number of unexpectedly succeeded tests';
265 is $agg->parse_errors, 0, '... and the correct number of parse errors';
267 my @exits = $agg->exit;
269 is @exits, 1, '... and the correct number of exits';
270 is pop(@exits), 'one possible reason',
271 '... and we collected the right exit reason';
273 ok $agg->has_problems,
274 '... and it should report true that there are problems';
276 # 4. !failed && !todo_passed && !parse_errors && !exit && wait
278 $agg = TAP::Parser::Aggregator->new();
280 $agg->add( 'tap', $parser5 );
282 push @{ $agg->{descriptions_for_wait} }, 'another possible reason';
286 'coverage tests for !failed && !todo_passed && !parse_errors && !exit... and we should have the correct number of passed tests';
288 '... and we should have the correct number of failed tests';
289 is $agg->todo_passed, 0,
290 '... and the correct number of unexpectedly succeeded tests';
291 is $agg->parse_errors, 0, '... and the correct number of parse errors';
292 is $agg->exit, 0, '... and the correct number of exits';
294 my @waits = $agg->wait;
296 is @waits, 1, '... and the correct number of waits';
297 is pop(@waits), 'another possible reason',
298 '... and we collected the right wait reason';
300 ok $agg->has_problems,
301 '... and it should report true that there are problems';