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