d23002ef3d04b8a96c6818e13cf3cb885b64ca32
[p5sagit/p5-mst-13.2.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 my %Test;
14
15 unless (open(MANIFEST, "MANIFEST")) {
16     die "$0: failed to open 'MANIFEST': $!\n";
17 }
18
19 sub add_by_name {
20     $Core_Modules{$_[0]}++;
21 }
22
23 while (<MANIFEST>) {
24     if (m!^(lib)/(\S+?)\.pm\s!) {
25         # Collecting modules names from under ext/ would be
26         # rather painful since the mapping from filenames
27         # to module names is not 100%.
28         my ($dir, $module) = ($1, $2);
29         $module =~ s!/!::!g;
30         add_by_name($module);
31     } elsif (m!^(lib|ext)/(\S+?)(?:\.t|/test.pl)\s!) {
32         my ($dir, $test) = ($1, $2);
33         $test =~ s!(\w+)/\1$!$1! if $dir eq 'ext';
34         $test =~ s!/t/[^/]+$!!;
35         $test =~ s!/!::!g;
36         $Test{$test}++;
37     }
38 }
39
40 close(MANIFEST);
41
42 # Delete stuff that can't be tested here.
43
44 sub delete_by_name {
45     delete $Core_Modules{$_[0]};
46 }
47
48 sub has_extension {
49     $Config{extensions} =~ /\b$_[0]\b/i;
50 }
51
52 sub delete_unless_has_extension {
53     delete $Core_Modules{$_[0]} unless has_extension($_[0]);
54 }
55
56 foreach my $known_extension (split(' ', $Config{known_extensions})) {
57     delete_unless_has_extension($known_extension);
58 }
59
60 sub delete_by_prefix {
61     for my $match (grep { /^$_[0]/ } keys %Core_Modules) {
62         delete_by_name($match);
63     }
64 }
65
66 delete_by_name('CGI::Fast');            # won't load without FCGI
67
68 delete_by_name('Devel::DProf');         # needs to be run as -d:DProf
69
70 delete_by_prefix('ExtUtils::MM_');      # ExtUtils::MakeMaker's domain
71
72 delete_by_prefix('File::Spec::');       # File::Spec's domain
73 add_by_name('File::Spec::Functions');   # put this back
74
75 delete_by_prefix('Attribute::Handlers');# we test this, and we have demos
76
77 sub using_feature {
78     my $use = "use$_[0]";
79     exists $Config{$use} &&
80         defined $Config{$use} &&
81         $Config{$use} eq 'define';
82 }
83
84 unless (using_feature('threads') && has_extension('Thread')) {
85     delete_by_name('Thread');
86     delete_by_prefix('Thread::');
87 }
88
89 unless (has_extension('NDBM_File')) {
90     delete_by_name('Memoize::NDBM_File');
91 }
92
93 delete_by_prefix('unicode::');
94
95 if (ord('A') == 193) {
96     delete_by_prefix('Net::') unless eval { require Convert::EBCDIC };
97 }
98
99 # Delete all modules which have their own tests.
100 # This makes this test a lot faster.
101 foreach my $mod (sort keys %Test) {
102     delete_by_name($mod);
103 }
104 foreach my $mod (<DATA>) {
105     chomp $mod;
106     print "### $mod has a test but is in DATA of $0\n" if exists $Test{$mod};
107     delete_by_name($mod);
108 }
109
110 # Okay, this is the list.
111
112 my @Core_Modules = sort keys %Core_Modules;
113
114 print "1..".@Core_Modules."\n";
115
116 my $test_num = 1;
117
118 foreach my $module (@Core_Modules) {
119     print "$module compile failed\nnot " unless compile_module($module);
120     print "ok $test_num\n";
121     $test_num++;
122 }
123
124 # We do this as a separate process else we'll blow the hell
125 # out of our namespace.
126 sub compile_module {
127     my ($module) = $_[0];
128     
129     my $out = scalar `$^X "-Ilib" t/lib/compmod.pl $module`;
130     print "# $out";
131     return $out =~ /^ok/;
132 }
133
134 # Add here modules that have their own test scripts and therefore
135 # need not be test-compiled by 1_compile.t.
136 __DATA__
137 B::ShowLex
138 CGI::Apache
139 CGI::Carp
140 CGI::Cookie
141 CGI::Form
142 CGI::Pretty
143 CGI::Push
144 CGI::Switch
145 CGI::Util
146 Carp::Heavy
147 CPAN::Nox
148 Devel::DProf
149 Exporter::Heavy
150 ExtUtils::Constant
151 ExtUtils::MakeMaker
152 Filter::Util::Call
153 GDBM_File
154 I18N::LangTags::List
155 IO::Dir
156 IO::File
157 IO::Handle
158 IO::Pipe
159 IO::Poll
160 IO::Seekable
161 IO::Select
162 IO::Socket
163 IO::Socket::INET
164 IO::Socket::UNIX
165 Locale::Constants
166 Locale::Country
167 Locale::Currency
168 Locale::Language
169 MIME::QuotedPrint
170 Math::BigFloat
171 Math::BigInt::Calc
172 Memoize::AnyDBM_File
173 Memoize::Expire
174 Memoize::ExpireFile
175 Memoize::ExpireTest
176 Memoize::NDBM_File
177 Memoize::SDBM_File
178 Memoize::Storable
179 NDBM_File
180 ODBM_File
181 Pod::Checker
182 Pod::Find
183 Pod::Text
184 Pod::Usage
185 SDBM_File
186 Safe
187 Scalar::Util
188 Sys::Syslog
189 Test::More
190 Test::ParseWords
191 Text::Tabs
192 Text::Wrap
193 Thread
194 Tie::Array
195 Tie::Handle
196 Tie::Hash
197 Time::tm
198 UNIVERSAL
199 attributes
200 base
201 bytes
202 ops
203 warnings::register