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