Debian Codegraph @

xt/author/00-compile.t

raw
1 use strict;
2 use warnings;
3
4 # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.059
5
6 use Test::More 0.94;
7
8 plan tests => 18;
9
10 my @module_files = (
11 'JSON/Schema/Modern.pm',
12 'JSON/Schema/Modern/Annotation.pm',
13 'JSON/Schema/Modern/Document.pm',
14 'JSON/Schema/Modern/Error.pm',
15 'JSON/Schema/Modern/Result.pm',
16 'JSON/Schema/Modern/ResultNode.pm',
17 'JSON/Schema/Modern/Utilities.pm',
18 'JSON/Schema/Modern/Vocabulary.pm',
19 'JSON/Schema/Modern/Vocabulary/Applicator.pm',
20 'JSON/Schema/Modern/Vocabulary/Content.pm',
21 'JSON/Schema/Modern/Vocabulary/Core.pm',
22 'JSON/Schema/Modern/Vocabulary/FormatAnnotation.pm',
23 'JSON/Schema/Modern/Vocabulary/FormatAssertion.pm',
24 'JSON/Schema/Modern/Vocabulary/MetaData.pm',
25 'JSON/Schema/Modern/Vocabulary/Unevaluated.pm',
26 'JSON/Schema/Modern/Vocabulary/Validation.pm'
27 );
28
29 my @scripts = (
30 'script/json-schema-eval'
31 );
32
33 # no fake home requested
34
35 my @switches = (
36 -d 'blib' ? '-Mblib' : '-Ilib',
37 );
38
39 use File::Spec;
40 use IPC::Open3;
41 use IO::Handle;
42
43 open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
44
45 my @warnings;
46 for my $lib (@module_files)
47 {
48 # see L<perlfaq8/How can I capture STDERR from an external command?>
49 my $stderr = IO::Handle->new;
50
51 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'}.$str.q{'} }
52 $^X, @switches, '-e', "require q[$lib]"))
53 if $ENV{PERL_COMPILE_TEST_DEBUG};
54
55 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
56 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
57 my @_warnings = <$stderr>;
58 waitpid($pid, 0);
59 is($?, 0, "$lib loaded ok");
60
61 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
62 and not eval { +require blib; blib->VERSION('1.01') };
63
64 if (@_warnings)
65 {
66 warn @_warnings;
67 push @warnings, @_warnings;
68 }
69 }
70
71 foreach my $file (@scripts)
72 { SKIP: {
73 open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
74 my $line = <$fh>;
75
76 close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*(?:env )?perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
77 @switches = (@switches, split(' ', $1)) if $1;
78
79 close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
80 if grep $_ eq '-T', @switches and $ENV{PERL5LIB};
81
82 my $stderr = IO::Handle->new;
83
84 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'}.$str.q{'} }
85 $^X, @switches, '-c', $file))
86 if $ENV{PERL_COMPILE_TEST_DEBUG};
87
88 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
89 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
90 my @_warnings = <$stderr>;
91 waitpid($pid, 0);
92 is($?, 0, "$file compiled ok");
93
94 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
95 and not eval { +require blib; blib->VERSION('1.01') };
96
97 # in older perls, -c output is simply the file portion of the path being tested
98 if (@_warnings = grep !/\bsyntax OK$/,
99 grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
100 {
101 warn @_warnings;
102 push @warnings, @_warnings;
103 }
104 } }
105
106
107
108 is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', explain(\@warnings);
109
110 BAIL_OUT("Compilation problems") if !Test::More->builder->is_passing;