12 use ExtUtils::MakeMaker;
13 use ExtUtils::Constant qw (constant_types C_constant XS_constant autoload);
15 use File::Spec::Functions qw(catfile rel2abs);
16 # Because were are going to be changing directory before running Makefile.PL
18 $perl = rel2abs( $^X ) unless $] < 5.006; # Hack. Until 5.00503 has rel2abs
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";
36 my $output = "output";
40 print "# $dir being removed...\n";
44 my $package = "ExtTest";
46 # Test the code that generates 1 and 2 letter name comparisons.
48 N => 0, 'NE' => 45, E => 90, SE => 135, S => 180, SW => 225, W => 270, NW => 315
52 'A Standard for the Transmission of IP Datagrams on Avian Carriers';
54 my @names = ("FIVE", {name=>"OK6", type=>"PV",},
55 {name=>"OK7", type=>"PVN",
56 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
57 {name => "FARTHING", type=>"NV"},
58 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
59 {name => "OPEN", type=>"PV", value=>'"/*"', macro=>1},
60 {name => "CLOSE", type=>"PV", value=>'"*/"',
61 macro=>["#if 1\n", "#endif\n"]},
62 {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
63 {name => "Yes", type=>"YES"},
64 {name => "No", type=>"NO"},
65 {name => "Undef", type=>"UNDEF"},
66 # OK. It wasn't really designed to allow the creation of dual valued constants.
67 # It was more for INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
68 {name=>"RFC1149", type=>"SV", value=>"sv_2mortal(temp_sv)",
69 pre=>"SV *temp_sv = newSVpv(RFC1149, 0); "
70 . "(void) SvUPGRADE(temp_sv,SVt_PVIV); SvIOK_on(temp_sv); "
71 . "SvIVX(temp_sv) = 1149;"},
74 push @names, $_ foreach keys %compass;
76 my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
79 my $constant_types = constant_types(); # macro defs
80 my $C_constant = join "\n",
81 C_constant ($package, undef, "IV", $types, undef, undef, @names);
82 my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant
84 ################ Header
85 my $header = catfile($dir, "test.h");
86 push @files, "test.h";
87 open FH, ">$header" or die "open >$header: $!\n";
97 #define RFC1149 "$parent_rfc1149"
102 while (my ($point, $bearing) = each %compass) {
103 print FH "#define $point $bearing\n"
105 close FH or die "close $header: $!\n";
108 my $xs = catfile($dir, "$package.xs");
109 push @files, "$package.xs";
110 open FH, ">$xs" or die "open >$xs: $!\n";
118 print FH "#include \"test.h\"\n\n";
119 print FH $constant_types;
120 print FH $C_constant, "\n";
121 print FH "MODULE = $package PACKAGE = $package\n";
122 print FH "PROTOTYPES: ENABLE\n";
123 print FH $XS_constant;
124 close FH or die "close $xs: $!\n";
127 my $pm = catfile($dir, "$package.pm");
128 push @files, "$package.pm";
129 open FH, ">$pm" or die "open >$pm: $!\n";
130 print FH "package $package;\n";
131 print FH "use $];\n";
137 printf FH "use warnings;\n" unless $] < 5.006;
143 use vars qw ($VERSION @ISA @EXPORT_OK $AUTOLOAD);
146 @ISA = qw(Exporter DynaLoader);
150 print FH "\t$_\n" foreach (@names_only);
152 print FH autoload ($package, $]);
153 print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
154 close FH or die "close $pm: $!\n";
156 ################ test.pl
157 my $testpl = catfile($dir, "test.pl");
158 push @files, "test.pl";
159 open FH, ">$testpl" or die "open >$testpl: $!\n";
161 print FH "use strict;\n";
162 print FH "use $package qw(@names_only);\n";
166 if (open OUTPUT, ">$output") {
170 print "not ok 1 # Failed to open '$output': $!\n";
177 # What follows goes to the temporary file.
183 print "not ok 5 # $five\n";
189 # PVN containing embedded \0s
195 my $farthing = FARTHING;
196 if ($farthing == 0.25) {
199 print "not ok 8 # $farthing\n";
203 my $not_zero = NOT_ZERO;
204 if ($not_zero > 0 && $not_zero == ~0) {
207 print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
210 # Value includes a "*/" in an attempt to bust out of a C comment.
211 # Also tests custom cpp #if clauses
213 if ($close eq '*/') {
216 print "not ok 10 # \$close='$close'\n";
219 # Default values if macro not defined.
224 print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n";
228 my $notdef = eval { NOTDEF; };
229 if (defined $notdef) {
230 print "not ok 12 # \$notdef='$notdef'\n";
231 } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
232 print "not ok 12 # \$@='$@'\n";
238 my $notthere = eval { &ExtTest::NOTTHERE; };
239 if (defined $notthere) {
240 print "not ok 13 # \$notthere='$notthere'\n";
241 } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
243 print "not ok 13 # \$@='$@'\n";
253 print "not ok 14 # $yes='\$yes'\n";
258 if (defined $no and !$no) {
261 print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
266 unless (defined $undef) {
269 print "not ok 16 # \$undef='$undef'\n";
273 # invalid macro (chosen to look like a mix up between No and SW)
274 $notdef = eval { &ExtTest::So };
275 if (defined $notdef) {
276 print "not ok 17 # \$notdef='$notdef'\n";
277 } elsif ($@ !~ /^So is not a valid ExtTest macro/) {
278 print "not ok 17 # \$@='$@'\n";
283 # invalid defined macro
284 $notdef = eval { &ExtTest::EW };
285 if (defined $notdef) {
286 print "not ok 18 # \$notdef='$notdef'\n";
287 } elsif ($@ !~ /^EW is not a valid ExtTest macro/) {
288 print "not ok 18 # \$@='$@'\n";
296 while (my ($point, $bearing) = each %compass) {
297 print FH "'$point' => $bearing, "
305 while (my ($point, $bearing) = each %compass) {
306 my $val = eval $point;
308 print "# $point: \$@='$@'\n";
310 } elsif (!defined $bearing) {
311 print "# $point: \$val=undef\n";
313 } elsif ($val != $bearing) {
314 print "# $point: \$val=$val, not $bearing\n";
327 my \$rfc1149 = RFC1149;
328 if (\$rfc1149 ne "$parent_rfc1149") {
329 print "not ok 20 # '\$rfc1149' ne '$parent_rfc1149'\n";
334 if (\$rfc1149 != 1149) {
335 printf "not ok 21 # %d != 1149\n", \$rfc1149;
348 print "not ok 22 # \$open='$open'\n";
351 close FH or die "close $testpl: $!\n";
353 ################ Makefile.PL
354 # We really need a Makefile.PL because make test for a no dynamic linking perl
355 # will run Makefile.PL again as part of the "make perl" target.
356 my $makefilePL = catfile($dir, "Makefile.PL");
357 push @files, "Makefile.PL";
358 open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
361 use ExtUtils::MakeMaker;
363 'NAME' => "$package",
364 'VERSION_FROM' => "$package.pm", # finds \$VERSION
366 (#ABSTRACT_FROM => "$package.pm", # XXX add this
367 AUTHOR => "$0") : ())
371 close FH or die "close $makefilePL: $!\n";
373 chdir $dir or die $!; push @INC, '../../lib';
374 END {chdir ".." or warn $!};
376 my @perlout = `$runperl Makefile.PL PERL_CORE=1`;
378 print "not ok 1 # $runperl Makefile.PL failed: $?\n";
379 print "# $_" foreach @perlout;
386 my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
387 my $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
388 if (-f "$makefile$makefile_ext") {
393 my $makefile_rename = ($^O eq 'VMS' ? '.mms' : '.old');
394 push @files, "$makefile$makefile_rename"; # Renamed by make clean
396 my $make = $Config{make};
398 $make = $ENV{MAKE} if exists $ENV{MAKE};
400 if ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; }
404 print "# make = '$make'\n";
407 print "not ok 3 # $make failed: $?\n";
408 print "# $_" foreach @makeout;
414 if ($Config{usedl}) {
417 my $makeperl = "$make perl";
418 print "# make = '$makeperl'\n";
419 @makeout = `$makeperl`;
421 print "not ok 4 # $makeperl failed: $?\n";
422 print "# $_" foreach @makeout;
429 push @files, $output;
431 my $maketest = "$make test";
432 print "# make = '$maketest'\n";
434 @makeout = `$maketest`;
436 if (open OUTPUT, "<$output") {
437 print while <OUTPUT>;
438 close OUTPUT or print "# Close $output failed: $!\n";
440 # Harness will report missing test results at this point.
441 print "# Open <$output failed: $!\n";
447 print "not ok $test # $maketest failed: $?\n";
448 print "# $_" foreach @makeout;
454 my $regen = `$runperl $package.xs`;
456 print "not ok $test # $runperl $package.xs failed: $?\n";
462 my $expect = $constant_types . $C_constant .
463 "\n#### XS Section:\n" . $XS_constant;
465 if ($expect eq $regen) {
468 print "not ok $test\n";
469 # open FOO, ">expect"; print FOO $expect;
470 # open FOO, ">regen"; print FOO $regen; close FOO;
474 my $makeclean = "$make clean";
475 print "# make = '$makeclean'\n";
476 @makeout = `$makeclean`;
478 print "not ok $test # $make failed: $?\n";
479 print "# $_" foreach @makeout;
486 unlink $_ or warn "unlink $_: $!";
490 opendir DIR, "." or die "opendir '.': $!";
491 while (defined (my $entry = readdir DIR)) {
492 next if $entry =~ /^\.\.?$/;
493 print "# Extra file '$entry'\n";
496 closedir DIR or warn "closedir '.': $!";
498 print "not ok $test\n";