1N/A#!/usr/bin/perl -w
1N/A
1N/ABEGIN {
1N/A if( $ENV{PERL_CORE} ) {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A }
1N/A use Config;
1N/A unless ($Config{usedl}) {
1N/A print "1..0 # no usedl, skipping\n";
1N/A exit 0;
1N/A }
1N/A}
1N/A
1N/A# use warnings;
1N/Ause strict;
1N/Ause ExtUtils::MakeMaker;
1N/Ause ExtUtils::Constant qw (constant_types C_constant XS_constant autoload);
1N/Ause File::Spec;
1N/Ause Cwd;
1N/A
1N/Amy $do_utf_tests = $] > 5.006;
1N/Amy $better_than_56 = $] > 5.007;
1N/A# For debugging set this to 1.
1N/Amy $keep_files = 0;
1N/A$| = 1;
1N/A
1N/A# Because were are going to be changing directory before running Makefile.PL
1N/Amy $perl = $^X;
1N/A# 5.005 doesn't have new enough File::Spec to have rel2abs. But actually we
1N/A# only need it when $^X isn't absolute, which is going to be 5.8.0 or later
1N/A# (where ExtUtils::Constant is in the core, and tests against the uninstalled
1N/A# perl)
1N/A$perl = File::Spec->rel2abs ($perl) unless $] < 5.006;
1N/A# ExtUtils::Constant::C_constant uses $^X inside a comment, and we want to
1N/A# compare output to ensure that it is the same. We were probably run as ./perl
1N/A# whereas we will run the child with the full path in $perl. So make $^X for
1N/A# us the same as our child will see.
1N/A$^X = $perl;
1N/Amy $lib = $ENV{PERL_CORE} ? '../../../lib' : '../../blib/lib';
1N/Amy $runperl = "$perl \"-I$lib\"";
1N/Aprint "# perl=$perl\n";
1N/A
1N/Amy $make = $Config{make};
1N/A$make = $ENV{MAKE} if exists $ENV{MAKE};
1N/Aif ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; }
1N/A
1N/A# Renamed by make clean
1N/Amy $makefile = ($^O eq 'VMS' ? 'descrip' : 'Makefile');
1N/Amy $makefile_ext = ($^O eq 'VMS' ? '.mms' : '');
1N/Amy $makefile_rename = $makefile . ($^O eq 'VMS' ? '.mms' : '.old');
1N/A
1N/Amy $output = "output";
1N/Amy $package = "ExtTest";
1N/Amy $dir = "ext-$$";
1N/Amy $subdir = 0;
1N/A# The real test counter.
1N/Amy $realtest = 1;
1N/A
1N/Amy $orig_cwd = cwd;
1N/Amy $updir = File::Spec->updir;
1N/Adie "Can't get current directory: $!" unless defined $orig_cwd;
1N/A
1N/Aprint "# $dir being created...\n";
1N/Amkdir $dir, 0777 or die "mkdir: $!\n";
1N/A
1N/AEND {
1N/A if (defined $orig_cwd and length $orig_cwd) {
1N/A chdir $orig_cwd or die "Can't chdir back to '$orig_cwd': $!";
1N/A use File::Path;
1N/A print "# $dir being removed...\n";
1N/A rmtree($dir) unless $keep_files;
1N/A } else {
1N/A # Can't get here.
1N/A die "cwd at start was empty, but directory '$dir' was created" if $dir;
1N/A }
1N/A}
1N/A
1N/Achdir $dir or die $!;
1N/Apush @INC, '../../lib', '../../../lib';
1N/A
1N/Asub check_for_bonus_files {
1N/A my $dir = shift;
1N/A my %expect = map {($^O eq 'VMS' ? lc($_) : $_), 1} @_;
1N/A
1N/A my $fail;
1N/A opendir DIR, $dir or die "opendir '$dir': $!";
1N/A while (defined (my $entry = readdir DIR)) {
1N/A $entry =~ s/\.$// if $^O eq 'VMS'; # delete trailing dot that indicates no extension
1N/A next if $expect{$entry};
1N/A print "# Extra file '$entry'\n";
1N/A $fail = 1;
1N/A }
1N/A
1N/A closedir DIR or warn "closedir '.': $!";
1N/A if ($fail) {
1N/A print "not ok $realtest\n";
1N/A } else {
1N/A print "ok $realtest\n";
1N/A }
1N/A $realtest++;
1N/A}
1N/A
1N/Asub build_and_run {
1N/A my ($tests, $expect, $files) = @_;
1N/A my $core = $ENV{PERL_CORE} ? ' PERL_CORE=1' : '';
1N/A my @perlout = `$runperl Makefile.PL $core`;
1N/A if ($?) {
1N/A print "not ok $realtest # $runperl Makefile.PL failed: $?\n";
1N/A print "# $_" foreach @perlout;
1N/A exit($?);
1N/A } else {
1N/A print "ok $realtest\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A if (-f "$makefile$makefile_ext") {
1N/A print "ok $realtest\n";
1N/A } else {
1N/A print "not ok $realtest\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A my @makeout;
1N/A
1N/A if ($^O eq 'VMS') { $make .= ' all'; }
1N/A
1N/A print "# make = '$make'\n";
1N/A @makeout = `$make`;
1N/A if ($?) {
1N/A print "not ok $realtest # $make failed: $?\n";
1N/A print "# $_" foreach @makeout;
1N/A exit($?);
1N/A } else {
1N/A print "ok $realtest\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A if ($^O eq 'VMS') { $make =~ s{ all}{}; }
1N/A
1N/A if ($Config{usedl}) {
1N/A print "ok $realtest # This is dynamic linking, so no need to make perl\n";
1N/A } else {
1N/A my $makeperl = "$make perl";
1N/A print "# make = '$makeperl'\n";
1N/A @makeout = `$makeperl`;
1N/A if ($?) {
1N/A print "not ok $realtest # $makeperl failed: $?\n";
1N/A print "# $_" foreach @makeout;
1N/A exit($?);
1N/A } else {
1N/A print "ok $realtest\n";
1N/A }
1N/A }
1N/A $realtest++;
1N/A
1N/A my $maketest = "$make test";
1N/A print "# make = '$maketest'\n";
1N/A
1N/A @makeout = `$maketest`;
1N/A
1N/A if (open OUTPUT, "<$output") {
1N/A local $/; # Slurp it - faster.
1N/A print <OUTPUT>;
1N/A close OUTPUT or print "# Close $output failed: $!\n";
1N/A } else {
1N/A # Harness will report missing test results at this point.
1N/A print "# Open <$output failed: $!\n";
1N/A }
1N/A
1N/A $realtest += $tests;
1N/A if ($?) {
1N/A print "not ok $realtest # $maketest failed: $?\n";
1N/A print "# $_" foreach @makeout;
1N/A } else {
1N/A print "ok $realtest - maketest\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A # -x is busted on Win32 < 5.6.1, so we emulate it.
1N/A my $regen;
1N/A if( $^O eq 'MSWin32' && $] <= 5.006001 ) {
1N/A open(REGENTMP, ">regentmp") or die $!;
1N/A open(XS, "$package.xs") or die $!;
1N/A my $saw_shebang;
1N/A while(<XS>) {
1N/A $saw_shebang++ if /^#!.*/i ;
1N/A print REGENTMP $_ if $saw_shebang;
1N/A }
1N/A close XS; close REGENTMP;
1N/A $regen = `$runperl regentmp`;
1N/A unlink 'regentmp';
1N/A }
1N/A else {
1N/A $regen = `$runperl -x $package.xs`;
1N/A }
1N/A if ($?) {
1N/A print "not ok $realtest # $runperl -x $package.xs failed: $?\n";
1N/A } else {
1N/A print "ok $realtest - regen\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A if ($expect eq $regen) {
1N/A print "ok $realtest - regen worked\n";
1N/A } else {
1N/A print "not ok $realtest - regen worked\n";
1N/A # open FOO, ">expect"; print FOO $expect;
1N/A # open FOO, ">regen"; print FOO $regen; close FOO;
1N/A }
1N/A $realtest++;
1N/A
1N/A my $makeclean = "$make clean";
1N/A print "# make = '$makeclean'\n";
1N/A @makeout = `$makeclean`;
1N/A if ($?) {
1N/A print "not ok $realtest # $make failed: $?\n";
1N/A print "# $_" foreach @makeout;
1N/A } else {
1N/A print "ok $realtest\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A check_for_bonus_files ('.', @$files, $output, $makefile_rename, '.', '..');
1N/A
1N/A rename $makefile_rename, $makefile
1N/A or die "Can't rename '$makefile_rename' to '$makefile': $!";
1N/A
1N/A unlink $output or warn "Can't unlink '$output': $!";
1N/A
1N/A # Need to make distclean to remove ../../lib/ExtTest.pm
1N/A my $makedistclean = "$make distclean";
1N/A print "# make = '$makedistclean'\n";
1N/A @makeout = `$makedistclean`;
1N/A if ($?) {
1N/A print "not ok $realtest # $make failed: $?\n";
1N/A print "# $_" foreach @makeout;
1N/A } else {
1N/A print "ok $realtest\n";
1N/A }
1N/A $realtest++;
1N/A
1N/A check_for_bonus_files ('.', @$files, '.', '..');
1N/A
1N/A unless ($keep_files) {
1N/A foreach (@$files) {
1N/A unlink $_ or warn "unlink $_: $!";
1N/A }
1N/A }
1N/A
1N/A check_for_bonus_files ('.', '.', '..');
1N/A}
1N/A
1N/Asub Makefile_PL {
1N/A my $package = shift;
1N/A ################ Makefile.PL
1N/A # We really need a Makefile.PL because make test for a no dynamic linking perl
1N/A # will run Makefile.PL again as part of the "make perl" target.
1N/A my $makefilePL = "Makefile.PL";
1N/A open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
1N/A print FH <<"EOT";
1N/A#!$perl -w
1N/Ause ExtUtils::MakeMaker;
1N/AWriteMakefile(
1N/A 'NAME' => "$package",
1N/A 'VERSION_FROM' => "$package.pm", # finds \$VERSION
1N/A (\$] >= 5.005 ?
1N/A (#ABSTRACT_FROM => "$package.pm", # XXX add this
1N/A AUTHOR => "$0") : ())
1N/A );
1N/AEOT
1N/A
1N/A close FH or die "close $makefilePL: $!\n";
1N/A return $makefilePL;
1N/A}
1N/A
1N/Asub MANIFEST {
1N/A my (@files) = @_;
1N/A ################ MANIFEST
1N/A # We really need a MANIFEST because make distclean checks it.
1N/A my $manifest = "MANIFEST";
1N/A push @files, $manifest;
1N/A open FH, ">$manifest" or die "open >$manifest: $!\n";
1N/A print FH "$_\n" foreach @files;
1N/A close FH or die "close $manifest: $!\n";
1N/A return @files;
1N/A}
1N/A
1N/Asub write_and_run_extension {
1N/A my ($name, $items, $export_names, $package, $header, $testfile, $num_tests)
1N/A = @_;
1N/A my $types = {};
1N/A my $constant_types = constant_types(); # macro defs
1N/A my $C_constant = join "\n",
1N/A C_constant ($package, undef, "IV", $types, undef, undef, @$items);
1N/A my $XS_constant = XS_constant ($package, $types); # XS for ExtTest::constant
1N/A
1N/A my $expect = $constant_types . $C_constant .
1N/A "\n#### XS Section:\n" . $XS_constant;
1N/A
1N/A print "# $name\n# $dir/$subdir being created...\n";
1N/A mkdir $subdir, 0777 or die "mkdir: $!\n";
1N/A chdir $subdir or die $!;
1N/A
1N/A my @files;
1N/A
1N/A ################ Header
1N/A my $header_name = "test.h";
1N/A push @files, $header_name;
1N/A open FH, ">$header_name" or die "open >$header_name: $!\n";
1N/A print FH $header or die $!;
1N/A close FH or die "close $header_name: $!\n";
1N/A
1N/A ################ XS
1N/A my $xs = "$package.xs";
1N/A push @files, $xs;
1N/A open FH, ">$xs" or die "open >$xs: $!\n";
1N/A
1N/A print FH <<'EOT';
1N/A#include "EXTERN.h"
1N/A#include "perl.h"
1N/A#include "XSUB.h"
1N/AEOT
1N/A
1N/A # XXX Here doc these:
1N/A print FH "#include \"$header_name\"\n\n";
1N/A print FH $constant_types;
1N/A print FH $C_constant, "\n";
1N/A print FH "MODULE = $package PACKAGE = $package\n";
1N/A print FH "PROTOTYPES: ENABLE\n";
1N/A print FH $XS_constant;
1N/A close FH or die "close $xs: $!\n";
1N/A
1N/A ################ PM
1N/A my $pm = "$package.pm";
1N/A push @files, $pm;
1N/A open FH, ">$pm" or die "open >$pm: $!\n";
1N/A print FH "package $package;\n";
1N/A print FH "use $];\n";
1N/A
1N/A print FH <<'EOT';
1N/A
1N/Ause strict;
1N/AEOT
1N/A printf FH "use warnings;\n" unless $] < 5.006;
1N/A print FH <<'EOT';
1N/Ause Carp;
1N/A
1N/Arequire Exporter;
1N/Arequire DynaLoader;
1N/Ause vars qw ($VERSION @ISA @EXPORT_OK $AUTOLOAD);
1N/A
1N/A$VERSION = '0.01';
1N/A@ISA = qw(Exporter DynaLoader);
1N/AEOT
1N/A # Having this qw( in the here doc confuses cperl mode far too much to be
1N/A # helpful. And I'm using cperl mode to edit this, even if you're not :-)
1N/A print FH "\@EXPORT_OK = qw(\n";
1N/A
1N/A # Print the names of all our autoloaded constants
1N/A print FH "\t$_\n" foreach (@$export_names);
1N/A print FH ");\n";
1N/A # Print the AUTOLOAD subroutine ExtUtils::Constant generated for us
1N/A print FH autoload ($package, $]);
1N/A print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
1N/A close FH or die "close $pm: $!\n";
1N/A
1N/A ################ test.pl
1N/A my $testpl = "test.pl";
1N/A push @files, $testpl;
1N/A open FH, ">$testpl" or die "open >$testpl: $!\n";
1N/A # Standard test header (need an option to suppress this?)
1N/A print FH <<"EOT" or die $!;
1N/Ause strict;
1N/Ause $package qw(@$export_names);
1N/A
1N/Aprint "1..2\n";
1N/Aif (open OUTPUT, ">$output") {
1N/A print "ok 1\n";
1N/A select OUTPUT;
1N/A} else {
1N/A print "not ok 1 # Failed to open '$output': \$!\n";
1N/A exit 1;
1N/A}
1N/AEOT
1N/A print FH $testfile or die $!;
1N/A print FH <<"EOT" or die $!;
1N/Aselect STDOUT;
1N/Aif (close OUTPUT) {
1N/A print "ok 2\n";
1N/A} else {
1N/A print "not ok 2 # Failed to close '$output': \$!\n";
1N/A}
1N/AEOT
1N/A close FH or die "close $testpl: $!\n";
1N/A
1N/A push @files, Makefile_PL($package);
1N/A @files = MANIFEST (@files);
1N/A
1N/A build_and_run ($num_tests, $expect, \@files);
1N/A
1N/A chdir $updir or die "chdir '$updir': $!";
1N/A ++$subdir;
1N/A}
1N/A# Tests are arrayrefs of the form
1N/A# $name, [items], [export_names], $package, $header, $testfile, $num_tests
1N/Amy @tests;
1N/Amy $before_tests = 4; # Number of "ok"s emitted to build extension
1N/Amy $after_tests = 8; # Number of "ok"s emitted after make test run
1N/Amy $dummytest = 1;
1N/A
1N/Amy $here;
1N/Asub start_tests {
1N/A $dummytest += $before_tests;
1N/A $here = $dummytest;
1N/A}
1N/Asub end_tests {
1N/A my ($name, $items, $export_names, $header, $testfile) = @_;
1N/A push @tests, [$name, $items, $export_names, $package, $header, $testfile,
1N/A $dummytest - $here];
1N/A $dummytest += $after_tests;
1N/A}
1N/A
1N/Amy $pound;
1N/Aif (ord('A') == 193) { # EBCDIC platform
1N/A $pound = chr 177; # A pound sign. (Currency)
1N/A} else { # ASCII platform
1N/A $pound = chr 163; # A pound sign. (Currency)
1N/A}
1N/Amy @common_items = (
1N/A {name=>"perl", type=>"PV",},
1N/A {name=>"*/", type=>"PV", value=>'"CLOSE"', macro=>1},
1N/A {name=>"/*", type=>"PV", value=>'"OPEN"', macro=>1},
1N/A {name=>$pound, type=>"PV", value=>'"Sterling"', macro=>1},
1N/A );
1N/A
1N/A{
1N/A # Simple tests
1N/A start_tests();
1N/A my $parent_rfc1149 =
1N/A 'A Standard for the Transmission of IP Datagrams on Avian Carriers';
1N/A # Test the code that generates 1 and 2 letter name comparisons.
1N/A my %compass = (
1N/A N => 0, 'NE' => 45, E => 90, SE => 135,
1N/A S => 180, SW => 225, W => 270, NW => 315
1N/A );
1N/A
1N/A my $header = << "EOT";
1N/A#define FIVE 5
1N/A#define OK6 "ok 6\\n"
1N/A#define OK7 1
1N/A#define FARTHING 0.25
1N/A#define NOT_ZERO 1
1N/A#define Yes 0
1N/A#define No 1
1N/A#define Undef 1
1N/A#define RFC1149 "$parent_rfc1149"
1N/A#undef NOTDEF
1N/A#define perl "rules"
1N/AEOT
1N/A
1N/A while (my ($point, $bearing) = each %compass) {
1N/A $header .= "#define $point $bearing\n"
1N/A }
1N/A
1N/A my @items = ("FIVE", {name=>"OK6", type=>"PV",},
1N/A {name=>"OK7", type=>"PVN",
1N/A value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
1N/A {name => "FARTHING", type=>"NV"},
1N/A {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
1N/A {name => "OPEN", type=>"PV", value=>'"/*"', macro=>1},
1N/A {name => "CLOSE", type=>"PV", value=>'"*/"',
1N/A macro=>["#if 1\n", "#endif\n"]},
1N/A {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
1N/A {name => "Yes", type=>"YES"},
1N/A {name => "No", type=>"NO"},
1N/A {name => "Undef", type=>"UNDEF"},
1N/A # OK. It wasn't really designed to allow the creation of dual valued
1N/A # constants.
1N/A # It was more for INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
1N/A {name=>"RFC1149", type=>"SV", value=>"sv_2mortal(temp_sv)",
1N/A pre=>"SV *temp_sv = newSVpv(RFC1149, 0); "
1N/A . "(void) SvUPGRADE(temp_sv,SVt_PVIV); SvIOK_on(temp_sv); "
1N/A . "SvIVX(temp_sv) = 1149;"},
1N/A );
1N/A
1N/A push @items, $_ foreach keys %compass;
1N/A
1N/A # Automatically compile the list of all the macro names, and make them
1N/A # exported constants.
1N/A my @export_names = map {(ref $_) ? $_->{name} : $_} @items;
1N/A
1N/A # Exporter::Heavy (currently) isn't able to export the last 3 of these:
1N/A push @items, @common_items;
1N/A
1N/A # XXX there are hardwired still.
1N/A my $test_body = <<'EOT';
1N/A# What follows goes to the temporary file.
1N/A# IV
1N/Amy $five = FIVE;
1N/Aif ($five == 5) {
1N/A print "ok 5\n";
1N/A} else {
1N/A print "not ok 5 # \$five\n";
1N/A}
1N/A
1N/A# PV
1N/Aprint OK6;
1N/A
1N/A# PVN containing embedded \0s
1N/A$_ = OK7;
1N/As/.*\0//s;
1N/Aprint;
1N/A
1N/A# NV
1N/Amy $farthing = FARTHING;
1N/Aif ($farthing == 0.25) {
1N/A print "ok 8\n";
1N/A} else {
1N/A print "not ok 8 # $farthing\n";
1N/A}
1N/A
1N/A# UV
1N/Amy $not_zero = NOT_ZERO;
1N/Aif ($not_zero > 0 && $not_zero == ~0) {
1N/A print "ok 9\n";
1N/A} else {
1N/A print "not ok 9 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
1N/A}
1N/A
1N/A# Value includes a "*/" in an attempt to bust out of a C comment.
1N/A# Also tests custom cpp #if clauses
1N/Amy $close = CLOSE;
1N/Aif ($close eq '*/') {
1N/A print "ok 10\n";
1N/A} else {
1N/A print "not ok 10 # \$close='$close'\n";
1N/A}
1N/A
1N/A# Default values if macro not defined.
1N/Amy $answer = ANSWER;
1N/Aif ($answer == 42) {
1N/A print "ok 11\n";
1N/A} else {
1N/A print "not ok 11 # What do you get if you multiply six by nine? '$answer'\n";
1N/A}
1N/A
1N/A# not defined macro
1N/Amy $notdef = eval { NOTDEF; };
1N/Aif (defined $notdef) {
1N/A print "not ok 12 # \$notdef='$notdef'\n";
1N/A} elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
1N/A print "not ok 12 # \$@='$@'\n";
1N/A} else {
1N/A print "ok 12\n";
1N/A}
1N/A
1N/A# not a macro
1N/Amy $notthere = eval { &ExtTest::NOTTHERE; };
1N/Aif (defined $notthere) {
1N/A print "not ok 13 # \$notthere='$notthere'\n";
1N/A} elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
1N/A chomp $@;
1N/A print "not ok 13 # \$@='$@'\n";
1N/A} else {
1N/A print "ok 13\n";
1N/A}
1N/A
1N/A# Truth
1N/Amy $yes = Yes;
1N/Aif ($yes) {
1N/A print "ok 14\n";
1N/A} else {
1N/A print "not ok 14 # $yes='\$yes'\n";
1N/A}
1N/A
1N/A# Falsehood
1N/Amy $no = No;
1N/Aif (defined $no and !$no) {
1N/A print "ok 15\n";
1N/A} else {
1N/A print "not ok 15 # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
1N/A}
1N/A
1N/A# Undef
1N/Amy $undef = Undef;
1N/Aunless (defined $undef) {
1N/A print "ok 16\n";
1N/A} else {
1N/A print "not ok 16 # \$undef='$undef'\n";
1N/A}
1N/A
1N/A# invalid macro (chosen to look like a mix up between No and SW)
1N/A$notdef = eval { &ExtTest::So };
1N/Aif (defined $notdef) {
1N/A print "not ok 17 # \$notdef='$notdef'\n";
1N/A} elsif ($@ !~ /^So is not a valid ExtTest macro/) {
1N/A print "not ok 17 # \$@='$@'\n";
1N/A} else {
1N/A print "ok 17\n";
1N/A}
1N/A
1N/A# invalid defined macro
1N/A$notdef = eval { &ExtTest::EW };
1N/Aif (defined $notdef) {
1N/A print "not ok 18 # \$notdef='$notdef'\n";
1N/A} elsif ($@ !~ /^EW is not a valid ExtTest macro/) {
1N/A print "not ok 18 # \$@='$@'\n";
1N/A} else {
1N/A print "ok 18\n";
1N/A}
1N/A
1N/Amy %compass = (
1N/AEOT
1N/A
1N/Awhile (my ($point, $bearing) = each %compass) {
1N/A $test_body .= "'$point' => $bearing, "
1N/A}
1N/A
1N/A$test_body .= <<'EOT';
1N/A
1N/A);
1N/A
1N/Amy $fail;
1N/Awhile (my ($point, $bearing) = each %compass) {
1N/A my $val = eval $point;
1N/A if ($@) {
1N/A print "# $point: \$@='$@'\n";
1N/A $fail = 1;
1N/A } elsif (!defined $bearing) {
1N/A print "# $point: \$val=undef\n";
1N/A $fail = 1;
1N/A } elsif ($val != $bearing) {
1N/A print "# $point: \$val=$val, not $bearing\n";
1N/A $fail = 1;
1N/A }
1N/A}
1N/Aif ($fail) {
1N/A print "not ok 19\n";
1N/A} else {
1N/A print "ok 19\n";
1N/A}
1N/A
1N/AEOT
1N/A
1N/A$test_body .= <<"EOT";
1N/Amy \$rfc1149 = RFC1149;
1N/Aif (\$rfc1149 ne "$parent_rfc1149") {
1N/A print "not ok 20 # '\$rfc1149' ne '$parent_rfc1149'\n";
1N/A} else {
1N/A print "ok 20\n";
1N/A}
1N/A
1N/Aif (\$rfc1149 != 1149) {
1N/A printf "not ok 21 # %d != 1149\n", \$rfc1149;
1N/A} else {
1N/A print "ok 21\n";
1N/A}
1N/A
1N/AEOT
1N/A
1N/A$test_body .= <<'EOT';
1N/A# test macro=>1
1N/Amy $open = OPEN;
1N/Aif ($open eq '/*') {
1N/A print "ok 22\n";
1N/A} else {
1N/A print "not ok 22 # \$open='$open'\n";
1N/A}
1N/AEOT
1N/A$dummytest+=18;
1N/A
1N/A end_tests("Simple tests", \@items, \@export_names, $header, $test_body);
1N/A}
1N/A
1N/Aif ($do_utf_tests) {
1N/A # utf8 tests
1N/A start_tests();
1N/A my ($inf, $pound_bytes, $pound_utf8);
1N/A
1N/A $inf = chr 0x221E;
1N/A # Check that we can distiguish the pathological case of a string, and the
1N/A # utf8 representation of that string.
1N/A $pound_utf8 = $pound . '1';
1N/A if ($better_than_56) {
1N/A $pound_bytes = $pound_utf8;
1N/A utf8::encode ($pound_bytes);
1N/A } else {
1N/A # Must have that "U*" to generate a zero length UTF string that forces
1N/A # top bit set chars (such as the pound sign) into UTF8, so that the
1N/A # unpack 'C*' then gets the byte form of the UTF8.
1N/A $pound_bytes = pack 'C*', unpack 'C*', $pound_utf8 . pack "U*";
1N/A }
1N/A
1N/A my @items = (@common_items,
1N/A {name=>$inf, type=>"PV", value=>'"Infinity"', macro=>1},
1N/A {name=>$pound_utf8, type=>"PV", value=>'"1 Pound"', macro=>1},
1N/A {name=>$pound_bytes, type=>"PV", value=>'"1 Pound (as bytes)"',
1N/A macro=>1},
1N/A );
1N/A
1N/A=pod
1N/A
1N/AThe above set of names seems to produce a suitably bad set of compile
1N/Aproblems on a Unicode naive version of ExtUtils::Constant (ie 0.11):
1N/A
1N/Anick@thinking-cap 15439-32-utf$ PERL_CORE=1 ./perl lib/ExtUtils/t/Constant.t
1N/A1..33
1N/A# perl=/stuff/perl5/15439-32-utf/perl
1N/A# ext-30370 being created...
1N/AWide character in print at lib/ExtUtils/t/Constant.t line 140.
1N/Aok 1
1N/Aok 2
1N/A# make = 'make'
1N/AExtTest.xs: In function `constant_1':
1N/AExtTest.xs:80: warning: multi-character character constant
1N/AExtTest.xs:80: warning: case value out of range
1N/Aok 3
1N/A
1N/A=cut
1N/A
1N/A# Grr `
1N/A
1N/A # Do this in 7 bit in case someone is testing with some settings that cause
1N/A # 8 bit files incapable of storing this character.
1N/A my @values
1N/A = map {"'" . join (",", unpack "U*", $_ . pack "U*") . "'"}
1N/A ($pound, $inf, $pound_bytes, $pound_utf8);
1N/A # Values is a list of strings, such as ('194,163,49', '163,49')
1N/A
1N/A my $test_body .= "my \$test = $dummytest;\n";
1N/A $dummytest += 7 * 3; # 3 tests for each of the 7 things:
1N/A
1N/A $test_body .= << 'EOT';
1N/A
1N/Ause utf8;
1N/Amy $better_than_56 = $] > 5.007;
1N/A
1N/Amy ($pound, $inf, $pound_bytes, $pound_utf8) = map {eval "pack 'U*', $_"}
1N/AEOT
1N/A
1N/A $test_body .= join ",", @values;
1N/A
1N/A $test_body .= << 'EOT';
1N/A;
1N/A
1N/Aforeach (["perl", "rules", "rules"],
1N/A ["/*", "OPEN", "OPEN"],
1N/A ["*/", "CLOSE", "CLOSE"],
1N/A [$pound, 'Sterling', []],
1N/A [$inf, 'Infinity', []],
1N/A [$pound_utf8, '1 Pound', '1 Pound (as bytes)'],
1N/A [$pound_bytes, '1 Pound (as bytes)', []],
1N/A ) {
1N/A # Flag an expected error with a reference for the expect string.
1N/A my ($string, $expect, $expect_bytes) = @$_;
1N/A (my $name = $string) =~ s/([^ -~])/sprintf '\x{%X}', ord $1/ges;
1N/A print "# \"$name\" => \'$expect\'\n";
1N/A # Try to force this to be bytes if possible.
1N/A if ($better_than_56) {
1N/A utf8::downgrade ($string, 1);
1N/A } else {
1N/A if ($string =~ tr/0-\377// == length $string) {
1N/A # No chars outside range 0-255
1N/A $string = pack 'C*', unpack 'U*', ($string . pack 'U*');
1N/A }
1N/A }
1N/AEOT
1N/A
1N/A $test_body .= "my (\$error, \$got) = ${package}::constant (\$string);\n";
1N/A
1N/A $test_body .= <<'EOT';
1N/A if ($error or $got ne $expect) {
1N/A print "not ok $test # error '$error', got '$got'\n";
1N/A } else {
1N/A print "ok $test\n";
1N/A }
1N/A $test++;
1N/A print "# Now upgrade '$name' to utf8\n";
1N/A if ($better_than_56) {
1N/A utf8::upgrade ($string);
1N/A } else {
1N/A $string = pack ('U*') . $string;
1N/A }
1N/AEOT
1N/A
1N/A $test_body .= "my (\$error, \$got) = ${package}::constant (\$string);\n";
1N/A
1N/A $test_body .= <<'EOT';
1N/A if ($error or $got ne $expect) {
1N/A print "not ok $test # error '$error', got '$got'\n";
1N/A } else {
1N/A print "ok $test\n";
1N/A }
1N/A $test++;
1N/A if (defined $expect_bytes) {
1N/A print "# And now with the utf8 byte sequence for name\n";
1N/A # Try the encoded bytes.
1N/A if ($better_than_56) {
1N/A utf8::encode ($string);
1N/A } else {
1N/A $string = pack 'C*', unpack 'C*', $string . pack "U*";
1N/A }
1N/AEOT
1N/A
1N/A $test_body .= "my (\$error, \$got) = ${package}::constant (\$string);\n";
1N/A
1N/A $test_body .= <<'EOT';
1N/A if (ref $expect_bytes) {
1N/A # Error expected.
1N/A if ($error) {
1N/A print "ok $test # error='$error' (as expected)\n";
1N/A } else {
1N/A print "not ok $test # expected error, got no error and '$got'\n";
1N/A }
1N/A } elsif ($got ne $expect_bytes) {
1N/A print "not ok $test # error '$error', expect '$expect_bytes', got '$got'\n";
1N/A } else {
1N/A print "ok $test\n";
1N/A }
1N/A $test++;
1N/A }
1N/A}
1N/AEOT
1N/A
1N/A end_tests("utf8 tests", \@items, [], "#define perl \"rules\"\n", $test_body);
1N/A}
1N/A
1N/A# XXX I think that I should merge this into the utf8 test above.
1N/Asub explict_call_constant {
1N/A my ($string, $expect) = @_;
1N/A # This does assume simple strings suitable for ''
1N/A my $test_body = <<"EOT";
1N/A{
1N/A my (\$error, \$got) = ${package}::constant ('$string');\n;
1N/AEOT
1N/A
1N/A if (defined $expect) {
1N/A # No error expected
1N/A $test_body .= <<"EOT";
1N/A if (\$error or \$got ne "$expect") {
1N/A print "not ok $dummytest # error '\$error', expect '$expect', got '\$got'\n";
1N/A } else {
1N/A print "ok $dummytest\n";
1N/A }
1N/A }
1N/AEOT
1N/A } else {
1N/A # Error expected.
1N/A $test_body .= <<"EOT";
1N/A if (\$error) {
1N/A print "ok $dummytest # error='\$error' (as expected)\n";
1N/A } else {
1N/A print "not ok $dummytest # expected error, got no error and '\$got'\n";
1N/A }
1N/AEOT
1N/A }
1N/A $dummytest++;
1N/A return $test_body . <<'EOT';
1N/A}
1N/AEOT
1N/A}
1N/A
1N/A# Simple tests to verify bits of the switch generation system work.
1N/Asub simple {
1N/A start_tests();
1N/A # Deliberately leave $name in @_, so that it is indexed from 1.
1N/A my ($name, @items) = @_;
1N/A my $test_header;
1N/A my $test_body = "my \$value;\n";
1N/A foreach my $counter (1 .. $#_) {
1N/A my $thisname = $_[$counter];
1N/A $test_header .= "#define $thisname $counter\n";
1N/A $test_body .= <<"EOT";
1N/A\$value = $thisname;
1N/Aif (\$value == $counter) {
1N/A print "ok $dummytest\n";
1N/A} else {
1N/A print "not ok $dummytest # $thisname gave \$value\n";
1N/A}
1N/AEOT
1N/A ++$dummytest;
1N/A # Yes, the last time round the loop appends a z to the string.
1N/A for my $i (0 .. length $thisname) {
1N/A my $copyname = $thisname;
1N/A substr ($copyname, $i, 1) = 'z';
1N/A $test_body .= explict_call_constant ($copyname,
1N/A $copyname eq $thisname
1N/A ? $thisname : undef);
1N/A }
1N/A }
1N/A # Ho. This seems to be buggy in 5.005_03:
1N/A # # Now remove $name from @_:
1N/A # shift @_;
1N/A end_tests($name, \@items, \@items, $test_header, $test_body);
1N/A}
1N/A
1N/A# Check that the memeq clauses work correctly when there isn't a switch
1N/A# statement to bump off a character
1N/Asimple ("Singletons", "A", "AB", "ABC", "ABCD", "ABCDE");
1N/A# Check the three code.
1N/Asimple ("Three start", qw(Bea kea Lea lea nea pea rea sea tea Wea yea Zea));
1N/A# There were 162 2 letter words in /usr/share/dict/words on FreeBSD 4.6, which
1N/A# I felt was rather too many. So I used words with 2 vowels.
1N/Asimple ("Twos and three middle", qw(aa ae ai ea eu ie io oe era eta));
1N/A# Given the choice go for the end, else the earliest point
1N/Asimple ("Three end and four symetry", qw(ean ear eat barb marm tart));
1N/A
1N/A
1N/A# Need this if the single test below is rolled into @tests :
1N/A# --$dummytest;
1N/Aprint "1..$dummytest\n";
1N/A
1N/Awrite_and_run_extension @$_ foreach @tests;
1N/A
1N/A# This was causing an assertion failure (a C<confess>ion)
1N/A# Any single byte > 128 should do it.
1N/AC_constant ($package, undef, undef, undef, undef, undef, chr 255);
1N/Aprint "ok $realtest\n"; $realtest++;
1N/A
1N/Aprint STDERR "# You were running with \$keep_files set to $keep_files\n"
1N/A if $keep_files;