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