Debian Codegraph @

t/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;
7
8 plan tests => 60 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
9
10 my @module_files = (
11 'Dancer2.pm',
12 'Dancer2/CLI.pm',
13 'Dancer2/CLI/Gen.pm',
14 'Dancer2/CLI/Version.pm',
15 'Dancer2/ConfigReader.pm',
16 'Dancer2/ConfigReader/Config/Any.pm',
17 'Dancer2/ConfigUtils.pm',
18 'Dancer2/Core.pm',
19 'Dancer2/Core/App.pm',
20 'Dancer2/Core/Cookie.pm',
21 'Dancer2/Core/DSL.pm',
22 'Dancer2/Core/Dispatcher.pm',
23 'Dancer2/Core/Error.pm',
24 'Dancer2/Core/Factory.pm',
25 'Dancer2/Core/HTTP.pm',
26 'Dancer2/Core/Hook.pm',
27 'Dancer2/Core/MIME.pm',
28 'Dancer2/Core/Request.pm',
29 'Dancer2/Core/Request/Upload.pm',
30 'Dancer2/Core/Response.pm',
31 'Dancer2/Core/Response/Delayed.pm',
32 'Dancer2/Core/Role/ConfigReader.pm',
33 'Dancer2/Core/Role/DSL.pm',
34 'Dancer2/Core/Role/Engine.pm',
35 'Dancer2/Core/Role/Handler.pm',
36 'Dancer2/Core/Role/HasConfig.pm',
37 'Dancer2/Core/Role/HasEnvironment.pm',
38 'Dancer2/Core/Role/HasLocation.pm',
39 'Dancer2/Core/Role/Hookable.pm',
40 'Dancer2/Core/Role/Logger.pm',
41 'Dancer2/Core/Role/Serializer.pm',
42 'Dancer2/Core/Role/SessionFactory.pm',
43 'Dancer2/Core/Role/SessionFactory/File.pm',
44 'Dancer2/Core/Role/StandardResponses.pm',
45 'Dancer2/Core/Role/Template.pm',
46 'Dancer2/Core/Route.pm',
47 'Dancer2/Core/Runner.pm',
48 'Dancer2/Core/Session.pm',
49 'Dancer2/Core/Time.pm',
50 'Dancer2/Core/Types.pm',
51 'Dancer2/FileUtils.pm',
52 'Dancer2/Handler/AutoPage.pm',
53 'Dancer2/Handler/File.pm',
54 'Dancer2/Logger/Capture.pm',
55 'Dancer2/Logger/Capture/Trap.pm',
56 'Dancer2/Logger/Console.pm',
57 'Dancer2/Logger/Diag.pm',
58 'Dancer2/Logger/File.pm',
59 'Dancer2/Logger/Note.pm',
60 'Dancer2/Logger/Null.pm',
61 'Dancer2/Plugin.pm',
62 'Dancer2/Serializer/JSON.pm',
63 'Dancer2/Serializer/Mutable.pm',
64 'Dancer2/Serializer/YAML.pm',
65 'Dancer2/Session/Simple.pm',
66 'Dancer2/Session/YAML.pm',
67 'Dancer2/Template/TemplateToolkit.pm',
68 'Dancer2/Template/Tiny.pm',
69 'Dancer2/Test.pm'
70 );
71
72 my @scripts = (
73 'script/dancer2'
74 );
75
76 # no fake home requested
77
78 my @switches = (
79 -d 'blib' ? '-Mblib' : '-Ilib',
80 );
81
82 use File::Spec;
83 use IPC::Open3;
84 use IO::Handle;
85
86 open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
87
88 my @warnings;
89 for my $lib (@module_files)
90 {
91 # see L<perlfaq8/How can I capture STDERR from an external command?>
92 my $stderr = IO::Handle->new;
93
94 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'}.$str.q{'} }
95 $^X, @switches, '-e', "require q[$lib]"))
96 if $ENV{PERL_COMPILE_TEST_DEBUG};
97
98 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
99 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
100 my @_warnings = <$stderr>;
101 waitpid($pid, 0);
102 is($?, 0, "$lib loaded ok");
103
104 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
105 and not eval { +require blib; blib->VERSION('1.01') };
106
107 if (@_warnings)
108 {
109 warn @_warnings;
110 push @warnings, @_warnings;
111 }
112 }
113
114 foreach my $file (@scripts)
115 { SKIP: {
116 open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
117 my $line = <$fh>;
118
119 close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*(?:env )?perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
120 @switches = (@switches, split(' ', $1)) if $1;
121
122 close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
123 if grep $_ eq '-T', @switches and $ENV{PERL5LIB};
124
125 my $stderr = IO::Handle->new;
126
127 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'}.$str.q{'} }
128 $^X, @switches, '-c', $file))
129 if $ENV{PERL_COMPILE_TEST_DEBUG};
130
131 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
132 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
133 my @_warnings = <$stderr>;
134 waitpid($pid, 0);
135 is($?, 0, "$file compiled ok");
136
137 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
138 and not eval { +require blib; blib->VERSION('1.01') };
139
140 # in older perls, -c output is simply the file portion of the path being tested
141 if (@_warnings = grep !/\bsyntax OK$/,
142 grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
143 {
144 warn @_warnings;
145 push @warnings, @_warnings;
146 }
147 } }
148
149
150
151 is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING};
152
153