4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', '../ext/Test-Harness/t/lib' );
19 my $HARNESS = 'TAP::Harness';
22 = $ENV{PERL_CORE} ? '../ext/Test-Harness/t/source_tests' : 't/source_tests';
24 = $ENV{PERL_CORE} ? '../ext/Test-Harness/t/sample-tests' : 't/sample-tests';
28 # note that this test will always pass when run through 'prove'
29 ok $ENV{HARNESS_ACTIVE}, 'HARNESS_ACTIVE env variable should be set';
30 ok $ENV{HARNESS_VERSION}, 'HARNESS_VERSION env variable should be set';
35 require TAP::Formatter::Base;
36 local *TAP::Formatter::Base::_output = sub {
38 push @output => grep { $_ ne '' }
43 } map { split /\n/ } @_;
46 # Make sure verbosity 1 overrides failures and comments.
47 my $harness = TAP::Harness->new(
53 my $harness_whisper = TAP::Harness->new( { verbosity => -1 } );
54 my $harness_mute = TAP::Harness->new( { verbosity => -2 } );
55 my $harness_directives = TAP::Harness->new( { directives => 1 } );
56 my $harness_failures = TAP::Harness->new( { failures => 1 } );
57 my $harness_comments = TAP::Harness->new( { comments => 1 } );
58 my $harness_fandc = TAP::Harness->new(
64 can_ok $harness, 'runtests';
66 # normal tests in verbose mode
68 ok my $aggregate = _runtests( $harness, "$source_tests/harness" ),
69 '... runtests returns the aggregate';
71 isa_ok $aggregate, 'TAP::Parser::Aggregator';
76 "$source_tests/harness ..",
78 'ok 1 - this is a test',
80 'All tests successful.',
82 my $status = pop @output;
83 my $expected_status = qr{^Result: PASS$};
84 my $summary = pop @output;
85 my $expected_summary = qr{^Files=1, Tests=1, \d+ wallclock secs};
87 is_deeply \@output, \@expected, '... the output should be correct';
88 like $status, $expected_status,
89 '... and the status line should be correct';
90 like $summary, $expected_summary,
91 '... and the report summary should look correct';
93 # use an alias for test name
97 = _runtests( $harness, [ "$source_tests/harness", 'My Nice Test' ] ),
98 'runtests returns the aggregate';
100 isa_ok $aggregate, 'TAP::Parser::Aggregator';
107 'ok 1 - this is a test',
109 'All tests successful.',
111 $status = pop @output;
112 $expected_status = qr{^Result: PASS$};
113 $summary = pop @output;
114 $expected_summary = qr{^Files=1, Tests=1, \d+ wallclock secs};
116 is_deeply \@output, \@expected, '... the output should be correct';
117 like $status, $expected_status,
118 '... and the status line should be correct';
119 like $summary, $expected_summary,
120 '... and the report summary should look correct';
122 # run same test twice
125 ok $aggregate = _runtests(
126 $harness, [ "$source_tests/harness", 'My Nice Test' ],
127 [ "$source_tests/harness", 'My Nice Test Again' ]
129 'runtests labels returns the aggregate';
131 isa_ok $aggregate, 'TAP::Parser::Aggregator';
136 'My Nice Test ........',
138 'ok 1 - this is a test',
140 'My Nice Test Again ..',
142 'ok 1 - this is a test',
144 'All tests successful.',
146 $status = pop @output;
147 $expected_status = qr{^Result: PASS$};
148 $summary = pop @output;
149 $expected_summary = qr{^Files=2, Tests=2, \d+ wallclock secs};
151 is_deeply \@output, \@expected, '... the output should be correct';
152 like $status, $expected_status,
153 '... and the status line should be correct';
154 like $summary, $expected_summary,
155 '... and the report summary should look correct';
157 # normal tests in quiet mode
160 ok _runtests( $harness_whisper, "$source_tests/harness" ),
161 'Run tests with whisper';
165 "$source_tests/harness .. ok",
166 'All tests successful.',
169 $status = pop @output;
170 $expected_status = qr{^Result: PASS$};
171 $summary = pop @output;
172 $expected_summary = qr/^Files=1, Tests=1, \d+ wallclock secs/;
174 is_deeply \@output, \@expected, '... the output should be correct';
175 like $status, $expected_status,
176 '... and the status line should be correct';
177 like $summary, $expected_summary,
178 '... and the report summary should look correct';
180 # normal tests in really_quiet mode
183 ok _runtests( $harness_mute, "$source_tests/harness" ), 'Run tests mute';
187 'All tests successful.',
190 $status = pop @output;
191 $expected_status = qr{^Result: PASS$};
192 $summary = pop @output;
193 $expected_summary = qr/^Files=1, Tests=1, \d+ wallclock secs/;
195 is_deeply \@output, \@expected, '... the output should be correct';
196 like $status, $expected_status,
197 '... and the status line should be correct';
198 like $summary, $expected_summary,
199 '... and the report summary should look correct';
201 # normal tests with failures
204 ok _runtests( $harness, "$source_tests/harness_failure" ),
205 'Run tests with failures';
207 $status = pop @output;
208 $summary = pop @output;
210 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
212 my @summary = @output[ 9 .. $#output ];
213 @output = @output[ 0 .. 8 ];
216 "$source_tests/harness_failure ..",
218 'ok 1 - this is a test',
219 'not ok 2 - this is another test',
220 q{# Failed test 'this is another test'},
221 '# in harness_failure.t at line 5.',
223 q{# expected: 'yarblokos'},
224 'Failed 1/2 subtests',
227 is_deeply \@output, \@expected,
228 '... and failing test output should be correct';
230 my @expected_summary = (
231 'Test Summary Report',
232 '-------------------',
233 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
238 is_deeply \@summary, \@expected_summary,
239 '... and the failure summary should also be correct';
241 # quiet tests with failures
244 ok _runtests( $harness_whisper, "$source_tests/harness_failure" ),
245 'Run whisper tests with failures';
247 $status = pop @output;
248 $summary = pop @output;
250 "$source_tests/harness_failure ..",
251 'Failed 1/2 subtests',
252 'Test Summary Report',
253 '-------------------',
254 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
259 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
261 is_deeply \@output, \@expected,
262 '... and failing test output should be correct';
264 # really quiet tests with failures
267 ok _runtests( $harness_mute, "$source_tests/harness_failure" ),
268 'Run mute tests with failures';
270 $status = pop @output;
271 $summary = pop @output;
273 'Test Summary Report',
274 '-------------------',
275 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
280 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
282 is_deeply \@output, \@expected,
283 '... and failing test output should be correct';
285 # only show directives
290 "$source_tests/harness_directives"
292 'Run tests with directives';
297 "$source_tests/harness_directives ..",
298 'not ok 2 - we have a something # TODO some output',
299 "ok 3 houston, we don't have liftoff # SKIP no funding",
301 'All tests successful.',
303 # ~TODO {{{ this should be an option
304 #'Test Summary Report',
305 #'-------------------',
306 #"$source_tests/harness_directives (Wstat: 0 Tests: 3 Failed: 0)",
312 $status = pop @output;
313 $summary = pop @output;
314 $expected_summary = qr/^Files=1, Tests=3, \d+ wallclock secs/;
316 is_deeply \@output, \@expected, '... the output should be correct';
317 like $summary, $expected_summary,
318 '... and the report summary should look correct';
320 like $status, qr{^Result: PASS$},
321 '... and the status line should be correct';
323 # normal tests with bad tap
326 ok _runtests( $harness, "$source_tests/harness_badtap" ),
327 'Run tests with bad TAP';
330 @output = map { trim($_) } @output;
331 $status = pop @output;
332 @summary = @output[ 6 .. ( $#output - 1 ) ];
333 @output = @output[ 0 .. 5 ];
335 "$source_tests/harness_badtap ..",
337 'ok 1 - this is a test',
338 'not ok 2 - this is another test',
340 'Failed 1/2 subtests',
342 is_deeply \@output, \@expected,
343 '... failing test output should be correct';
344 like $status, qr{^Result: FAIL$},
345 '... and the status line should be correct';
346 @expected_summary = (
347 'Test Summary Report',
348 '-------------------',
349 "$source_tests/harness_badtap (Wstat: 0 Tests: 2 Failed: 1)",
352 'Parse errors: More than one plan found in TAP output',
354 is_deeply \@summary, \@expected_summary,
355 '... and the badtap summary should also be correct';
357 # coverage testing for _should_show_failures
361 ok _runtests( $harness_failures, "$source_tests/harness_failure" ),
362 'Run tests with failures only';
367 "$source_tests/harness_failure ..",
368 'not ok 2 - this is another test',
369 'Failed 1/2 subtests',
370 'Test Summary Report',
371 '-------------------',
372 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
377 $status = pop @output;
378 $summary = pop @output;
380 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
381 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
382 is_deeply \@output, \@expected, '... and the output should be correct';
384 # check the status output for no tests
387 ok _runtests( $harness_failures, "$sample_tests/no_output" ),
388 'Run tests with failures';
393 "$sample_tests/no_output ..",
395 'Test Summary Report',
396 '-------------------',
397 "$sample_tests/no_output (Wstat: 0 Tests: 0 Failed: 0)",
398 'Parse errors: No plan found in TAP output',
401 $status = pop @output;
402 $summary = pop @output;
404 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
405 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
406 is_deeply \@output, \@expected, '... and the output should be correct';
408 # coverage testing for _should_show_comments
412 ok _runtests( $harness_comments, "$source_tests/harness_failure" ),
413 'Run tests with comments';
417 "$source_tests/harness_failure ..",
418 q{# Failed test 'this is another test'},
419 '# in harness_failure.t at line 5.',
421 q{# expected: 'yarblokos'},
422 'Failed 1/2 subtests',
423 'Test Summary Report',
424 '-------------------',
425 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
430 $status = pop @output;
431 $summary = pop @output;
433 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
434 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
435 is_deeply \@output, \@expected, '... and the output should be correct';
437 # coverage testing for _should_show_comments and _should_show_failures
438 # only show comments and failures
442 ok _runtests( $harness_fandc, "$source_tests/harness_failure" ),
443 'Run tests with failures and comments';
448 "$source_tests/harness_failure ..",
449 'not ok 2 - this is another test',
450 q{# Failed test 'this is another test'},
451 '# in harness_failure.t at line 5.',
453 q{# expected: 'yarblokos'},
454 'Failed 1/2 subtests',
455 'Test Summary Report',
456 '-------------------',
457 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
462 $status = pop @output;
463 $summary = pop @output;
465 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
466 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
467 is_deeply \@output, \@expected, '... and the output should be correct';
473 $_[0] =~ s/^\s+|\s+$//g;
478 my ( $harness, @tests ) = @_;
479 local $ENV{PERL_TEST_HARNESS_DUMP_TAP} = 0;
480 my $aggregate = $harness->runtests(@tests);