13 my $HARNESS = 'TAP::Harness';
15 my $source_tests = 't/source_tests';
16 my $sample_tests = 't/sample-tests';
20 # note that this test will always pass when run through 'prove'
21 ok $ENV{HARNESS_ACTIVE}, 'HARNESS_ACTIVE env variable should be set';
22 ok $ENV{HARNESS_VERSION}, 'HARNESS_VERSION env variable should be set';
27 require TAP::Formatter::Base;
28 local *TAP::Formatter::Base::_output = sub {
30 push @output => grep { $_ ne '' }
35 } map { split /\n/ } @_;
38 # Make sure verbosity 1 overrides failures and comments.
39 my $harness = TAP::Harness->new(
45 my $harness_whisper = TAP::Harness->new( { verbosity => -1 } );
46 my $harness_mute = TAP::Harness->new( { verbosity => -2 } );
47 my $harness_directives = TAP::Harness->new( { directives => 1 } );
48 my $harness_failures = TAP::Harness->new( { failures => 1 } );
49 my $harness_comments = TAP::Harness->new( { comments => 1 } );
50 my $harness_fandc = TAP::Harness->new(
56 can_ok $harness, 'runtests';
58 # normal tests in verbose mode
60 ok my $aggregate = _runtests( $harness, "$source_tests/harness" ),
61 '... runtests returns the aggregate';
63 isa_ok $aggregate, 'TAP::Parser::Aggregator';
68 "$source_tests/harness ..",
70 'ok 1 - this is a test',
72 'All tests successful.',
74 my $status = pop @output;
75 my $expected_status = qr{^Result: PASS$};
76 my $summary = pop @output;
77 my $expected_summary = qr{^Files=1, Tests=1, \d+ wallclock secs};
79 is_deeply \@output, \@expected, '... the output should be correct';
80 like $status, $expected_status,
81 '... and the status line should be correct';
82 like $summary, $expected_summary,
83 '... and the report summary should look correct';
85 # use an alias for test name
89 = _runtests( $harness, [ "$source_tests/harness", 'My Nice Test' ] ),
90 'runtests returns the aggregate';
92 isa_ok $aggregate, 'TAP::Parser::Aggregator';
99 'ok 1 - this is a test',
101 'All tests successful.',
103 $status = pop @output;
104 $expected_status = qr{^Result: PASS$};
105 $summary = pop @output;
106 $expected_summary = qr{^Files=1, Tests=1, \d+ wallclock secs};
108 is_deeply \@output, \@expected, '... the output should be correct';
109 like $status, $expected_status,
110 '... and the status line should be correct';
111 like $summary, $expected_summary,
112 '... and the report summary should look correct';
114 # run same test twice
117 ok $aggregate = _runtests(
118 $harness, [ "$source_tests/harness", 'My Nice Test' ],
119 [ "$source_tests/harness", 'My Nice Test Again' ]
121 'runtests labels returns the aggregate';
123 isa_ok $aggregate, 'TAP::Parser::Aggregator';
128 'My Nice Test ........',
130 'ok 1 - this is a test',
132 'My Nice Test Again ..',
134 'ok 1 - this is a test',
136 'All tests successful.',
138 $status = pop @output;
139 $expected_status = qr{^Result: PASS$};
140 $summary = pop @output;
141 $expected_summary = qr{^Files=2, Tests=2, \d+ wallclock secs};
143 is_deeply \@output, \@expected, '... the output should be correct';
144 like $status, $expected_status,
145 '... and the status line should be correct';
146 like $summary, $expected_summary,
147 '... and the report summary should look correct';
149 # normal tests in quiet mode
152 ok _runtests( $harness_whisper, "$source_tests/harness" ),
153 'Run tests with whisper';
157 "$source_tests/harness .. ok",
158 'All tests successful.',
161 $status = pop @output;
162 $expected_status = qr{^Result: PASS$};
163 $summary = pop @output;
164 $expected_summary = qr/^Files=1, Tests=1, \d+ wallclock secs/;
166 is_deeply \@output, \@expected, '... the output should be correct';
167 like $status, $expected_status,
168 '... and the status line should be correct';
169 like $summary, $expected_summary,
170 '... and the report summary should look correct';
172 # normal tests in really_quiet mode
175 ok _runtests( $harness_mute, "$source_tests/harness" ), 'Run tests mute';
179 'All tests successful.',
182 $status = pop @output;
183 $expected_status = qr{^Result: PASS$};
184 $summary = pop @output;
185 $expected_summary = qr/^Files=1, Tests=1, \d+ wallclock secs/;
187 is_deeply \@output, \@expected, '... the output should be correct';
188 like $status, $expected_status,
189 '... and the status line should be correct';
190 like $summary, $expected_summary,
191 '... and the report summary should look correct';
193 # normal tests with failures
196 ok _runtests( $harness, "$source_tests/harness_failure" ),
197 'Run tests with failures';
199 $status = pop @output;
200 $summary = pop @output;
202 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
204 my @summary = @output[ 9 .. $#output ];
205 @output = @output[ 0 .. 8 ];
208 "$source_tests/harness_failure ..",
210 'ok 1 - this is a test',
211 'not ok 2 - this is another test',
212 q{# Failed test 'this is another test'},
213 '# in harness_failure.t at line 5.',
215 q{# expected: 'yarblokos'},
216 'Failed 1/2 subtests',
219 is_deeply \@output, \@expected,
220 '... and failing test output should be correct';
222 my @expected_summary = (
223 'Test Summary Report',
224 '-------------------',
225 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
230 is_deeply \@summary, \@expected_summary,
231 '... and the failure summary should also be correct';
233 # quiet tests with failures
236 ok _runtests( $harness_whisper, "$source_tests/harness_failure" ),
237 'Run whisper tests with failures';
239 $status = pop @output;
240 $summary = pop @output;
242 "$source_tests/harness_failure ..",
243 'Failed 1/2 subtests',
244 'Test Summary Report',
245 '-------------------',
246 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
251 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
253 is_deeply \@output, \@expected,
254 '... and failing test output should be correct';
256 # really quiet tests with failures
259 ok _runtests( $harness_mute, "$source_tests/harness_failure" ),
260 'Run mute tests with failures';
262 $status = pop @output;
263 $summary = pop @output;
265 'Test Summary Report',
266 '-------------------',
267 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
272 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
274 is_deeply \@output, \@expected,
275 '... and failing test output should be correct';
277 # only show directives
282 "$source_tests/harness_directives"
284 'Run tests with directives';
289 "$source_tests/harness_directives ..",
290 'not ok 2 - we have a something # TODO some output',
291 "ok 3 houston, we don't have liftoff # SKIP no funding",
293 'All tests successful.',
295 # ~TODO {{{ this should be an option
296 #'Test Summary Report',
297 #'-------------------',
298 #"$source_tests/harness_directives (Wstat: 0 Tests: 3 Failed: 0)",
304 $status = pop @output;
305 $summary = pop @output;
306 $expected_summary = qr/^Files=1, Tests=3, \d+ wallclock secs/;
308 is_deeply \@output, \@expected, '... the output should be correct';
309 like $summary, $expected_summary,
310 '... and the report summary should look correct';
312 like $status, qr{^Result: PASS$},
313 '... and the status line should be correct';
315 # normal tests with bad tap
318 ok _runtests( $harness, "$source_tests/harness_badtap" ),
319 'Run tests with bad TAP';
322 @output = map { trim($_) } @output;
323 $status = pop @output;
324 @summary = @output[ 6 .. ( $#output - 1 ) ];
325 @output = @output[ 0 .. 5 ];
327 "$source_tests/harness_badtap ..",
329 'ok 1 - this is a test',
330 'not ok 2 - this is another test',
332 'Failed 1/2 subtests',
334 is_deeply \@output, \@expected,
335 '... failing test output should be correct';
336 like $status, qr{^Result: FAIL$},
337 '... and the status line should be correct';
338 @expected_summary = (
339 'Test Summary Report',
340 '-------------------',
341 "$source_tests/harness_badtap (Wstat: 0 Tests: 2 Failed: 1)",
344 'Parse errors: More than one plan found in TAP output',
346 is_deeply \@summary, \@expected_summary,
347 '... and the badtap summary should also be correct';
349 # coverage testing for _should_show_failures
353 ok _runtests( $harness_failures, "$source_tests/harness_failure" ),
354 'Run tests with failures only';
359 "$source_tests/harness_failure ..",
360 'not ok 2 - this is another test',
361 'Failed 1/2 subtests',
362 'Test Summary Report',
363 '-------------------',
364 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
369 $status = pop @output;
370 $summary = pop @output;
372 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
373 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
374 is_deeply \@output, \@expected, '... and the output should be correct';
376 # check the status output for no tests
379 ok _runtests( $harness_failures, "$sample_tests/no_output" ),
380 'Run tests with failures';
385 "$sample_tests/no_output ..",
387 'Test Summary Report',
388 '-------------------',
389 "$sample_tests/no_output (Wstat: 0 Tests: 0 Failed: 0)",
390 'Parse errors: No plan found in TAP output',
393 $status = pop @output;
394 $summary = pop @output;
396 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
397 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
398 is_deeply \@output, \@expected, '... and the output should be correct';
400 # coverage testing for _should_show_comments
404 ok _runtests( $harness_comments, "$source_tests/harness_failure" ),
405 'Run tests with comments';
409 "$source_tests/harness_failure ..",
410 q{# Failed test 'this is another test'},
411 '# in harness_failure.t at line 5.',
413 q{# expected: 'yarblokos'},
414 'Failed 1/2 subtests',
415 'Test Summary Report',
416 '-------------------',
417 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
422 $status = pop @output;
423 $summary = pop @output;
425 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
426 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
427 is_deeply \@output, \@expected, '... and the output should be correct';
429 # coverage testing for _should_show_comments and _should_show_failures
430 # only show comments and failures
434 ok _runtests( $harness_fandc, "$source_tests/harness_failure" ),
435 'Run tests with failures and comments';
440 "$source_tests/harness_failure ..",
441 'not ok 2 - this is another test',
442 q{# Failed test 'this is another test'},
443 '# in harness_failure.t at line 5.',
445 q{# expected: 'yarblokos'},
446 'Failed 1/2 subtests',
447 'Test Summary Report',
448 '-------------------',
449 "$source_tests/harness_failure (Wstat: 0 Tests: 2 Failed: 1)",
454 $status = pop @output;
455 $summary = pop @output;
457 like $status, qr{^Result: FAIL$}, '... the status line should be correct';
458 $expected_summary = qr/^Files=1, Tests=2, \d+ wallclock secs/;
459 is_deeply \@output, \@expected, '... and the output should be correct';
465 $_[0] =~ s/^\s+|\s+$//g;
470 my ( $harness, @tests ) = @_;
471 local $ENV{PERL_TEST_HARNESS_DUMP_TAP} = 0;
472 my $aggregate = $harness->runtests(@tests);