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 # Test the code that generates 1 and 2 letter name comparisons.
47 N => 0, NE => 45, E => 90, SE => 135, S => 180, SW => 225, W => 270, NW => 315
50 my @names = ("FIVE", {name=>"OK6", type=>"PV",},
51 {name=>"OK7", type=>"PVN",
52 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
53 {name => "FARTHING", type=>"NV"},
54 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
55 {name => "OPEN", type=>"PV", value=>'"/*"',
56 macro=>["#if 1\n", "#endif\n"]},
57 {name => "CLOSE", type=>"PV", value=>'"*/"',
58 macro=>["#if 1\n", "#endif\n"]},
59 {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
60 {name => "Yes", type=>"YES"},
61 {name => "No", type=>"NO"},
62 {name => "Undef", type=>"UNDEF"},
65 push @names, $_ foreach keys %compass;
67 my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
70 my $constant_types = constant_types(); # macro defs
71 my $C_constant = join "\n",
72 C_constant ($package, undef, "IV", $types, undef, undef, @names);
73 my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant
75 ################ Header
76 my $header = catfile($dir, "test.h");
77 push @files, "test.h";
78 open FH, ">$header" or die "open >$header: $!\n";
93 while (my ($point, $bearing) = each %compass) {
94 print FH "#define $point $bearing\n"
96 close FH or die "close $header: $!\n";
99 my $xs = catfile($dir, "$package.xs");
100 push @files, "$package.xs";
101 open FH, ">$xs" or die "open >$xs: $!\n";
109 print FH "#include \"test.h\"\n\n";
110 print FH $constant_types;
111 print FH $C_constant, "\n";
112 print FH "MODULE = $package PACKAGE = $package\n";
113 print FH "PROTOTYPES: ENABLE\n";
114 print FH $XS_constant;
115 close FH or die "close $xs: $!\n";
118 my $pm = catfile($dir, "$package.pm");
119 push @files, "$package.pm";
120 open FH, ">$pm" or die "open >$pm: $!\n";
121 print FH "package $package;\n";
122 print FH "use $];\n";
132 use vars qw ($VERSION @ISA @EXPORT_OK);
135 @ISA = qw(Exporter DynaLoader);
139 print FH "\t$_\n" foreach (@names_only);
141 print FH autoload ($package, $]);
142 print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
143 close FH or die "close $pm: $!\n";
145 ################ test.pl
146 my $testpl = catfile($dir, "test.pl");
147 push @files, "test.pl";
148 open FH, ">$testpl" or die "open >$testpl: $!\n";
150 print FH "use strict;\n";
151 print FH "use $package qw(@names_only);\n";
159 print "not ok 5 # $five\n";
165 # PVN containing embedded \0s
171 my $farthing = FARTHING;
172 if ($farthing == 0.25) {
175 print "not ok 8 # $farthing\n";
179 my $not_zero = NOT_ZERO;
180 if ($not_zero > 0 && $not_zero == ~0) {
183 print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
186 # Value includes a "*/" in an attempt to bust out of a C comment.
187 # Also tests custom cpp #if clauses
189 if ($close eq '*/') {
192 print "not ok 10 # \$close='$close'\n";
195 # Default values if macro not defined.
200 print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n";
204 my $notdef = eval { NOTDEF; };
205 if (defined $notdef) {
206 print "not ok 12 # \$notdef='$notdef'\n";
207 } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
208 print "not ok 12 # \$@='$@'\n";
214 my $notthere = eval { &ExtTest::NOTTHERE; };
215 if (defined $notthere) {
216 print "not ok 13 # \$notthere='$notthere'\n";
217 } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
219 print "not ok 13 # \$@='$@'\n";
229 print "not ok 14 # $yes='\$yes'\n";
234 if (defined $no and !$no) {
237 print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
242 unless (defined $undef) {
245 print "not ok 16 # \$undef='$undef'\n";
249 # invalid macro (chosen to look like a mix up between No and SW)
250 $notdef = eval { &ExtTest::So };
251 if (defined $notdef) {
252 print "not ok 17 # \$notdef='$notdef'\n";
253 } elsif ($@ !~ /^So is not a valid ExtTest macro/) {
254 print "not ok 17 # \$@='$@'\n";
259 # invalid defined macro
260 $notdef = eval { &ExtTest::EW };
261 if (defined $notdef) {
262 print "not ok 18 # \$notdef='$notdef'\n";
263 } elsif ($@ !~ /^EW is not a valid ExtTest macro/) {
264 print "not ok 18 # \$@='$@'\n";
272 while (my ($point, $bearing) = each %compass) {
273 print FH "$point => $bearing, "
281 while (my ($point, $bearing) = each %compass) {
282 my $val = eval $point;
284 print "# $point: \$@='$@'\n";
286 } elsif (!defined $bearing) {
287 print "# $point: \$val=undef\n";
289 } elsif ($val != $bearing) {
290 print "# $point: \$val=$val, not $bearing\n";
302 close FH or die "close $testpl: $!\n";
304 ################ Makefile.PL
305 # We really need a Makefile.PL because make test for a no dynamic linking perl
306 # will run Makefile.PL again as part of the "make perl" target.
307 my $makefilePL = catfile($dir, "Makefile.PL");
308 push @files, "Makefile.PL";
309 open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
312 use ExtUtils::MakeMaker;
314 'NAME' => "$package",
315 'VERSION_FROM' => "$package.pm", # finds \$VERSION
317 (#ABSTRACT_FROM => "$package.pm", # XXX add this
318 AUTHOR => "$0") : ())
322 close FH or die "close $makefilePL: $!\n";
324 chdir $dir or die $!; push @INC, '../../lib';
325 END {chdir ".." or warn $!};
327 my @perlout = `$runperl Makefile.PL`;
329 print "not ok 1 # $runperl Makefile.PL failed: $?\n";
330 print "# $_" foreach @perlout;
337 my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
338 my $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
339 if (-f "$makefile$makefile_ext") {
344 my $makefile_rename = ($^O eq 'VMS' ? '.mms' : '.old');
345 push @files, "$makefile$makefile_rename"; # Renamed by make clean
347 my $make = $Config{make};
349 $make = $ENV{MAKE} if exists $ENV{MAKE};
353 print "# make = '$make'\n";
356 print "not ok 3 # $make failed: $?\n";
362 if ($Config{usedl}) {
365 push @files, "perl$Config{exe_ext}";
366 my $makeperl = "$make perl";
367 print "# make = '$makeperl'\n";
368 $makeout = `$makeperl`;
370 print "not ok 4 # $makeperl failed: $?\n";
378 my $maketest = "$make test";
379 print "# make = '$maketest'\n";
380 $makeout = `$maketest`;
382 # echo of running the test script
383 $makeout =~ s/^\s*PERL_DL_NONLAZY=.+?\n//m;
384 $makeout =~ s/^MCR.+test.pl\n//mig if $^O eq 'VMS';
387 $makeout =~ s/^\w*?make.+?(?:entering|leaving) directory.+?\n//mig;
389 # Hopefully gets most make's babblings
390 # make -f Makefile.aperl perl
391 $makeout =~ s/^\w*?make.+\sperl[^A-Za-z0-9]*\n//mig;
392 # make[1]: `perl' is up to date.
393 $makeout =~ s/^\w*?make.+perl.+?is up to date.*?\n//mig;
398 print "not ok $test # $maketest failed: $?\n";
404 my $regen = `$runperl $package.xs`;
406 print "not ok $test # $runperl $package.xs failed: $?\n";
412 my $expect = $constant_types . $C_constant .
413 "\n#### XS Section:\n" . $XS_constant;
415 if ($expect eq $regen) {
418 print "not ok $test\n";
419 # open FOO, ">expect"; print FOO $expect;
420 # open FOO, ">regen"; print FOO $regen; close FOO;
424 my $makeclean = "$make clean";
425 print "# make = '$makeclean'\n";
426 $makeout = `$makeclean`;
428 print "not ok $test # $make failed: $?\n";
435 unlink $_ or warn "unlink $_: $!";
439 opendir DIR, "." or die "opendir '.': $!";
440 while (defined (my $entry = readdir DIR)) {
441 next if $entry =~ /^\.\.?$/;
442 print "# Extra file '$entry'\n";
445 closedir DIR or warn "closedir '.': $!";
447 print "not ok $test\n";