Re: Why t/lib/extutils.t is failing (was Re: [PATCH] Re: [PATCH] Re: [SPAM] Re:...
[p5sagit/p5-mst-13.2.git] / t / lib / extutils.t
CommitLineData
af6c647e 1#!./perl -w
2
835f860c 3print "1..12\n";
af6c647e 4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8}
9
10use warnings;
11use strict;
12use ExtUtils::MakeMaker;
13use ExtUtils::Constant qw (constant_types C_constant XS_constant autoload);
14use Config;
835f860c 15use File::Spec::Functions;
16use File::Spec;
17# Because were are going to be changing directory before running Makefile.PL
18my $perl = File::Spec->rel2abs( $^X );
af6c647e 19
835f860c 20print "# perl=$perl\n";
21my $runperl = "$perl \"-I../../lib\"";
94b1a389 22
af6c647e 23$| = 1;
24
25my $dir = "ext-$$";
0ddb8edc 26my @files;
94b1a389 27
28print "# $dir being created...\n";
29mkdir $dir, 0777 or die "mkdir: $!\n";
30
af6c647e 31
32END {
94b1a389 33 use File::Path;
34 print "# $dir being removed...\n";
35 rmtree($dir);
af6c647e 36}
37
835f860c 38my @names = ("FIVE", {name=>"OK6", type=>"PV",},
39 {name=>"OK7", type=>"PVN",
40 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
af6c647e 41 {name => "FARTHING", type=>"NV"},
7abfcde3 42 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"});
af6c647e 43
44my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
45
46my $package = "ExtTest";
47################ Header
94b1a389 48my $header = catfile($dir, "test.h");
0ddb8edc 49push @files, "test.h";
94b1a389 50open FH, ">$header" or die "open >$header: $!\n";
af6c647e 51print FH <<'EOT';
835f860c 52#define FIVE 5
53#define OK6 "ok 6\n"
54#define OK7 1
af6c647e 55#define FARTHING 0.25
56#define NOT_ZERO 1
57EOT
94b1a389 58close FH or die "close $header: $!\n";
af6c647e 59
60################ XS
94b1a389 61my $xs = catfile($dir, "$package.xs");
0ddb8edc 62push @files, "$package.xs";
94b1a389 63open FH, ">$xs" or die "open >$xs: $!\n";
af6c647e 64
65print FH <<'EOT';
66#include "EXTERN.h"
67#include "perl.h"
68#include "XSUB.h"
69EOT
70
71print FH "#include \"test.h\"\n\n";
72print FH constant_types(); # macro defs
73my $types = {};
74foreach (C_constant (undef, "IV", $types, undef, undef, @names) ) {
75 print FH $_, "\n"; # C constant subs
76}
77print FH "MODULE = $package PACKAGE = $package\n";
78print FH "PROTOTYPES: ENABLE\n";
79print FH XS_constant ($package, $types); # XS for ExtTest::constant
94b1a389 80close FH or die "close $xs: $!\n";
af6c647e 81
82################ PM
94b1a389 83my $pm = catfile($dir, "$package.pm");
0ddb8edc 84push @files, "$package.pm";
94b1a389 85open FH, ">$pm" or die "open >$pm: $!\n";
af6c647e 86print FH "package $package;\n";
87print FH "use $];\n";
88
89print FH <<'EOT';
90
91use strict;
92use warnings;
93use Carp;
94
95require Exporter;
96require DynaLoader;
97use AutoLoader;
98use vars qw ($VERSION @ISA @EXPORT_OK);
99
100$VERSION = '0.01';
101@ISA = qw(Exporter DynaLoader);
102@EXPORT_OK = qw(
103EOT
104
105print FH "\t$_\n" foreach (@names_only);
106print FH ");\n";
107print FH autoload ($package, $]);
108print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
94b1a389 109close FH or die "close $pm: $!\n";
af6c647e 110
111################ test.pl
94b1a389 112my $testpl = catfile($dir, "test.pl");
0ddb8edc 113push @files, "test.pl";
94b1a389 114open FH, ">$testpl" or die "open >$testpl: $!\n";
af6c647e 115
116print FH "use $package qw(@names_only);\n";
117print FH <<'EOT';
118
835f860c 119my $five = FIVE;
120if ($five == 5) {
121 print "ok 5\n";
af6c647e 122} else {
835f860c 123 print "not ok 5 # $five\n";
af6c647e 124}
125
835f860c 126print OK6;
af6c647e 127
835f860c 128$_ = OK7;
af6c647e 129s/.*\0//s;
130print;
131
132my $farthing = FARTHING;
133if ($farthing == 0.25) {
835f860c 134 print "ok 8\n";
af6c647e 135} else {
835f860c 136 print "not ok 8 # $farthing\n";
af6c647e 137}
138
139my $not_zero = NOT_ZERO;
140if ($not_zero > 0 && $not_zero == ~0) {
835f860c 141 print "ok 9\n";
af6c647e 142} else {
835f860c 143 print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
af6c647e 144}
145
146
147EOT
148
94b1a389 149close FH or die "close $testpl: $!\n";
af6c647e 150
835f860c 151################ Makefile.PL
af6c647e 152# Keep the dependancy in the Makefile happy
94b1a389 153my $makefilePL = catfile($dir, "Makefile.PL");
0ddb8edc 154push @files, "Makefile.PL";
94b1a389 155open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
835f860c 156print FH <<"EOT";
157use ExtUtils::MakeMaker;
158WriteMakefile(
159 'NAME' => "$package",
160 'VERSION_FROM' => "$package.pm", # finds \$VERSION
161 (\$] >= 5.005 ?
162 (#ABSTRACT_FROM => "$package.pm", # XXX add this
163 AUTHOR => "$0") : ())
164 );
165EOT
166
94b1a389 167close FH or die "close $makefilePL: $!\n";
af6c647e 168
169chdir $dir or die $!; push @INC, '../../lib';
170END {chdir ".." or warn $!};
171
835f860c 172my @perlout = `$runperl Makefile.PL`;
173if ($?) {
174 print "not ok 1 # $runperl Makefile.PL failed: $?\n";
175 print "# $_" foreach @perlout;
176 exit($?);
177} else {
178 print "ok 1\n";
179}
180
181
24874030 182my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
183my $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
184if (-f "$makefile$makefile_ext") {
835f860c 185 print "ok 2\n";
af6c647e 186} else {
835f860c 187 print "not ok 2\n";
af6c647e 188}
24874030 189my $makefile_rename = ($^O eq 'VMS' ? '.mms' : '.old');
190push @files, "$makefile$makefile_rename"; # Renamed by make clean
af6c647e 191
192my $make = $Config{make};
94b1a389 193
af6c647e 194$make = $ENV{MAKE} if exists $ENV{MAKE};
94b1a389 195
196my $makeout;
197
af6c647e 198print "# make = '$make'\n";
94b1a389 199$makeout = `$make`;
200if ($?) {
835f860c 201 print "not ok 3 # $make failed: $?\n";
94b1a389 202 exit($?);
af6c647e 203} else {
835f860c 204 print "ok 3\n";
205}
206
207if ($Config{usedl}) {
208 print "ok 4\n";
209} else {
210 push @files, "perl$Config{exe_ext}";
211 my $makeperl = "$make perl";
212 print "# make = '$makeperl'\n";
213 $makeout = `$makeperl`;
214 if ($?) {
215 print "not ok 4 # $makeperl failed: $?\n";
216 exit($?);
217 } else {
218 print "ok 4\n";
219 }
af6c647e 220}
221
0ddb8edc 222my $maketest = "$make test";
223print "# make = '$maketest'\n";
224$makeout = `$maketest`;
94b1a389 225if ($?) {
835f860c 226 print "not ok 10 # $maketest failed: $?\n";
af6c647e 227} else {
94b1a389 228 # Perl babblings
737e87b0 229 $makeout =~ s/^\s*PERL_DL_NONLAZY=.+?\n//m;
94b1a389 230
231 # GNU make babblings
232 $makeout =~ s/^\w*?make.+?(?:entering|leaving) directory.+?\n//mig;
233
835f860c 234 # Hopefully gets most make's babblings
235 # make -f Makefile.aperl perl
236 $makeout =~ s/^\w*?make.+\sperl[^A-Za-z0-9]*\n//mig;
237 # make[1]: `perl' is up to date.
238 $makeout =~ s/^\w*?make.+perl.+?is up to date.*?\n//mig;
239
94b1a389 240 print $makeout;
835f860c 241 print "ok 10\n";
af6c647e 242}
0ddb8edc 243
244my $makeclean = "$make clean";
245print "# make = '$makeclean'\n";
246$makeout = `$makeclean`;
247if ($?) {
835f860c 248 print "not ok 11 # $make failed: $?\n";
0ddb8edc 249} else {
835f860c 250 print "ok 11\n";
0ddb8edc 251}
252
253foreach (@files) {
254 unlink $_ or warn "unlink $_: $!";
255}
256
257my $fail;
258opendir DIR, "." or die "opendir '.': $!";
259while (defined (my $entry = readdir DIR)) {
260 next if $entry =~ /^\.\.?$/;
261 print "# Extra file '$entry'\n";
262 $fail = 1;
263}
264closedir DIR or warn "closedir '.': $!";
265if ($fail) {
835f860c 266 print "not ok 12\n";
0ddb8edc 267} else {
835f860c 268 print "ok 12\n";
0ddb8edc 269}