]> Dogcows Code - chaz/graphql-client/blob - t/00-compile.t
676ed70453919689ad4c038ef1158fbe4f0df79e
[chaz/graphql-client] / 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 => 4 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
10
11 my @module_files = (
12 'GraphQL/Client.pm',
13 'GraphQL/Client/http.pm',
14 'GraphQL/Client/https.pm'
15 );
16
17 my @scripts = (
18 'bin/graphql'
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 close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
68 if grep { $_ eq '-T' } @switches and $ENV{PERL5LIB};
69
70 my $stderr = IO::Handle->new;
71
72 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
73 $^X, @switches, '-c', $file))
74 if $ENV{PERL_COMPILE_TEST_DEBUG};
75
76 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
77 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
78 my @_warnings = <$stderr>;
79 waitpid($pid, 0);
80 is($?, 0, "$file compiled ok");
81
82 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
83 and not eval { +require blib; blib->VERSION('1.01') };
84
85 # in older perls, -c output is simply the file portion of the path being tested
86 if (@_warnings = grep { !/\bsyntax OK$/ }
87 grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
88 {
89 warn @_warnings;
90 push @warnings, @_warnings;
91 }
92 } }
93
94
95
96 is(scalar(@warnings), 0, 'no warnings found')
97 or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING};
98
99
This page took 0.042302 seconds and 3 git commands to generate.