| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use if $ENV{AUTOMATED_TESTING}, 'Test::DiagINC'; use Test::More tests => 4; |
| 6 |
use TAP::Harness; |
| 7 |
use IO::Scalar; |
| 8 |
use File::Slurp qw(write_file); |
| 9 |
|
| 10 |
############################################################################### |
| 11 |
# When timer is disabled, we should have *NO* timer info in the JUnit output. |
| 12 |
timer_disabled: { |
| 13 |
my $test = qq| |
| 14 |
use Test::More tests => 1; |
| 15 |
pass 'no timing in this test'; |
| 16 |
|; |
| 17 |
my $results = run_test($test, { |
| 18 |
timer => 0, |
| 19 |
} ); |
| 20 |
ok $results, 'got JUnit'; |
| 21 |
unlike $results, qr/time/ism, '... without any timing information'; |
| 22 |
} |
| 23 |
|
| 24 |
############################################################################### |
| 25 |
# When timer is enabled, JUnit output *should* have timer info in it. |
| 26 |
timer_enabled: { |
| 27 |
my $test = qq| |
| 28 |
use Test::More tests => 2; |
| 29 |
pass 'one'; |
| 30 |
pass 'two'; |
| 31 |
|; |
| 32 |
my $results = run_test($test, { |
| 33 |
timer => 1, |
| 34 |
} ); |
| 35 |
ok $results, 'got JUnit'; |
| 36 |
like $results, qr/time/ism, '... with timing information'; |
| 37 |
} |
| 38 |
|
| 39 |
sub run_test { |
| 40 |
my $code = shift; |
| 41 |
my $opts = shift; |
| 42 |
my $file = "test-$$.t"; |
| 43 |
|
| 44 |
my $junit = undef; |
| 45 |
my $fh = IO::Scalar->new(\$junit); |
| 46 |
my $harness = TAP::Harness->new( { |
| 47 |
formatter_class => 'TAP::Formatter::JUnit', |
| 48 |
stdout => $fh, |
| 49 |
%{$opts}, |
| 50 |
} ); |
| 51 |
|
| 52 |
write_file($file, $code); |
| 53 |
$harness->runtests($file); |
| 54 |
unlink $file; |
| 55 |
|
| 56 |
return $junit; |
| 57 |
} |