5 # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058
9 plan tests => 8 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
12 'App/HomeBank2Ledger.pm',
13 'App/HomeBank2Ledger/Formatter.pm',
14 'App/HomeBank2Ledger/Formatter/Beancount.pm',
15 'App/HomeBank2Ledger/Formatter/Ledger.pm',
16 'App/HomeBank2Ledger/Ledger.pm',
17 'App/HomeBank2Ledger/Util.pm',
25 # no fake home requested
28 -d 'blib' ? '-Mblib' : '-Ilib',
35 open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
38 for my $lib (@module_files)
40 # see L<perlfaq8/How can I capture STDERR from an external command?>
41 my $stderr = IO::Handle->new;
43 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
44 $^X, @switches, '-e', "require q[$lib]"))
45 if $ENV{PERL_COMPILE_TEST_DEBUG};
47 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
48 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
49 my @_warnings = <$stderr>;
51 is($?, 0, "$lib loaded ok");
53 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
54 and not eval { +require blib; blib->VERSION('1.01') };
59 push @warnings, @_warnings;
63 foreach my $file (@scripts)
65 open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
68 close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
69 @switches = (@switches, split(' ', $1)) if $1;
71 close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
72 if grep { $_ eq '-T' } @switches and $ENV{PERL5LIB};
74 my $stderr = IO::Handle->new;
76 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
77 $^X, @switches, '-c', $file))
78 if $ENV{PERL_COMPILE_TEST_DEBUG};
80 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
81 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
82 my @_warnings = <$stderr>;
84 is($?, 0, "$file compiled ok");
86 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
87 and not eval { +require blib; blib->VERSION('1.01') };
89 # in older perls, -c output is simply the file portion of the path being tested
90 if (@_warnings = grep { !/\bsyntax OK$/ }
91 grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
94 push @warnings, @_warnings;
100 is(scalar(@warnings), 0, 'no warnings found')
101 or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING};