Re: [PATCH] ...while $var = glob(...)
[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..".@Core_Modules."\n";
118
119 my $test_num = 1;
120
121 foreach my $module (@Core_Modules) {
122     print "$module compile failed\nnot " unless compile_module($module);
123     print "ok $test_num\n";
124     $test_num++;
125 }
126
127 # We do this as a separate process else we'll blow the hell
128 # out of our namespace.
129 sub compile_module {
130     my ($module) = $_[0];
131     
132     my $out = scalar `$^X "-Ilib" t/lib/compmod.pl $module`;
133     print "# $out";
134     return $out =~ /^ok/;
135 }
136
137 # Add here modules that have their own test scripts and therefore
138 # need not be test-compiled by 1_compile.t.
139 __DATA__
140 B::ShowLex
141 CGI::Apache
142 CGI::Carp
143 CGI::Cookie
144 CGI::Form
145 CGI::Pretty
146 CGI::Push
147 CGI::Switch
148 CGI::Util
149 Carp::Heavy
150 CPAN::Nox
151 Exporter::Heavy
152 ExtUtils::Constant
153 ExtUtils::MakeMaker
154 Filter::Util::Call
155 GDBM_File
156 I18N::LangTags::List
157 IO::Dir
158 IO::File
159 IO::Handle
160 IO::Pipe
161 IO::Poll
162 IO::Seekable
163 IO::Select
164 IO::Socket
165 IO::Socket::INET
166 IO::Socket::UNIX
167 Locale::Constants
168 Locale::Country
169 Locale::Currency
170 Locale::Language
171 MIME::QuotedPrint
172 Math::BigFloat
173 Math::BigInt::Calc
174 Memoize::AnyDBM_File
175 Memoize::Expire
176 Memoize::ExpireFile
177 Memoize::ExpireTest
178 Memoize::NDBM_File
179 Memoize::SDBM_File
180 Memoize::Storable
181 NDBM_File
182 Net::Config
183 Net::FTP
184 Net::Netrc
185 Net::NNTP
186 Net::SMTP
187 Net::Time
188 ODBM_File
189 Pod::Checker
190 Pod::Find
191 Pod::Html
192 Pod::LaTeX
193 Pod::Man
194 Pod::ParseLink
195 Pod::ParseUtils
196 Pod::Text
197 Pod::Text::Overstrike
198 Pod::Text::Termcap
199 Pod::Usage
200 SDBM_File
201 Safe
202 Scalar::Util
203 Sys::Syslog
204 Test::More
205 Test::ParseWords
206 Text::Tabs
207 Text::Wrap
208 Thread
209 Tie::Array
210 Tie::Handle
211 Tie::Hash
212 Time::tm
213 UNIVERSAL
214 attributes
215 base
216 ops
217 warnings::register