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
51 'A Standard for the Transmission of IP Datagrams on Avian Carriers';
53 my @names = ("FIVE", {name=>"OK6", type=>"PV",},
54 {name=>"OK7", type=>"PVN",
55 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
56 {name => "FARTHING", type=>"NV"},
57 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
58 {name => "OPEN", type=>"PV", value=>'"/*"', macro=>1},
59 {name => "CLOSE", type=>"PV", value=>'"*/"',
60 macro=>["#if 1\n", "#endif\n"]},
61 {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
62 {name => "Yes", type=>"YES"},
63 {name => "No", type=>"NO"},
64 {name => "Undef", type=>"UNDEF"},
65 # OK. It wasn't really designed to allow the creation of dual valued constants.
66 # It was more for INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
67 {name=>"RFC1149", type=>"SV", value=>"sv_2mortal(temp_sv)",
68 pre=>"SV *temp_sv = newSVpv(RFC1149, 0); "
69 . "(void) SvUPGRADE(temp_sv,SVt_PVIV); SvIOK_on(temp_sv); "
70 . "SvIVX(temp_sv) = 1149;"},
73 push @names, $_ foreach keys %compass;
75 my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
78 my $constant_types = constant_types(); # macro defs
79 my $C_constant = join "\n",
80 C_constant ($package, undef, "IV", $types, undef, undef, @names);
81 my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant
83 ################ Header
84 my $header = catfile($dir, "test.h");
85 push @files, "test.h";
86 open FH, ">$header" or die "open >$header: $!\n";
96 #define RFC1149 "$parent_rfc1149"
101 while (my ($point, $bearing) = each %compass) {
102 print FH "#define $point $bearing\n"
104 close FH or die "close $header: $!\n";
107 my $xs = catfile($dir, "$package.xs");
108 push @files, "$package.xs";
109 open FH, ">$xs" or die "open >$xs: $!\n";
117 print FH "#include \"test.h\"\n\n";
118 print FH $constant_types;
119 print FH $C_constant, "\n";
120 print FH "MODULE = $package PACKAGE = $package\n";
121 print FH "PROTOTYPES: ENABLE\n";
122 print FH $XS_constant;
123 close FH or die "close $xs: $!\n";
126 my $pm = catfile($dir, "$package.pm");
127 push @files, "$package.pm";
128 open FH, ">$pm" or die "open >$pm: $!\n";
129 print FH "package $package;\n";
130 print FH "use $];\n";
140 use vars qw ($VERSION @ISA @EXPORT_OK);
143 @ISA = qw(Exporter DynaLoader);
147 print FH "\t$_\n" foreach (@names_only);
149 print FH autoload ($package, $]);
150 print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
151 close FH or die "close $pm: $!\n";
153 ################ test.pl
154 my $testpl = catfile($dir, "test.pl");
155 push @files, "test.pl";
156 open FH, ">$testpl" or die "open >$testpl: $!\n";
158 print FH "use strict;\n";
159 print FH "use $package qw(@names_only);\n";
167 print "not ok 5 # $five\n";
173 # PVN containing embedded \0s
179 my $farthing = FARTHING;
180 if ($farthing == 0.25) {
183 print "not ok 8 # $farthing\n";
187 my $not_zero = NOT_ZERO;
188 if ($not_zero > 0 && $not_zero == ~0) {
191 print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
194 # Value includes a "*/" in an attempt to bust out of a C comment.
195 # Also tests custom cpp #if clauses
197 if ($close eq '*/') {
200 print "not ok 10 # \$close='$close'\n";
203 # Default values if macro not defined.
208 print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n";
212 my $notdef = eval { NOTDEF; };
213 if (defined $notdef) {
214 print "not ok 12 # \$notdef='$notdef'\n";
215 } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
216 print "not ok 12 # \$@='$@'\n";
222 my $notthere = eval { &ExtTest::NOTTHERE; };
223 if (defined $notthere) {
224 print "not ok 13 # \$notthere='$notthere'\n";
225 } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
227 print "not ok 13 # \$@='$@'\n";
237 print "not ok 14 # $yes='\$yes'\n";
242 if (defined $no and !$no) {
245 print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
250 unless (defined $undef) {
253 print "not ok 16 # \$undef='$undef'\n";
257 # invalid macro (chosen to look like a mix up between No and SW)
258 $notdef = eval { &ExtTest::So };
259 if (defined $notdef) {
260 print "not ok 17 # \$notdef='$notdef'\n";
261 } elsif ($@ !~ /^So is not a valid ExtTest macro/) {
262 print "not ok 17 # \$@='$@'\n";
267 # invalid defined macro
268 $notdef = eval { &ExtTest::EW };
269 if (defined $notdef) {
270 print "not ok 18 # \$notdef='$notdef'\n";
271 } elsif ($@ !~ /^EW is not a valid ExtTest macro/) {
272 print "not ok 18 # \$@='$@'\n";
280 while (my ($point, $bearing) = each %compass) {
281 print FH "$point => $bearing, "
289 while (my ($point, $bearing) = each %compass) {
290 my $val = eval $point;
292 print "# $point: \$@='$@'\n";
294 } elsif (!defined $bearing) {
295 print "# $point: \$val=undef\n";
297 } elsif ($val != $bearing) {
298 print "# $point: \$val=$val, not $bearing\n";
311 my \$rfc1149 = RFC1149;
312 if (\$rfc1149 ne "$parent_rfc1149") {
313 print "not ok 20 # '\$rfc1149' ne '$parent_rfc1149'\n";
318 if (\$rfc1149 != 1149) {
319 printf "not ok 21 # %d != 1149\n", \$rfc1149;
332 print "not ok 22 # \$open='$open'\n";
335 close FH or die "close $testpl: $!\n";
337 ################ Makefile.PL
338 # We really need a Makefile.PL because make test for a no dynamic linking perl
339 # will run Makefile.PL again as part of the "make perl" target.
340 my $makefilePL = catfile($dir, "Makefile.PL");
341 push @files, "Makefile.PL";
342 open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
345 use ExtUtils::MakeMaker;
347 'NAME' => "$package",
348 'VERSION_FROM' => "$package.pm", # finds \$VERSION
350 (#ABSTRACT_FROM => "$package.pm", # XXX add this
351 AUTHOR => "$0") : ())
355 close FH or die "close $makefilePL: $!\n";
357 chdir $dir or die $!; push @INC, '../../lib';
358 END {chdir ".." or warn $!};
360 my @perlout = `$runperl Makefile.PL`;
362 print "not ok 1 # $runperl Makefile.PL failed: $?\n";
363 print "# $_" foreach @perlout;
370 my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
371 my $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
372 if (-f "$makefile$makefile_ext") {
377 my $makefile_rename = ($^O eq 'VMS' ? '.mms' : '.old');
378 push @files, "$makefile$makefile_rename"; # Renamed by make clean
380 my $make = $Config{make};
382 $make = $ENV{MAKE} if exists $ENV{MAKE};
384 if ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; }
388 print "# make = '$make'\n";
391 print "not ok 3 # $make failed: $?\n";
397 if ($Config{usedl}) {
400 my $makeperl = "$make perl";
401 print "# make = '$makeperl'\n";
402 $makeout = `$makeperl`;
404 print "not ok 4 # $makeperl failed: $?\n";
412 my $maketest = "$make test";
413 print "# make = '$maketest'\n";
414 $makeout = `$maketest`;
416 # echo of running the test script
417 $makeout =~ s/^\s*PERL_DL_NONLAZY=.+?\n//m;
418 $makeout =~ s/^MCR.+test.pl\n//mig if $^O eq 'VMS';
421 $makeout =~ s/^\w*?make.+?(?:entering|leaving) directory.+?\n//mig;
423 # Hopefully gets most make's babblings
424 # make -f Makefile.aperl perl
425 $makeout =~ s/^\w*?make.+\sperl[^A-Za-z0-9]*\n//mig;
426 # make[1]: `perl' is up to date.
427 $makeout =~ s/^\w*?make.+perl.+?is up to date.*?\n//mig;
432 print "not ok $test # $maketest failed: $?\n";
438 my $regen = `$runperl $package.xs`;
440 print "not ok $test # $runperl $package.xs failed: $?\n";
446 my $expect = $constant_types . $C_constant .
447 "\n#### XS Section:\n" . $XS_constant;
449 if ($expect eq $regen) {
452 print "not ok $test\n";
453 # open FOO, ">expect"; print FOO $expect;
454 # open FOO, ">regen"; print FOO $regen; close FOO;
458 my $makeclean = "$make clean";
459 print "# make = '$makeclean'\n";
460 $makeout = `$makeclean`;
462 print "not ok $test # $make failed: $?\n";
469 unlink $_ or warn "unlink $_: $!";
473 opendir DIR, "." or die "opendir '.': $!";
474 while (defined (my $entry = readdir DIR)) {
475 next if $entry =~ /^\.\.?$/;
476 print "# Extra file '$entry'\n";
479 closedir DIR or warn "closedir '.': $!";
481 print "not ok $test\n";