Debian Codegraph @

xt/author/00-compile.t

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