]> Dogcows Code - chaz/groupsecret/blob - t/00-compile.t
Version 0.303
[chaz/groupsecret] / 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.057
6
7 use Test::More;
8
9 plan tests => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
10
11 my @module_files = (
12 'App/GroupSecret.pm',
13 'App/GroupSecret/Crypt.pm',
14 'App/GroupSecret/File.pm'
15 );
16
17 my @scripts = (
18 'bin/groupsecret'
19 );
20
21 # no fake home requested
22
23 my @switches = (
24 -d 'blib' ? '-Mblib' : '-Ilib',
25 );
26
27 use File::Spec;
28 use IPC::Open3;
29 use IO::Handle;
30
31 open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
32
33 my @warnings;
34 for my $lib (@module_files)
35 {
36 # see L<perlfaq8/How can I capture STDERR from an external command?>
37 my $stderr = IO::Handle->new;
38
39 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
40 $^X, @switches, '-e', "require q[$lib]"))
41 if $ENV{PERL_COMPILE_TEST_DEBUG};
42
43 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
44 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
45 my @_warnings = <$stderr>;
46 waitpid($pid, 0);
47 is($?, 0, "$lib loaded ok");
48
49 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
50 and not eval { +require blib; blib->VERSION('1.01') };
51
52 if (@_warnings)
53 {
54 warn @_warnings;
55 push @warnings, @_warnings;
56 }
57 }
58
59 foreach my $file (@scripts)
60 { SKIP: {
61 open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
62 my $line = <$fh>;
63
64 close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
65 @switches = (@switches, split(' ', $1)) if $1;
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')
94 or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING};
95
96
This page took 0.058756 seconds and 4 git commands to generate.