4 if( $ENV{PERL_CORE} ) {
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 \"-I../../lib\"";
33 print "# $dir being created...\n";
34 mkdir $dir, 0777 or die "mkdir: $!\n";
36 my $output = "output";
38 # For debugging set this to 1.
43 print "# $dir being removed...\n";
44 rmtree($dir) unless $keep_files;
47 my $package = "ExtTest";
49 # Test the code that generates 1 and 2 letter name comparisons.
51 N => 0, 'NE' => 45, E => 90, SE => 135, S => 180, SW => 225, W => 270, NW => 315
55 'A Standard for the Transmission of IP Datagrams on Avian Carriers';
56 # Check that 8 bit and unicode names don't cause problems.
57 my $pound = chr 163; # A pound sign. (Currency)
59 # Check that we can distiguish the pathological case of a string, and the
60 # utf8 representation of that string.
61 my $pound_bytes = my $pound_utf8 = $pound . '1';
62 utf8::encode ($pound_bytes);
64 my @names = ("FIVE", {name=>"OK6", type=>"PV",},
65 {name=>"OK7", type=>"PVN",
66 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
67 {name => "FARTHING", type=>"NV"},
68 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
69 {name => "OPEN", type=>"PV", value=>'"/*"', macro=>1},
70 {name => "CLOSE", type=>"PV", value=>'"*/"',
71 macro=>["#if 1\n", "#endif\n"]},
72 {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
73 {name => "Yes", type=>"YES"},
74 {name => "No", type=>"NO"},
75 {name => "Undef", type=>"UNDEF"},
76 # OK. It wasn't really designed to allow the creation of dual valued constants.
77 # It was more for INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
78 {name=>"RFC1149", type=>"SV", value=>"sv_2mortal(temp_sv)",
79 pre=>"SV *temp_sv = newSVpv(RFC1149, 0); "
80 . "(void) SvUPGRADE(temp_sv,SVt_PVIV); SvIOK_on(temp_sv); "
81 . "SvIVX(temp_sv) = 1149;"},
82 {name=>"perl", type=>"PV",},
85 push @names, $_ foreach keys %compass;
87 # Automatically compile the list of all the macro names, and make them
89 my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
91 # Exporter::Heavy (currently) isn't able to export these names:
92 push @names, ({name=>"*/", type=>"PV", value=>'"CLOSE"', macro=>1},
93 {name=>"/*", type=>"PV", value=>'"OPEN"', macro=>1},
94 {name=>$pound, type=>"PV", value=>'"Sterling"', macro=>1},
95 {name=>$inf, type=>"PV", value=>'"Infinity"', macro=>1},
96 {name=>$pound_utf8, type=>"PV", value=>'"1 Pound"', macro=>1},
97 {name=>$pound_bytes, type=>"PV", value=>'"1 Pound (as bytes)"',
103 The above set of names seems to produce a suitably bad set of compile
104 problems on a Unicode naive version of ExtUtils::Constant (ie 0.11):
106 nick@thinking-cap 15439-32-utf$ PERL_CORE=1 ./perl lib/ExtUtils/t/Constant.t
108 # perl=/stuff/perl5/15439-32-utf/perl
109 # ext-30370 being created...
110 Wide character in print at lib/ExtUtils/t/Constant.t line 140.
114 ExtTest.xs: In function `constant_1':
115 ExtTest.xs:80: warning: multi-character character constant
116 ExtTest.xs:80: warning: case value out of range
122 my $constant_types = constant_types(); # macro defs
123 my $C_constant = join "\n",
124 C_constant ($package, undef, "IV", $types, undef, undef, @names);
125 my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant
127 ################ Header
128 my $header = catfile($dir, "test.h");
129 push @files, "test.h";
130 open FH, ">$header" or die "open >$header: $!\n";
133 #define OK6 "ok 6\\n"
135 #define FARTHING 0.25
140 #define RFC1149 "$parent_rfc1149"
145 while (my ($point, $bearing) = each %compass) {
146 print FH "#define $point $bearing\n"
148 close FH or die "close $header: $!\n";
151 my $xs = catfile($dir, "$package.xs");
152 push @files, "$package.xs";
153 open FH, ">$xs" or die "open >$xs: $!\n";
161 print FH "#include \"test.h\"\n\n";
162 print FH $constant_types;
163 print FH $C_constant, "\n";
164 print FH "MODULE = $package PACKAGE = $package\n";
165 print FH "PROTOTYPES: ENABLE\n";
166 print FH $XS_constant;
167 close FH or die "close $xs: $!\n";
170 my $pm = catfile($dir, "$package.pm");
171 push @files, "$package.pm";
172 open FH, ">$pm" or die "open >$pm: $!\n";
173 print FH "package $package;\n";
174 print FH "use $];\n";
180 printf FH "use warnings;\n" unless $] < 5.006;
186 use vars qw ($VERSION @ISA @EXPORT_OK $AUTOLOAD);
189 @ISA = qw(Exporter DynaLoader);
193 # Print the names of all our autoloaded constants
194 print FH "\t$_\n" foreach (@names_only);
196 # Print the AUTOLOAD subroutine ExtUtils::Constant generated for us
197 print FH autoload ($package, $]);
198 print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
199 close FH or die "close $pm: $!\n";
201 ################ test.pl
202 my $testpl = catfile($dir, "test.pl");
203 push @files, "test.pl";
204 open FH, ">$testpl" or die "open >$testpl: $!\n";
206 print FH "use strict;\n";
207 print FH "use $package qw(@names_only);\n";
213 if (open OUTPUT, ">$output") {
217 print "not ok 1 # Failed to open '$output': $!\n";
224 # What follows goes to the temporary file.
230 print "not ok 5 # $five\n";
236 # PVN containing embedded \0s
242 my $farthing = FARTHING;
243 if ($farthing == 0.25) {
246 print "not ok 8 # $farthing\n";
250 my $not_zero = NOT_ZERO;
251 if ($not_zero > 0 && $not_zero == ~0) {
254 print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
257 # Value includes a "*/" in an attempt to bust out of a C comment.
258 # Also tests custom cpp #if clauses
260 if ($close eq '*/') {
263 print "not ok 10 # \$close='$close'\n";
266 # Default values if macro not defined.
271 print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n";
275 my $notdef = eval { NOTDEF; };
276 if (defined $notdef) {
277 print "not ok 12 # \$notdef='$notdef'\n";
278 } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
279 print "not ok 12 # \$@='$@'\n";
285 my $notthere = eval { &ExtTest::NOTTHERE; };
286 if (defined $notthere) {
287 print "not ok 13 # \$notthere='$notthere'\n";
288 } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
290 print "not ok 13 # \$@='$@'\n";
300 print "not ok 14 # $yes='\$yes'\n";
305 if (defined $no and !$no) {
308 print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
313 unless (defined $undef) {
316 print "not ok 16 # \$undef='$undef'\n";
320 # invalid macro (chosen to look like a mix up between No and SW)
321 $notdef = eval { &ExtTest::So };
322 if (defined $notdef) {
323 print "not ok 17 # \$notdef='$notdef'\n";
324 } elsif ($@ !~ /^So is not a valid ExtTest macro/) {
325 print "not ok 17 # \$@='$@'\n";
330 # invalid defined macro
331 $notdef = eval { &ExtTest::EW };
332 if (defined $notdef) {
333 print "not ok 18 # \$notdef='$notdef'\n";
334 } elsif ($@ !~ /^EW is not a valid ExtTest macro/) {
335 print "not ok 18 # \$@='$@'\n";
343 while (my ($point, $bearing) = each %compass) {
344 print FH "'$point' => $bearing, "
352 while (my ($point, $bearing) = each %compass) {
353 my $val = eval $point;
355 print "# $point: \$@='$@'\n";
357 } elsif (!defined $bearing) {
358 print "# $point: \$val=undef\n";
360 } elsif ($val != $bearing) {
361 print "# $point: \$val=$val, not $bearing\n";
374 my \$rfc1149 = RFC1149;
375 if (\$rfc1149 ne "$parent_rfc1149") {
376 print "not ok 20 # '\$rfc1149' ne '$parent_rfc1149'\n";
381 if (\$rfc1149 != 1149) {
382 printf "not ok 21 # %d != 1149\n", \$rfc1149;
395 print "not ok 22 # \$open='$open'\n";
399 # Do this in 7 bit in case someone is testing with some settings that cause
400 # 8 bit files incapable of storing this character.
402 = map {"'" . join (",", unpack "U*", $_) . "'"}
403 ($pound, $inf, $pound_bytes, $pound_utf8);
404 # Values is a list of strings, such as ('194,163,49', '163,49')
408 # I can see that this child test program might be about to use parts of
412 my ($pound, $inf, $pound_bytes, $pound_utf8) = map {eval "pack 'U*', $_"}
415 print FH join ",", @values;
420 foreach (["perl", "rules", "rules"],
421 ["/*", "OPEN", "OPEN"],
422 ["*/", "CLOSE", "CLOSE"],
423 [$pound, 'Sterling', []],
424 [$inf, 'Infinity', []],
425 [$pound_utf8, '1 Pound', '1 Pound (as bytes)'],
426 [$pound_bytes, '1 Pound (as bytes)', []],
428 # Flag an expected error with a reference for the expect string.
429 my ($string, $expect, $expect_bytes) = @$_;
430 (my $name = $string) =~ s/([^ -~])/sprintf '\x{%X}', ord $1/ges;
431 print "# \"$name\" => \'$expect\'\n";
432 # Try to force this to be bytes if possible.
433 utf8::downgrade ($string, 1);
436 print FH "my (\$error, \$got) = ${package}::constant (\$string);\n";
439 if ($error or $got ne $expect) {
440 print "not ok $test # error '$error', got '$got'\n";
445 print "# Now upgrade '$name' to utf8\n";
446 utf8::upgrade ($string);
449 print FH "my (\$error, \$got) = ${package}::constant (\$string);\n";
452 if ($error or $got ne $expect) {
453 print "not ok $test # error '$error', got '$got'\n";
458 if (defined $expect_bytes) {
459 print "# And now with the utf8 byte sequence for name\n";
460 # Try the encoded bytes.
461 utf8::encode ($string);
464 print FH "my (\$error, \$got) = ${package}::constant (\$string);\n";
467 if (ref $expect_bytes) {
470 print "ok $test # error='$error' (as expected)\n";
472 print "not ok $test # expected error, got no error and '$got'\n";
474 } elsif ($got ne $expect_bytes) {
475 print "not ok $test # error '$error', expect '$expect_bytes', got '$got'\n";
484 close FH or die "close $testpl: $!\n";
486 # This is where the test numbers carry on after the test number above are
490 ################ Makefile.PL
491 # We really need a Makefile.PL because make test for a no dynamic linking perl
492 # will run Makefile.PL again as part of the "make perl" target.
493 my $makefilePL = catfile($dir, "Makefile.PL");
494 push @files, "Makefile.PL";
495 open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
498 use ExtUtils::MakeMaker;
500 'NAME' => "$package",
501 'VERSION_FROM' => "$package.pm", # finds \$VERSION
503 (#ABSTRACT_FROM => "$package.pm", # XXX add this
504 AUTHOR => "$0") : ())
508 close FH or die "close $makefilePL: $!\n";
510 chdir $dir or die $!; push @INC, '../../lib';
511 END {chdir ".." or warn $!};
513 my @perlout = `$runperl Makefile.PL PERL_CORE=1`;
515 print "not ok 1 # $runperl Makefile.PL failed: $?\n";
516 print "# $_" foreach @perlout;
523 my $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
524 my $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
525 if (-f "$makefile$makefile_ext") {
530 my $makefile_rename = ($^O eq 'VMS' ? '.mms' : '.old');
531 push @files, "$makefile$makefile_rename"; # Renamed by make clean
533 my $make = $Config{make};
535 $make = $ENV{MAKE} if exists $ENV{MAKE};
537 if ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; }
541 if ($^O eq 'VMS') { $make .= ' all'; }
542 print "# make = '$make'\n";
545 print "not ok 3 # $make failed: $?\n";
546 print "# $_" foreach @makeout;
552 if ($^O eq 'VMS') { $make =~ s{ all}{}; }
554 if ($Config{usedl}) {
557 my $makeperl = "$make perl";
558 print "# make = '$makeperl'\n";
559 @makeout = `$makeperl`;
561 print "not ok 4 # $makeperl failed: $?\n";
562 print "# $_" foreach @makeout;
569 push @files, $output;
571 my $maketest = "$make test";
572 print "# make = '$maketest'\n";
574 @makeout = `$maketest`;
576 if (open OUTPUT, "<$output") {
577 print while <OUTPUT>;
578 close OUTPUT or print "# Close $output failed: $!\n";
580 # Harness will report missing test results at this point.
581 print "# Open <$output failed: $!\n";
585 print "not ok $test # $maketest failed: $?\n";
586 print "# $_" foreach @makeout;
588 print "ok $test - maketest\n";
593 # -x is busted on Win32 < 5.6.1, so we emulate it.
595 if( $^O eq 'MSWin32' && $] <= 5.006001 ) {
596 open(REGENTMP, ">regentmp") or die $!;
597 open(XS, "$package.xs") or die $!;
600 $saw_shebang++ if /^#!.*/i ;
601 print REGENTMP $_ if $saw_shebang;
603 close XS; close REGENTMP;
604 $regen = `$runperl regentmp`;
608 $regen = `$runperl -x $package.xs`;
611 print "not ok $test # $runperl -x $package.xs failed: $?\n";
613 print "ok $test - regen\n";
617 my $expect = $constant_types . $C_constant .
618 "\n#### XS Section:\n" . $XS_constant;
620 if ($expect eq $regen) {
621 print "ok $test - regen worked\n";
623 print "not ok $test - regen worked\n";
624 # open FOO, ">expect"; print FOO $expect;
625 # open FOO, ">regen"; print FOO $regen; close FOO;
629 my $makeclean = "$make clean";
630 print "# make = '$makeclean'\n";
631 @makeout = `$makeclean`;
633 print "not ok $test # $make failed: $?\n";
634 print "# $_" foreach @makeout;
640 unless ($keep_files) {
642 unlink $_ or warn "unlink $_: $!";
647 opendir DIR, "." or die "opendir '.': $!";
648 while (defined (my $entry = readdir DIR)) {
649 next if $entry =~ /^\.\.?$/;
650 print "# Extra file '$entry'\n";
653 closedir DIR or warn "closedir '.': $!";
655 print "not ok $test\n";