This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
vars very much has a test.
[perl5.git] / t / lib / 1_compile.t
1 #!./perl
2
3 BEGIN {
4     chdir '..' if -d '../pod' && -d '../t';
5     @INC = 'lib';
6 }
7
8 use strict;
9 use warnings;
10 use Config;
11
12 my %Core_Modules;
13
14 unless (open(MANIFEST, "MANIFEST")) {
15     die "$0: failed to open 'MANIFEST': $!\n";
16 }
17
18 sub add_by_name {
19     $Core_Modules{$_[0]}++;
20 }
21
22 while (<MANIFEST>) {
23     next unless m!^lib/(\S+?)\.pm!;
24     my $module = $1;
25     $module =~ s!/!::!g;
26     add_by_name($module);
27 }
28
29 close(MANIFEST);
30
31 # Delete stuff that can't be tested here.
32
33 sub delete_by_name {
34     delete $Core_Modules{$_[0]};
35 }
36
37 sub has_extension {
38     $Config{extensions} =~ /\b$_[0]\b/i;
39 }
40
41 sub delete_unless_has_extension {
42     delete $Core_Modules{$_[0]} unless has_extension($_[0]);
43 }
44
45 foreach my $known_extension (split(' ', $Config{known_extensions})) {
46     delete_unless_has_extension($known_extension);
47 }
48
49 sub delete_by_prefix {
50     for my $match (grep { /^$_[0]/ } keys %Core_Modules) {
51         delete_by_name($match);
52     }
53 }
54
55 delete_by_name('CGI::Fast');            # won't load without FCGI
56
57 delete_by_name('Devel::DProf');         # needs to be run as -d:DProf
58
59 delete_by_prefix('ExtUtils::MM_');      # ExtUtils::MakeMaker's domain
60
61 delete_by_prefix('File::Spec::');       # File::Spec's domain
62 add_by_name('File::Spec::Functions');   # put this back
63
64 delete_by_prefix('Attribute::Handlers');# we test this, and we have demos
65
66 sub using_feature {
67     my $use = "use$_[0]";
68     exists $Config{$use} &&
69         defined $Config{$use} &&
70         $Config{$use} eq 'define';
71 }
72
73 unless (using_feature('threads') && has_extension('Thread')) {
74     delete_by_name('Thread');
75     delete_by_prefix('Thread::');
76 }
77
78 unless (has_extension('NDBM_File')) {
79     delete_by_name('Memoize::NDBM_File');
80 }
81
82 delete_by_prefix('unicode::');
83
84 # Delete all modules which have their own tests.
85 # This makes this test a lot faster.
86 foreach my $mod (<DATA>) {
87     chomp $mod;
88     delete_by_name($mod);
89 }
90
91 # Okay, this is the list.
92
93 my @Core_Modules = sort keys %Core_Modules;
94
95 print "1..".@Core_Modules."\n";
96
97 my $test_num = 1;
98
99 foreach my $module (@Core_Modules) {
100     print "$module compile failed\nnot " unless compile_module($module);
101     print "ok $test_num\n";
102     $test_num++;
103 }
104
105 # We do this as a separate process else we'll blow the hell
106 # out of our namespace.
107 sub compile_module {
108     my ($module) = $_[0];
109     
110     my $out = scalar `$^X "-Ilib" t/lib/compmod.pl $module`;
111     print "# $out";
112     return $out =~ /^ok/;
113 }
114
115 # Add here modules that have their own test scripts and therefore
116 # need not be test-compiled by 1_compile.t.
117 __DATA__
118 AnyDBM_File
119 Attribute::Handlers
120 AutoLoader
121 B
122 B::Debug
123 B::Deparse
124 B::ShowLex
125 B::Stash
126 Benchmark
127 CGI
128 CGI::Apache
129 CGI::Carp
130 CGI::Cookie
131 CGI::Form
132 CGI::Pretty
133 CGI::Switch
134 CGI::Util
135 Carp
136 Carp::Heavy
137 Class::ISA
138 Class::Struct
139 CPAN
140 Cwd
141 DB_File
142 Data::Dumper
143 Devel::DProf
144 Devel::Peek
145 Devel::SelfStubber
146 Digest
147 Digest::MD5
148 DirHandle
149 Dumpvalue
150 Encode
151 English
152 Env
153 Errno
154 Exporter
155 Exporter::Heavy
156 ExtUtils::Constant
157 ExtUtils::MakeMaker
158 Fatal
159 Fcntl
160 File::Basename
161 File::CheckTree
162 File::Compare
163 File::Copy
164 File::DosGlob
165 File::Find
166 File::Glob
167 File::Path
168 File::Spec
169 File::Spec::Functions
170 File::Temp
171 File::stat
172 FileCache
173 FileHandle
174 Filter::Simple
175 Filter::Util::Call
176 FindBin
177 GDBM_File
178 Getopt::Long
179 Getopt::Std
180 I18N::Langinfo
181 I18N::LangTags
182 I18N::LangTags::List
183 I18N::Collate
184 IO::Dir
185 IO::File
186 IO::Handle
187 IO::Pipe
188 IO::Poll
189 IO::Seekable
190 IO::Select
191 IO::Socket
192 IO::Socket::INET
193 IO::Socket::UNIX
194 IPC::Open2
195 IPC::Open3
196 IPC::SysV
197 Lingua::KO::Hangul::Util
198 List::Util
199 Locale::Constants
200 Locale::Country
201 Locale::Currency
202 Locale::Language
203 Locale::Maketext
204 MIME::Base64
205 MIME::QuotedPrint
206 Math::BigFloat
207 Math::BigInt
208 Math::BigInt::Calc
209 Math::Complex
210 Math::Trig
211 Memoize
212 Memoize::AnyDBM_File
213 Memoize::Expire
214 Memoize::ExpireFile
215 Memoize::ExpireTest
216 Memoize::NDBM_File
217 Memoize::SDBM_File
218 Memoize::Storable
219 NDBM_File
220 NEXT
221 Net::hostent
222 Net::netent
223 Net::protoent
224 Net::servent
225 ODBM_File
226 Opcode
227 PerlIO
228 POSIX
229 Pod::Checker
230 Pod::Find
231 Pod::Text
232 Pod::Usage
233 SDBM_File
234 Safe
235 Scalar::Util
236 Search::Dict
237 SelectSaver
238 SelfLoader
239 Shell
240 Socket
241 Storable
242 Switch
243 Symbol
244 Sys::Hostname
245 Sys::Syslog
246 Term::ANSIColor
247 Test
248 Test::Harness
249 Test::More
250 Test::Simple
251 Test::ParseWords
252 Text::Abbrev
253 Text::Balanced
254 Text::ParseWords
255 Text::Soundex
256 Text::Tabs
257 Text::Wrap
258 Thread
259 Tie::Array
260 Tie::Handle
261 Tie::Hash
262 Tie::RefHash
263 Tie::Scalar
264 Tie::SubstrHash
265 Time::HiRes
266 Time::Local
267 Time::gmtime
268 Time::localtime
269 Time::tm
270 Unicode::Collate
271 Unicode::Normalize
272 Unicode::UCD
273 UNIVERSAL
274 User::grent
275 User::pwent
276 XS::Typemap
277 attributes
278 attrs
279 autouse
280 base
281 bytes
282 charnames
283 constant
284 diagnostics
285 fields
286 integer
287 less
288 locale
289 ops
290 overload
291 strict
292 subs
293 utf8
294 vars
295 warnings
296 warnings::register