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