12 use ExtUtils::MakeMaker;
13 use ExtUtils::Constant qw (constant_types C_constant XS_constant autoload);
15 use File::Spec::Functions;
17 # Because were are going to be changing directory before running Makefile.PL
18 my $perl = File::Spec->rel2abs( $^X );
19 # ExtUtils::Constant::C_constant uses $^X inside a comment, and we want to
20 # compare output to ensure that it is the same. We were probably run as ./perl
21 # whereas we will run the child with the full path in $perl. So make $^X for
22 # us the same as our child will see.
25 print "# perl=$perl\n";
26 my $runperl = "$perl -x \"-I../../lib\"";
33 print "# $dir being created...\n";
34 mkdir $dir, 0777 or die "mkdir: $!\n";
39 print "# $dir being removed...\n";
43 my $package = "ExtTest";
45 my @names = ("FIVE", {name=>"OK6", type=>"PV",},
46 {name=>"OK7", type=>"PVN",
47 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
48 {name => "FARTHING", type=>"NV"},
49 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
50 {name => "OPEN", type=>"PV", value=>'"/*"',
51 macro=>["#if 1\n", "#endif\n"]},
52 {name => "CLOSE", type=>"PV", value=>'"*/"',
53 macro=>["#if 1\n", "#endif\n"]},
54 {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
55 {name => "Yes", type=>"YES"},
56 {name => "No", type=>"NO"},
57 {name => "Undef", type=>"UNDEF"}
60 my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
63 my $constant_types = constant_types(); # macro defs
64 my $C_constant = join "\n",
65 C_constant ($package, undef, "IV", $types, undef, undef, @names);
66 my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant
68 ################ Header
69 my $header = catfile($dir, "test.h");
70 push @files, "test.h";
71 open FH, ">$header" or die "open >$header: $!\n";
83 close FH or die "close $header: $!\n";
86 my $xs = catfile($dir, "$package.xs");
87 push @files, "$package.xs";
88 open FH, ">$xs" or die "open >$xs: $!\n";
96 print FH "#include \"test.h\"\n\n";
97 print FH $constant_types;
98 print FH $C_constant, "\n";
99 print FH "MODULE = $package PACKAGE = $package\n";
100 print FH "PROTOTYPES: ENABLE\n";
101 print FH $XS_constant;
102 close FH or die "close $xs: $!\n";
105 my $pm = catfile($dir, "$package.pm");
106 push @files, "$package.pm";
107 open FH, ">$pm" or die "open >$pm: $!\n";
108 print FH "package $package;\n";
109 print FH "use $];\n";
119 use vars qw ($VERSION @ISA @EXPORT_OK);
122 @ISA = qw(Exporter DynaLoader);
126 print FH "\t$_\n" foreach (@names_only);
128 print FH autoload ($package, $]);
129 print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
130 close FH or die "close $pm: $!\n";
132 ################ test.pl
133 my $testpl = catfile($dir, "test.pl");
134 push @files, "test.pl";
135 open FH, ">$testpl" or die "open >$testpl: $!\n";
137 print FH "use strict;\n";
138 print FH "use $package qw(@names_only);\n";
146 print "not ok 5 # $five\n";
152 # PVN containing embedded \0s
158 my $farthing = FARTHING;
159 if ($farthing == 0.25) {
162 print "not ok 8 # $farthing\n";
166 my $not_zero = NOT_ZERO;
167 if ($not_zero > 0 && $not_zero == ~0) {
170 print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
173 # Value includes a "*/" in an attempt to bust out of a C comment.
174 # Also tests custom cpp #if clauses
176 if ($close eq '*/') {
179 print "not ok 10 # \$close='$close'\n";
182 # Default values if macro not defined.
187 print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n";
191 my $notdef = eval { NOTDEF; };
192 if (defined $notdef) {
193 print "not ok 12 # \$notdef='$notdef'\n";
194 } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
195 print "not ok 12 # \$@='$@'\n";
201 my $notthere = eval { &ExtTest::NOTTHERE; };
202 if (defined $notthere) {
203 print "not ok 13 # \$notthere='$notthere'\n";
204 } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
206 print "not ok 13 # \$@='$@'\n";
216 print "not ok 14 # $yes='\$yes'\n";
221 if (defined $no and !$no) {
224 print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
229 unless (defined $undef) {
232 print "not ok 16 # \$undef='$undef'\n";
237 close FH or die "close $testpl: $!\n";
239 ################ Makefile.PL
240 # We really need a Makefile.PL because make test for a no dynamic linking perl
241 # will run Makefile.PL again as part of the "make perl" target.
242 my $makefilePL = catfile($dir, "Makefile.PL");
243 push @files, "Makefile.PL";
244 open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
247 use ExtUtils::MakeMaker;
249 'NAME' => "$package",
250 'VERSION_FROM' => "$package.pm", # finds \$VERSION
252 (#ABSTRACT_FROM => "$package.pm", # XXX add this
253 AUTHOR => "$0") : ())
257 close FH or die "close $makefilePL: $!\n";
259 chdir $dir or die $!; push @INC, '../../lib';
260 END {chdir ".." or warn $!};
262 my @perlout = `$runperl Makefile.PL`;
264 print "not ok 1 # $runperl Makefile.PL failed: $?\n";
265 print "# $_" foreach @perlout;
272 my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
273 my $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
274 if (-f "$makefile$makefile_ext") {
279 my $makefile_rename = ($^O eq 'VMS' ? '.mms' : '.old');
280 push @files, "$makefile$makefile_rename"; # Renamed by make clean
282 my $make = $Config{make};
284 $make = $ENV{MAKE} if exists $ENV{MAKE};
288 print "# make = '$make'\n";
291 print "not ok 3 # $make failed: $?\n";
297 if ($Config{usedl}) {
300 push @files, "perl$Config{exe_ext}";
301 my $makeperl = "$make perl";
302 print "# make = '$makeperl'\n";
303 $makeout = `$makeperl`;
305 print "not ok 4 # $makeperl failed: $?\n";
313 my $maketest = "$make test";
314 print "# make = '$maketest'\n";
315 $makeout = `$maketest`;
317 # echo of running the test script
318 $makeout =~ s/^\s*PERL_DL_NONLAZY=.+?\n//m;
319 $makeout =~ s/^MCR.+test.pl\n//mig if $^O eq 'VMS';
322 $makeout =~ s/^\w*?make.+?(?:entering|leaving) directory.+?\n//mig;
324 # Hopefully gets most make's babblings
325 # make -f Makefile.aperl perl
326 $makeout =~ s/^\w*?make.+\sperl[^A-Za-z0-9]*\n//mig;
327 # make[1]: `perl' is up to date.
328 $makeout =~ s/^\w*?make.+perl.+?is up to date.*?\n//mig;
333 print "not ok $test # $maketest failed: $?\n";
339 my $regen = `$runperl $package.xs`;
341 print "not ok $test # $runperl $package.xs failed: $?\n";
347 my $expect = $constant_types . $C_constant .
348 "\n#### XS Section:\n" . $XS_constant;
350 if ($expect eq $regen) {
353 print "not ok $test\n";
354 # open FOO, ">expect"; print FOO $expect;
355 # open FOO, ">regen"; print FOO $regen; close FOO;
359 my $makeclean = "$make clean";
360 print "# make = '$makeclean'\n";
361 $makeout = `$makeclean`;
363 print "not ok $test # $make failed: $?\n";
370 unlink $_ or warn "unlink $_: $!";
374 opendir DIR, "." or die "opendir '.': $!";
375 while (defined (my $entry = readdir DIR)) {
376 next if $entry =~ /^\.\.?$/;
377 print "# Extra file '$entry'\n";
380 closedir DIR or warn "closedir '.': $!";
382 print "not ok $test\n";