4 if( $ENV{PERL_CORE} ) {
9 unless ($Config{usedl}) {
10 print "1..0 # no usedl, skipping\n";
17 use ExtUtils::MakeMaker;
18 use ExtUtils::Constant qw (C_constant autoload);
22 my $do_utf_tests = $] > 5.006;
23 my $better_than_56 = $] > 5.007;
24 # For debugging set this to 1.
28 # Because were are going to be changing directory before running Makefile.PL
30 # 5.005 doesn't have new enough File::Spec to have rel2abs. But actually we
31 # only need it when $^X isn't absolute, which is going to be 5.8.0 or later
32 # (where ExtUtils::Constant is in the core, and tests against the uninstalled
34 $perl = File::Spec->rel2abs ($perl) unless $] < 5.006;
35 # ExtUtils::Constant::C_constant uses $^X inside a comment, and we want to
36 # compare output to ensure that it is the same. We were probably run as ./perl
37 # whereas we will run the child with the full path in $perl. So make $^X for
38 # us the same as our child will see.
40 my $lib = $ENV{PERL_CORE} ? '../../../lib' : '../../blib/lib';
41 my $runperl = "$perl \"-I$lib\"";
42 print "# perl=$perl\n";
44 my $make = $Config{make};
45 $make = $ENV{MAKE} if exists $ENV{MAKE};
46 if ($^O eq 'MSWin32' && $make eq 'nmake') { $make .= " -nologo"; }
48 # VMS may be using something other than MMS/MMK
53 $mms_or_mmk = 1 if (($make eq 'MMK') || ($make eq 'MMS'));
59 if (eval 'require VMS::Feature') {
60 $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
61 $vms_efs = VMS::Feature::current("efs_case_preserve");
62 $vms_efs_case = VMS::Feature::current("efs_charset");
64 my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
65 my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
66 my $efs_case = $ENV{'DECC$EFS_CASE_PRESERVE'} || '';
67 $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
68 $vms_efs = $efs_charset =~ /^[ET1]/i;
69 $vms_efs_case = $efs_case =~ /^[ET1]/i;
71 $vms_lc = 0 if $vms_efs_case;
72 $vms_nodot = 0 if $vms_unix_rpt;
75 # Renamed by make clean
76 my $makefile = ($mms_or_mmk ? 'descrip' : 'Makefile');
77 my $makefile_ext = ($mms_or_mmk ? '.mms' : '');
78 my $makefile_rename = $makefile . ($mms_or_mmk ? '.mms_old' : '.old');
80 my $output = "output";
81 my $package = "ExtTest";
84 # The real test counter.
88 my $updir = File::Spec->updir;
89 die "Can't get current directory: $!" unless defined $orig_cwd;
91 print "# $dir being created...\n";
92 mkdir $dir, 0777 or die "mkdir: $!\n";
95 if (defined $orig_cwd and length $orig_cwd) {
96 chdir $orig_cwd or die "Can't chdir back to '$orig_cwd': $!";
98 print "# $dir being removed...\n";
99 rmtree($dir) unless $keep_files;
102 die "cwd at start was empty, but directory '$dir' was created" if $dir;
106 chdir $dir or die $!;
107 push @INC, '../../lib', '../../../lib';
113 bless(\( my $ref = ''), $class);
118 $$self .= join('', @_);
123 $$self .= sprintf shift, @_;
128 return substr($$self, 0, length($$self), '');
133 sub check_for_bonus_files {
135 my %expect = map {($vms_lc ? lc($_) : $_), 1} @_;
138 opendir DIR, $dir or die "opendir '$dir': $!";
139 while (defined (my $entry = readdir DIR)) {
140 $entry =~ s/\.$// if $vms_nodot; # delete trailing dot that indicates no extension
141 next if $expect{$entry};
142 print "# Extra file '$entry'\n";
146 closedir DIR or warn "closedir '.': $!";
148 print "not ok $realtest\n";
150 print "ok $realtest\n";
156 my ($tests, $expect, $files) = @_;
157 my $core = $ENV{PERL_CORE} ? ' PERL_CORE=1' : '';
158 my @perlout = `$runperl Makefile.PL $core`;
160 print "not ok $realtest # $runperl Makefile.PL failed: $?\n";
161 print "# $_" foreach @perlout;
164 print "ok $realtest\n";
168 if (-f "$makefile$makefile_ext") {
169 print "ok $realtest\n";
171 print "not ok $realtest\n";
177 if ($^O eq 'VMS') { $make .= ' all'; }
179 # Sometimes it seems that timestamps can get confused
182 # Makefile out-of-date with respect to Makefile.PL
183 # Cleaning current config before rebuilding Makefile...
184 # make -f Makefile.old clean > /dev/null 2>&1 || /bin/sh -c true
185 # ../../perl "-I../../../lib" "-I../../../lib" Makefile.PL "PERL_CORE=1"
186 # Checking if your kit is complete...
188 # Writing Makefile for ExtTest
189 # ==> Your Makefile has been rebuilt. <==
190 # ==> Please rerun the make command. <==
193 my $timewarp = (-M "Makefile.PL") - (-M "$makefile$makefile_ext");
194 # Convert from days to seconds
196 print "# Makefile.PL is $timewarp second(s) older than $makefile$makefile_ext\n";
198 # Sleep for a while to catch up.
199 $timewarp = -$timewarp;
201 $timewarp = 10 if $timewarp > 10;
202 print "# Sleeping for $timewarp second(s) to try to resolve this\n";
206 print "# make = '$make'\n";
209 print "not ok $realtest # $make failed: $?\n";
210 print "# $_" foreach @makeout;
213 print "ok $realtest\n";
217 if ($^O eq 'VMS') { $make =~ s{ all}{}; }
219 if ($Config{usedl}) {
220 print "ok $realtest # This is dynamic linking, so no need to make perl\n";
222 my $makeperl = "$make perl";
223 print "# make = '$makeperl'\n";
224 @makeout = `$makeperl`;
226 print "not ok $realtest # $makeperl failed: $?\n";
227 print "# $_" foreach @makeout;
230 print "ok $realtest\n";
235 my $maketest = "$make test";
236 print "# make = '$maketest'\n";
238 @makeout = `$maketest`;
240 if (open OUTPUT, "<$output") {
241 local $/; # Slurp it - faster.
243 close OUTPUT or print "# Close $output failed: $!\n";
245 # Harness will report missing test results at this point.
246 print "# Open <$output failed: $!\n";
251 print "not ok $realtest # $maketest failed: $?\n";
252 print "# $_" foreach @makeout;
254 print "ok $realtest - maketest\n";
258 if (defined $expect) {
259 # -x is busted on Win32 < 5.6.1, so we emulate it.
261 if( $^O eq 'MSWin32' && $] <= 5.006001 ) {
262 open(REGENTMP, ">regentmp") or die $!;
263 open(XS, "$package.xs") or die $!;
266 $saw_shebang++ if /^#!.*/i ;
267 print REGENTMP $_ if $saw_shebang;
269 close XS; close REGENTMP;
270 $regen = `$runperl regentmp`;
274 $regen = `$runperl -x $package.xs`;
277 print "not ok $realtest # $runperl -x $package.xs failed: $?\n";
279 print "ok $realtest - regen\n";
283 if ($expect eq $regen) {
284 print "ok $realtest - regen worked\n";
286 print "not ok $realtest - regen worked\n";
287 # open FOO, ">expect"; print FOO $expect;
288 # open FOO, ">regen"; print FOO $regen; close FOO;
293 print "ok $realtest # skip no regen or expect for this set of tests\n";
298 my $makeclean = "$make clean";
299 print "# make = '$makeclean'\n";
300 @makeout = `$makeclean`;
302 print "not ok $realtest # $make failed: $?\n";
303 print "# $_" foreach @makeout;
305 print "ok $realtest\n";
309 check_for_bonus_files ('.', @$files, $output, $makefile_rename, '.', '..');
311 rename $makefile_rename, $makefile . $makefile_ext
312 or die "Can't rename '$makefile_rename' to '$makefile$makefile_ext': $!";
314 unlink $output or warn "Can't unlink '$output': $!";
316 # Need to make distclean to remove ../../lib/ExtTest.pm
317 my $makedistclean = "$make distclean";
318 print "# make = '$makedistclean'\n";
319 @makeout = `$makedistclean`;
321 print "not ok $realtest # $make failed: $?\n";
322 print "# $_" foreach @makeout;
324 print "ok $realtest\n";
328 check_for_bonus_files ('.', @$files, '.', '..');
330 unless ($keep_files) {
332 unlink $_ or warn "unlink $_: $!";
336 check_for_bonus_files ('.', '.', '..');
341 ################ Makefile.PL
342 # We really need a Makefile.PL because make test for a no dynamic linking perl
343 # will run Makefile.PL again as part of the "make perl" target.
344 my $makefilePL = "Makefile.PL";
345 open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
348 use ExtUtils::MakeMaker;
350 'NAME' => "$package",
351 'VERSION_FROM' => "$package.pm", # finds \$VERSION
353 (#ABSTRACT_FROM => "$package.pm", # XXX add this
354 AUTHOR => "$0") : ())
358 close FH or die "close $makefilePL: $!\n";
364 ################ MANIFEST
365 # We really need a MANIFEST because make distclean checks it.
366 my $manifest = "MANIFEST";
367 push @files, $manifest;
368 open FH, ">$manifest" or die "open >$manifest: $!\n";
369 print FH "$_\n" foreach @files;
370 close FH or die "close $manifest: $!\n";
374 sub write_and_run_extension {
375 my ($name, $items, $export_names, $package, $header, $testfile, $num_tests,
378 my $c = tie *C, 'TieOut';
379 my $xs = tie *XS, 'TieOut';
381 ExtUtils::Constant::WriteConstants(C_FH => \*C,
388 my $C_code = $c->read();
389 my $XS_code = $xs->read();
397 # Don't check the regeneration code if we specify extra arguments to
398 # WriteConstants. (Fix this to give finer grained control if needed)
400 $expect = $C_code . "\n#### XS Section:\n" . $XS_code unless $wc_args;
402 print "# $name\n# $dir/$subdir being created...\n";
403 mkdir $subdir, 0777 or die "mkdir: $!\n";
404 chdir $subdir or die $!;
408 ################ Header
409 my $header_name = "test.h";
410 push @files, $header_name;
411 open FH, ">$header_name" or die "open >$header_name: $!\n";
412 print FH $header or die $!;
413 close FH or die "close $header_name: $!\n";
416 my $xs_name = "$package.xs";
417 push @files, $xs_name;
418 open FH, ">$xs_name" or die "open >$xs_name: $!\n";
424 #include "$header_name"
428 MODULE = $package PACKAGE = $package
433 close FH or die "close $xs: $!\n";
436 my $pm = "$package.pm";
438 open FH, ">$pm" or die "open >$pm: $!\n";
439 print FH "package $package;\n";
440 print FH "use $];\n";
446 printf FH "use warnings;\n" unless $] < 5.006;
452 use vars qw ($VERSION @ISA @EXPORT_OK $AUTOLOAD);
455 @ISA = qw(Exporter DynaLoader);
457 # Having this qw( in the here doc confuses cperl mode far too much to be
458 # helpful. And I'm using cperl mode to edit this, even if you're not :-)
459 print FH "\@EXPORT_OK = qw(\n";
461 # Print the names of all our autoloaded constants
462 print FH "\t$_\n" foreach (@$export_names);
464 # Print the AUTOLOAD subroutine ExtUtils::Constant generated for us
465 print FH autoload ($package, $]);
466 print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
467 close FH or die "close $pm: $!\n";
469 ################ test.pl
470 my $testpl = "test.pl";
471 push @files, $testpl;
472 open FH, ">$testpl" or die "open >$testpl: $!\n";
473 # Standard test header (need an option to suppress this?)
474 print FH <<"EOT" or die $!;
476 use $package qw(@$export_names);
479 if (open OUTPUT, ">$output") {
483 print "not ok 1 # Failed to open '$output': \$!\n";
487 print FH $testfile or die $!;
488 print FH <<"EOT" or die $!;
493 print "not ok 2 # Failed to close '$output': \$!\n";
496 close FH or die "close $testpl: $!\n";
498 push @files, Makefile_PL($package);
499 @files = MANIFEST (@files);
501 build_and_run ($num_tests, $expect, \@files);
503 chdir $updir or die "chdir '$updir': $!";
507 # Tests are arrayrefs of the form
508 # $name, [items], [export_names], $package, $header, $testfile, $num_tests
510 my $before_tests = 4; # Number of "ok"s emitted to build extension
511 my $after_tests = 8; # Number of "ok"s emitted after make test run
516 $dummytest += $before_tests;
520 my ($name, $items, $export_names, $header, $testfile, $args) = @_;
521 push @tests, [$name, $items, $export_names, $package, $header, $testfile,
522 $dummytest - $here, $args];
523 $dummytest += $after_tests;
527 if (ord('A') == 193) { # EBCDIC platform
528 $pound = chr 177; # A pound sign. (Currency)
529 } else { # ASCII platform
530 $pound = chr 163; # A pound sign. (Currency)
533 {name=>"perl", type=>"PV",},
534 {name=>"*/", type=>"PV", value=>'"CLOSE"', macro=>1},
535 {name=>"/*", type=>"PV", value=>'"OPEN"', macro=>1},
536 {name=>$pound, type=>"PV", value=>'"Sterling"', macro=>1},
540 push @args, [PROXYSUBS => 1] if $] > 5.009002;
541 foreach my $args (@args)
546 'A Standard for the Transmission of IP Datagrams on Avian Carriers';
547 # Test the code that generates 1 and 2 letter name comparisons.
549 N => 0, 'NE' => 45, E => 90, SE => 135,
550 S => 180, SW => 225, W => 270, NW => 315
553 my $header = << "EOT";
555 #define OK6 "ok 6\\n"
557 #define FARTHING 0.25
562 #define RFC1149 "$parent_rfc1149"
567 while (my ($point, $bearing) = each %compass) {
568 $header .= "#define $point $bearing\n"
571 my @items = ("FIVE", {name=>"OK6", type=>"PV",},
572 {name=>"OK7", type=>"PVN",
573 value=>['"not ok 7\\n\\0ok 7\\n"', 15]},
574 {name => "FARTHING", type=>"NV"},
575 {name => "NOT_ZERO", type=>"UV", value=>"~(UV)0"},
576 {name => "OPEN", type=>"PV", value=>'"/*"', macro=>1},
577 {name => "CLOSE", type=>"PV", value=>'"*/"',
578 macro=>["#if 1\n", "#endif\n"]},
579 {name => "ANSWER", default=>["UV", 42]}, "NOTDEF",
580 {name => "Yes", type=>"YES"},
581 {name => "No", type=>"NO"},
582 {name => "Undef", type=>"UNDEF"},
583 # OK. It wasn't really designed to allow the creation of dual valued
585 # It was more for INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
586 {name=>"RFC1149", type=>"SV", value=>"sv_2mortal(temp_sv)",
587 pre=>"SV *temp_sv = newSVpv(RFC1149, 0); "
588 . "(void) SvUPGRADE(temp_sv,SVt_PVIV); SvIOK_on(temp_sv); "
589 . "SvIV_set(temp_sv, 1149);"},
592 push @items, $_ foreach keys %compass;
594 # Automatically compile the list of all the macro names, and make them
595 # exported constants.
596 my @export_names = map {(ref $_) ? $_->{name} : $_} @items;
598 # Exporter::Heavy (currently) isn't able to export the last 3 of these:
599 push @items, @common_items;
601 my $test_body = <<"EOT";
603 my \$test = $dummytest;
607 $test_body .= <<'EOT';
608 # What follows goes to the temporary file.
614 print "not ok $test # \$five\n";
619 if (OK6 eq "ok 6\n") {
622 print "not ok $test # \$five\n";
626 # PVN containing embedded \0s
634 my $farthing = FARTHING;
635 if ($farthing == 0.25) {
638 print "not ok $test # $farthing\n";
643 my $not_zero = NOT_ZERO;
644 if ($not_zero > 0 && $not_zero == ~0) {
647 print "not ok $test # \$not_zero=$not_zero ~0=" . (~0) . "\n";
651 # Value includes a "*/" in an attempt to bust out of a C comment.
652 # Also tests custom cpp #if clauses
654 if ($close eq '*/') {
657 print "not ok $test # \$close='$close'\n";
661 # Default values if macro not defined.
666 print "not ok $test # What do you get if you multiply six by nine? '$answer'\n";
671 my $notdef = eval { NOTDEF; };
672 if (defined $notdef) {
673 print "not ok $test # \$notdef='$notdef'\n";
674 } elsif ($@ !~ /Your vendor has not defined ExtTest macro NOTDEF/) {
675 print "not ok $test # \$@='$@'\n";
682 my $notthere = eval { &ExtTest::NOTTHERE; };
683 if (defined $notthere) {
684 print "not ok $test # \$notthere='$notthere'\n";
685 } elsif ($@ !~ /NOTTHERE is not a valid ExtTest macro/) {
687 print "not ok $test # \$@='$@'\n";
698 print "not ok $test # $yes='\$yes'\n";
704 if (defined $no and !$no) {
707 print "not ok $test # \$no=" . defined ($no) ? "'$no'\n" : "undef\n";
713 unless (defined $undef) {
716 print "not ok $test # \$undef='$undef'\n";
720 # invalid macro (chosen to look like a mix up between No and SW)
721 $notdef = eval { &ExtTest::So };
722 if (defined $notdef) {
723 print "not ok $test # \$notdef='$notdef'\n";
724 } elsif ($@ !~ /^So is not a valid ExtTest macro/) {
725 print "not ok $test # \$@='$@'\n";
731 # invalid defined macro
732 $notdef = eval { &ExtTest::EW };
733 if (defined $notdef) {
734 print "not ok $test # \$notdef='$notdef'\n";
735 } elsif ($@ !~ /^EW is not a valid ExtTest macro/) {
736 print "not ok $test # \$@='$@'\n";
745 while (my ($point, $bearing) = each %compass) {
746 $test_body .= "'$point' => $bearing, "
749 $test_body .= <<'EOT';
754 while (my ($point, $bearing) = each %compass) {
755 my $val = eval $point;
757 print "# $point: \$@='$@'\n";
759 } elsif (!defined $bearing) {
760 print "# $point: \$val=undef\n";
762 } elsif ($val != $bearing) {
763 print "# $point: \$val=$val, not $bearing\n";
768 print "not ok $test\n";
776 $test_body .= <<"EOT";
777 my \$rfc1149 = RFC1149;
778 if (\$rfc1149 ne "$parent_rfc1149") {
779 print "not ok \$test # '\$rfc1149' ne '$parent_rfc1149'\n";
785 if (\$rfc1149 != 1149) {
786 printf "not ok \$test # %d != 1149\n", \$rfc1149;
794 $test_body .= <<'EOT';
800 print "not ok $test # \$open='$open'\n";
806 end_tests("Simple tests", \@items, \@export_names, $header, $test_body,
813 my ($inf, $pound_bytes, $pound_utf8);
816 # Check that we can distiguish the pathological case of a string, and the
817 # utf8 representation of that string.
818 $pound_utf8 = $pound . '1';
819 if ($better_than_56) {
820 $pound_bytes = $pound_utf8;
821 utf8::encode ($pound_bytes);
823 # Must have that "U*" to generate a zero length UTF string that forces
824 # top bit set chars (such as the pound sign) into UTF8, so that the
825 # unpack 'C*' then gets the byte form of the UTF8.
826 $pound_bytes = pack 'C*', unpack 'C*', $pound_utf8 . pack "U*";
829 my @items = (@common_items,
830 {name=>$inf, type=>"PV", value=>'"Infinity"', macro=>1},
831 {name=>$pound_utf8, type=>"PV", value=>'"1 Pound"', macro=>1},
832 {name=>$pound_bytes, type=>"PV", value=>'"1 Pound (as bytes)"',
838 The above set of names seems to produce a suitably bad set of compile
839 problems on a Unicode naive version of ExtUtils::Constant (ie 0.11):
841 nick@thinking-cap 15439-32-utf$ PERL_CORE=1 ./perl lib/ExtUtils/t/Constant.t
843 # perl=/stuff/perl5/15439-32-utf/perl
844 # ext-30370 being created...
845 Wide character in print at lib/ExtUtils/t/Constant.t line 140.
849 ExtTest.xs: In function `constant_1':
850 ExtTest.xs:80: warning: multi-character character constant
851 ExtTest.xs:80: warning: case value out of range
858 # Do this in 7 bit in case someone is testing with some settings that cause
859 # 8 bit files incapable of storing this character.
861 = map {"'" . join (",", unpack "U*", $_ . pack "U*") . "'"}
862 ($pound, $inf, $pound_bytes, $pound_utf8);
863 # Values is a list of strings, such as ('194,163,49', '163,49')
865 my $test_body .= "my \$test = $dummytest;\n";
866 $dummytest += 7 * 3; # 3 tests for each of the 7 things:
868 $test_body .= << 'EOT';
871 my $better_than_56 = $] > 5.007;
873 my ($pound, $inf, $pound_bytes, $pound_utf8) = map {eval "pack 'U*', $_"}
876 $test_body .= join ",", @values;
878 $test_body .= << 'EOT';
881 foreach (["perl", "rules", "rules"],
882 ["/*", "OPEN", "OPEN"],
883 ["*/", "CLOSE", "CLOSE"],
884 [$pound, 'Sterling', []],
885 [$inf, 'Infinity', []],
886 [$pound_utf8, '1 Pound', '1 Pound (as bytes)'],
887 [$pound_bytes, '1 Pound (as bytes)', []],
889 # Flag an expected error with a reference for the expect string.
890 my ($string, $expect, $expect_bytes) = @$_;
891 (my $name = $string) =~ s/([^ !"#\$%&'()*+,\-.\/0-9:;<=>?\@A-Z[\\\]^_`a-z{|}~])/sprintf '\x{%X}', ord $1/ges;
892 print "# \"$name\" => \'$expect\'\n";
893 # Try to force this to be bytes if possible.
894 if ($better_than_56) {
895 utf8::downgrade ($string, 1);
897 if ($string =~ tr/0-\377// == length $string) {
898 # No chars outside range 0-255
899 $string = pack 'C*', unpack 'U*', ($string . pack 'U*');
904 $test_body .= "my (\$error, \$got) = ${package}::constant (\$string);\n";
906 $test_body .= <<'EOT';
907 if ($error or $got ne $expect) {
908 print "not ok $test # error '$error', got '$got'\n";
913 print "# Now upgrade '$name' to utf8\n";
914 if ($better_than_56) {
915 utf8::upgrade ($string);
917 $string = pack ('U*') . $string;
921 $test_body .= "my (\$error, \$got) = ${package}::constant (\$string);\n";
923 $test_body .= <<'EOT';
924 if ($error or $got ne $expect) {
925 print "not ok $test # error '$error', got '$got'\n";
930 if (defined $expect_bytes) {
931 print "# And now with the utf8 byte sequence for name\n";
932 # Try the encoded bytes.
933 if ($better_than_56) {
934 utf8::encode ($string);
936 $string = pack 'C*', unpack 'C*', $string . pack "U*";
940 $test_body .= "my (\$error, \$got) = ${package}::constant (\$string);\n";
942 $test_body .= <<'EOT';
943 if (ref $expect_bytes) {
946 print "ok $test # error='$error' (as expected)\n";
948 print "not ok $test # expected error, got no error and '$got'\n";
950 } elsif ($got ne $expect_bytes) {
951 print "not ok $test # error '$error', expect '$expect_bytes', got '$got'\n";
960 end_tests("utf8 tests", \@items, [], "#define perl \"rules\"\n", $test_body);
963 # XXX I think that I should merge this into the utf8 test above.
964 sub explict_call_constant {
965 my ($string, $expect) = @_;
966 # This does assume simple strings suitable for ''
967 my $test_body = <<"EOT";
969 my (\$error, \$got) = ${package}::constant ('$string');\n;
972 if (defined $expect) {
974 $test_body .= <<"EOT";
975 if (\$error or \$got ne "$expect") {
976 print "not ok $dummytest # error '\$error', expect '$expect', got '\$got'\n";
978 print "ok $dummytest\n";
984 $test_body .= <<"EOT";
986 print "ok $dummytest # error='\$error' (as expected)\n";
988 print "not ok $dummytest # expected error, got no error and '\$got'\n";
993 return $test_body . <<'EOT';
998 # Simple tests to verify bits of the switch generation system work.
1001 # Deliberately leave $name in @_, so that it is indexed from 1.
1002 my ($name, @items) = @_;
1004 my $test_body = "my \$value;\n";
1005 foreach my $counter (1 .. $#_) {
1006 my $thisname = $_[$counter];
1007 $test_header .= "#define $thisname $counter\n";
1008 $test_body .= <<"EOT";
1009 \$value = $thisname;
1010 if (\$value == $counter) {
1011 print "ok $dummytest\n";
1013 print "not ok $dummytest # $thisname gave \$value\n";
1017 # Yes, the last time round the loop appends a z to the string.
1018 for my $i (0 .. length $thisname) {
1019 my $copyname = $thisname;
1020 substr ($copyname, $i, 1) = 'z';
1021 $test_body .= explict_call_constant ($copyname,
1022 $copyname eq $thisname
1023 ? $thisname : undef);
1026 # Ho. This seems to be buggy in 5.005_03:
1027 # # Now remove $name from @_:
1029 end_tests($name, \@items, \@items, $test_header, $test_body);
1032 # Check that the memeq clauses work correctly when there isn't a switch
1033 # statement to bump off a character
1034 simple ("Singletons", "A", "AB", "ABC", "ABCD", "ABCDE");
1035 # Check the three code.
1036 simple ("Three start", qw(Bea kea Lea lea nea pea rea sea tea Wea yea Zea));
1037 # There were 162 2 letter words in /usr/share/dict/words on FreeBSD 4.6, which
1038 # I felt was rather too many. So I used words with 2 vowels.
1039 simple ("Twos and three middle", qw(aa ae ai ea eu ie io oe era eta));
1040 # Given the choice go for the end, else the earliest point
1041 simple ("Three end and four symetry", qw(ean ear eat barb marm tart));
1044 # Need this if the single test below is rolled into @tests :
1046 print "1..$dummytest\n";
1048 write_and_run_extension @$_ foreach @tests;
1050 # This was causing an assertion failure (a C<confess>ion)
1051 # Any single byte > 128 should do it.
1052 C_constant ($package, undef, undef, undef, undef, undef, chr 255);
1053 print "ok $realtest\n"; $realtest++;
1055 print STDERR "# You were running with \$keep_files set to $keep_files\n"