| 1 |
use 5.006; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 |
| 6 |
|
| 7 |
use if $ENV{AUTOMATED_TESTING}, 'Test::DiagINC'; use Test::More 0.94; |
| 8 |
|
| 9 |
plan tests => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0); |
| 10 |
|
| 11 |
my @module_files = ( |
| 12 |
'TAP/Formatter/JUnit.pm', |
| 13 |
'TAP/Formatter/JUnit/Result.pm', |
| 14 |
'TAP/Formatter/JUnit/Session.pm' |
| 15 |
); |
| 16 |
|
| 17 |
my @scripts = ( |
| 18 |
'script/tap2junit' |
| 19 |
); |
| 20 |
|
| 21 |
# fake home for cpan-testers |
| 22 |
use File::Temp; |
| 23 |
local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); |
| 24 |
|
| 25 |
|
| 26 |
my @switches = ( |
| 27 |
-d 'blib' ? '-Mblib' : '-Ilib', |
| 28 |
); |
| 29 |
|
| 30 |
use File::Spec; |
| 31 |
use IPC::Open3; |
| 32 |
use IO::Handle; |
| 33 |
|
| 34 |
open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; |
| 35 |
|
| 36 |
my @warnings; |
| 37 |
for my $lib (@module_files) |
| 38 |
{ |
| 39 |
# see L<perlfaq8/How can I capture STDERR from an external command?> |
| 40 |
my $stderr = IO::Handle->new; |
| 41 |
|
| 42 |
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } |
| 43 |
$^X, @switches, '-e', "require q[$lib]")) |
| 44 |
if $ENV{PERL_COMPILE_TEST_DEBUG}; |
| 45 |
|
| 46 |
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); |
| 47 |
binmode $stderr, ':crlf' if $^O eq 'MSWin32'; |
| 48 |
my @_warnings = <$stderr>; |
| 49 |
waitpid($pid, 0); |
| 50 |
is($?, 0, "$lib loaded ok"); |
| 51 |
|
| 52 |
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ |
| 53 |
and not eval { +require blib; blib->VERSION('1.01') }; |
| 54 |
|
| 55 |
if (@_warnings) |
| 56 |
{ |
| 57 |
warn @_warnings; |
| 58 |
push @warnings, @_warnings; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
foreach my $file (@scripts) |
| 63 |
{ SKIP: { |
| 64 |
open my $fh, '<', $file or warn("Unable to open $file: $!"), next; |
| 65 |
my $line = <$fh>; |
| 66 |
|
| 67 |
close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/; |
| 68 |
@switches = (@switches, split(' ', $1)) if $1; |
| 69 |
|
| 70 |
close $fh and skip("$file uses -T; not testable with PERL5LIB", 1) |
| 71 |
if grep { $_ eq '-T' } @switches and $ENV{PERL5LIB}; |
| 72 |
|
| 73 |
my $stderr = IO::Handle->new; |
| 74 |
|
| 75 |
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } |
| 76 |
$^X, @switches, '-c', $file)) |
| 77 |
if $ENV{PERL_COMPILE_TEST_DEBUG}; |
| 78 |
|
| 79 |
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file); |
| 80 |
binmode $stderr, ':crlf' if $^O eq 'MSWin32'; |
| 81 |
my @_warnings = <$stderr>; |
| 82 |
waitpid($pid, 0); |
| 83 |
is($?, 0, "$file compiled ok"); |
| 84 |
|
| 85 |
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ |
| 86 |
and not eval { +require blib; blib->VERSION('1.01') }; |
| 87 |
|
| 88 |
# in older perls, -c output is simply the file portion of the path being tested |
| 89 |
if (@_warnings = grep { !/\bsyntax OK$/ } |
| 90 |
grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings) |
| 91 |
{ |
| 92 |
warn @_warnings; |
| 93 |
push @warnings, @_warnings; |
| 94 |
} |
| 95 |
} } |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
is(scalar(@warnings), 0, 'no warnings found') |
| 100 |
or diag 'got warnings: ', explain(\@warnings) if $ENV{AUTHOR_TESTING}; |
| 101 |
|
| 102 |
BAIL_OUT("Compilation problems") if !Test::More->builder->is_passing; |