Integrate mainline (Win2k/MinGW all ok except threads/t/end.t)
[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     s/_pm\.PL/.pm/; # Don't forget the extracted modules
25     if (m!^(lib)/(\S+?)\.pm\s!) {
26         # Collecting modules names from under ext/ would be
27         # rather painful since the mapping from filenames
28         # to module names is not 100%.
29         my ($dir, $module) = ($1, $2);
30         $module =~ s!/!::!g;
31         add_by_name($module);
32     } elsif (m!^(lib|ext)/(\S+?)(?:\.t|/test.pl)\s!) {
33         my ($dir, $test) = ($1, $2);
34         $test =~ s!(\w+)/\1$!$1! if $dir eq 'ext';
35         $test =~ s!/t/[^/]+$!!;
36         $test =~ s!/!::!g;
37         $Test{$test}++;
38     }
39 }
40
41 close(MANIFEST);
42
43 # Delete stuff that can't be tested here.
44
45 sub delete_by_name {
46     delete $Core_Modules{$_[0]};
47 }
48
49 sub has_extension {
50     $Config{extensions} =~ /\b$_[0]\b/i;
51 }
52
53 sub delete_unless_has_extension {
54     delete $Core_Modules{$_[0]} unless has_extension($_[0]);
55 }
56
57 foreach my $known_extension (split(' ', $Config{known_extensions})) {
58     delete_unless_has_extension($known_extension);
59 }
60
61 sub delete_by_prefix {
62     for my $match (grep { /^$_[0]/ } keys %Core_Modules) {
63         delete_by_name($match);
64     }
65 }
66
67 delete_by_name('CGI::Fast');            # won't load without FCGI
68
69 delete_by_prefix('ExtUtils::MM_');      # ExtUtils::MakeMaker's domain
70
71 delete_by_prefix('File::Spec::');       # File::Spec's domain
72 add_by_name('File::Spec::Functions');   # put this back
73
74 delete_by_prefix('Attribute::Handlers');# we test this, and we have demos
75
76 delete_by_prefix('Net::FTP::');         # Net::FTP is tested.
77
78 # In this case we could rely on the fake Socket layer the libnet tests
79 # use but frankly I think in this case we might as well let it be.
80 delete_by_prefix('Net::') unless has_extension('Socket');
81
82 sub using_feature {
83     my $use = "use$_[0]";
84     exists $Config{$use} &&
85         defined $Config{$use} &&
86         $Config{$use} eq 'define';
87 }
88
89 unless (using_feature('threads') && has_extension('Thread')) {
90     delete_by_name('Thread');
91     delete_by_prefix('Thread::');
92 }
93
94 unless (has_extension('NDBM_File')) {
95     delete_by_name('Memoize::NDBM_File');
96 }
97
98 if (ord('A') == 193) {
99     delete_by_prefix('Net::') unless eval { require Convert::EBCDIC };
100 }
101
102 # Delete all modules which have their own tests.
103 # This makes this test a lot faster.
104 foreach my $mod (sort keys %Test) {
105     delete_by_name($mod);
106 }
107 foreach my $mod (<DATA>) {
108     chomp $mod;
109     print "### $mod has a test but is in DATA of $0\n" if exists $Test{$mod};
110     delete_by_name($mod);
111 }
112
113 # Okay, this is the list.
114
115 my @Core_Modules = sort keys %Core_Modules;
116
117 print "1..".(1+@Core_Modules)."\n";
118
119 my $message
120   = "ok 1 - All modules should have tests # TODO Make Schwern Poorer\n";
121 if (@Core_Modules) {
122   print "not $message";
123 } else {
124   print $message;
125 }
126
127 my $test_num = 2;
128
129 foreach my $module (@Core_Modules) {
130     print "$module compile failed\nnot " unless compile_module($module);
131     print "ok $test_num\n";
132     $test_num++;
133 }
134
135 # We do this as a separate process else we'll blow the hell
136 # out of our namespace.
137 sub compile_module {
138     my ($module) = $_[0];
139     
140     my $out = scalar `$^X "-Ilib" t/lib/compmod.pl $module`;
141     print "# $out";
142     return $out =~ /^ok/;
143 }
144
145 # Add here modules that have their own test scripts and therefore
146 # need not be test-compiled by 1_compile.t.
147 __DATA__
148 B::ShowLex
149 CGI::Apache
150 CGI::Carp
151 CGI::Cookie
152 CGI::Form
153 CGI::Pretty
154 CGI::Push
155 CGI::Switch
156 CGI::Util
157 Carp::Heavy
158 CPAN::Nox
159 Exporter::Heavy
160 ExtUtils::Command
161 ExtUtils::Constant
162 ExtUtils::Embed
163 ExtUtils::Installed
164 ExtUtils::MakeMaker
165 ExtUtils::Manifest
166 ExtUtils::Mkbootstrap
167 ExtUtils::Packlist
168 File::Spec::Functions
169 Filter::Util::Call
170 GDBM_File
171 I18N::LangTags::List
172 IO::Dir
173 IO::File
174 IO::Handle
175 IO::Pipe
176 IO::Poll
177 IO::Seekable
178 IO::Select
179 IO::Socket
180 IO::Socket::INET
181 IO::Socket::UNIX
182 Locale::Constants
183 Locale::Country
184 Locale::Currency
185 Locale::Language
186 Locale::Script
187 MIME::QuotedPrint
188 Math::BigFloat
189 Math::BigInt::Calc
190 Memoize::AnyDBM_File
191 Memoize::Expire
192 Memoize::ExpireFile
193 Memoize::ExpireTest
194 Memoize::NDBM_File
195 Memoize::SDBM_File
196 Memoize::Storable
197 NDBM_File
198 Net::Config
199 Net::FTP
200 Net::Netrc
201 Net::NNTP
202 Net::SMTP
203 Net::Time
204 ODBM_File
205 Pod::Checker
206 Pod::Find
207 Pod::Functions
208 Pod::Html
209 Pod::InputObjects
210 Pod::LaTeX
211 Pod::Man
212 Pod::ParseLink
213 Pod::ParseUtils
214 Pod::Select
215 Pod::Text
216 Pod::Text::Overstrike
217 Pod::Text::Termcap
218 Pod::Usage
219 SDBM_File
220 Safe
221 Scalar::Util
222 Sys::Syslog
223 Test::Builder
224 Test::Harness::Assert
225 Test::Harness::Straps
226 Test::More
227 Test::ParseWords
228 Text::Tabs
229 Text::Wrap
230 Thread
231 Tie::Array
232 Tie::Handle
233 Tie::Hash
234 Time::tm
235 UNIVERSAL
236 attributes
237 base
238 ops
239 warnings::register