2 # t/test.pl - most of Test::More functionality without the fuss, plus
3 # has mappings native_to_latin1 and latin1_to_native so that fewer tests
4 # on non ASCII-ish platforms need to be skipped
9 # Increment ($x++) has a certain amount of cleverness for things like
12 # $x++; # $x eq 'aaa';
14 # stands more chance of breaking than just a simple
18 # In this file, we use the latter "Baby Perl" approach, and increment
19 # will be worked over by t/op/inc.t
25 my $Perl; # Safer version of $^X set by which_perl()
30 # Use this instead of print to avoid interference while testing globals.
32 local($\, $", $,) = (undef, ' ', '');
37 local($\, $", $,) = (undef, ' ', '');
45 if ($n eq 'no_plan') {
53 _print "1..$n\n" unless $noplan;
60 if (defined $planned && $planned != $ran) {
62 "# Looks like you planned $planned tests but ran $ran.\n";
69 # Use this instead of "print STDERR" when outputing failure diagnostic
73 my @mess = map { /^#/ ? "$_\n" : "# $_\n" }
74 map { split /\n/ } @_;
75 $TODO ? _print(@mess) : _print_stderr(@mess);
84 _print "1..0 # Skip @_\n";
92 my ($pass, $where, $name, @mess) = @_;
93 # Do not try to microoptimize by factoring out the "not ".
97 # escape out '#' or it will interfere with '# skip' and such
99 $out = $pass ? "ok $test - $name" : "not ok $test - $name";
101 $out = $pass ? "ok $test" : "not ok $test";
104 $out = $out . " # TODO $TODO" if $TODO;
108 _diag "# Failed $where\n";
111 # Ensure that the message is properly escaped.
114 $test = $test + 1; # don't use ++
120 my @caller = caller($Level);
121 return "at $caller[1] line $caller[2]";
124 # DON'T use this for matches. Use like() instead.
126 my ($pass, $name, @mess) = @_;
127 _ok($pass, _where(), $name, @mess);
132 return 'undef' unless defined $x;
141 return defined $x ? '"' . display ($x) . '"' : 'undef';
144 # keys are the codes \n etc map to, values are 2 char strings such as \n
145 my %backslash_escape;
146 foreach my $x (split //, 'nrtfa\\\'"') {
147 $backslash_escape{ord eval "\"\\$x\""} = "\\$x";
149 # A way to display scalars containing control characters and Unicode.
150 # Trying to avoid setting $_, or relying on local $_ to work.
154 if (defined $x and not ref $x) {
156 foreach my $c (unpack("U*", $x)) {
158 $y = $y . sprintf "\\x{%x}", $c;
159 } elsif ($backslash_escape{$c}) {
160 $y = $y . $backslash_escape{$c};
162 my $z = chr $c; # Maybe we can get away with a literal...
163 if ($z =~ /[[:^print:]]/) {
165 # Use octal for characters traditionally expressed as
166 # such: the low controls
168 $z = sprintf "\\%03o", $c;
170 $z = sprintf "\\x{%x}", $c;
178 return $x unless wantarray;
185 my ($got, $expected, $name, @mess) = @_;
188 if( !defined $got || !defined $expected ) {
189 # undef only matches undef
190 $pass = !defined $got && !defined $expected;
193 $pass = $got eq $expected;
197 unshift(@mess, "# got "._qq($got)."\n",
198 "# expected "._qq($expected)."\n");
200 _ok($pass, _where(), $name, @mess);
204 my ($got, $isnt, $name, @mess) = @_;
207 if( !defined $got || !defined $isnt ) {
208 # undef only matches undef
209 $pass = defined $got || defined $isnt;
212 $pass = $got ne $isnt;
216 unshift(@mess, "# it should not be "._qq($got)."\n",
219 _ok($pass, _where(), $name, @mess);
223 my($got, $type, $expected, $name, @mess) = @_;
228 local($@,$!); # don't interfere with $@
229 # eval() sometimes resets $!
230 $pass = eval "\$got $type \$expected";
233 # It seems Irix long doubles can have 2147483648 and 2147483648
234 # that stringify to the same thing but are acutally numerically
235 # different. Display the numbers if $type isn't a string operator,
236 # and the numbers are stringwise the same.
237 # (all string operators have alphabetic names, so tr/a-z// is true)
238 # This will also show numbers for some uneeded cases, but will
239 # definately be helpful for things such as == and <= that fail
240 if ($got eq $expected and $type !~ tr/a-z//) {
241 unshift @mess, "# $got - $expected = " . ($got - $expected) . "\n";
243 unshift(@mess, "# got "._qq($got)."\n",
244 "# expected $type "._qq($expected)."\n");
246 _ok($pass, _where(), $name, @mess);
249 # Check that $got is within $range of $expected
250 # if $range is 0, then check it's exact
251 # else if $expected is 0, then $range is an absolute value
252 # otherwise $range is a fractional error.
253 # Here $range must be numeric, >= 0
254 # Non numeric ranges might be a useful future extension. (eg %)
256 my ($got, $expected, $range, $name, @mess) = @_;
258 if (!defined $got or !defined $expected or !defined $range) {
259 # This is a fail, but doesn't need extra diagnostics
260 } elsif ($got !~ tr/0-9// or $expected !~ tr/0-9// or $range !~ tr/0-9//) {
262 unshift @mess, "# got, expected and range must be numeric\n";
263 } elsif ($range < 0) {
264 # This is also a fail
265 unshift @mess, "# range must not be negative\n";
266 } elsif ($range == 0) {
268 $pass = $got == $expected;
269 } elsif ($expected == 0) {
270 # If expected is 0, treat range as absolute
271 $pass = ($got <= $range) && ($got >= - $range);
273 my $diff = $got - $expected;
274 $pass = abs ($diff / $expected) < $range;
277 if ($got eq $expected) {
278 unshift @mess, "# $got - $expected = " . ($got - $expected) . "\n";
280 unshift@mess, "# got "._qq($got)."\n",
281 "# expected "._qq($expected)." (within "._qq($range).")\n";
283 _ok($pass, _where(), $name, @mess);
286 # Note: this isn't quite as fancy as Test::More::like().
288 sub like ($$@) { like_yn (0,@_) }; # 0 for -
289 sub unlike ($$@) { like_yn (1,@_) }; # 1 for un-
292 my ($flip, $got, $expected, $name, @mess) = @_;
294 $pass = $got =~ /$expected/ if !$flip;
295 $pass = $got !~ /$expected/ if $flip;
297 unshift(@mess, "# got '$got'\n",
299 ? "# expected !~ /$expected/\n" : "# expected /$expected/\n");
301 local $Level = $Level + 1;
302 _ok($pass, _where(), $name, @mess);
310 _ok(0, _where(), @_);
320 $test = $test + 1; # don't use ++
324 # Note: can't pass multipart messages since we try to
325 # be compatible with Test::More::skip().
328 my $n = @_ ? shift : 1;
330 _print "ok $test # skip $why\n";
339 my $n = @_ ? shift : 1;
342 _print "not ok $test # TODO & SKIP $why\n";
351 return 0 unless $#$ra == $#$rb;
352 for my $i (0..$#$ra) {
353 next if !defined $ra->[$i] && !defined $rb->[$i];
354 return 0 if !defined $ra->[$i];
355 return 0 if !defined $rb->[$i];
356 return 0 unless $ra->[$i] eq $rb->[$i];
362 my ($orig, $suspect) = @_;
364 while (my ($key, $value) = each %$suspect) {
365 # Force a hash recompute if this perl's internals can cache the hash key.
367 if (exists $orig->{$key}) {
368 if ($orig->{$key} ne $value) {
369 _print "# key ", _qq($key), " was ", _qq($orig->{$key}),
370 " now ", _qq($value), "\n";
374 _print "# key ", _qq($key), " is ", _qq($value),
375 ", not in original.\n";
379 foreach (keys %$orig) {
380 # Force a hash recompute if this perl's internals can cache the hash key.
382 next if (exists $suspect->{$_});
383 _print "# key ", _qq($_), " was ", _qq($orig->{$_}), " now missing.\n";
394 _ok(!$@, _where(), "require $require");
402 _ok(!$@, _where(), "use $use");
405 # runperl - Runs a separate perl interpreter.
407 # switches => [ command-line switches ]
408 # nolib => 1 # don't use -I../lib (included by default)
409 # prog => one-liner (avoid quotes)
410 # progs => [ multi-liner (avoid quotes) ]
411 # progfile => perl script
412 # stdin => string to feed the stdin
413 # stderr => redirect stderr to stdout
414 # args => [ command-line arguments to the perl program ]
415 # verbose => print the command line
417 my $is_mswin = $^O eq 'MSWin32';
418 my $is_netware = $^O eq 'NetWare';
419 my $is_vms = $^O eq 'VMS';
420 my $is_cygwin = $^O eq 'cygwin';
423 my ($runperl, $args) = @_;
426 # In VMS protect with doublequotes because otherwise
427 # DCL will lowercase -- unless already doublequoted.
428 $_ = q(").$_.q(") if $is_vms && !/^\"/ && length($_) > 0;
429 $runperl = $runperl . ' ' . $_;
434 sub _create_runperl { # Create the string to qx in runperl().
436 my $runperl = which_perl();
437 if ($runperl =~ m/\s/) {
438 $runperl = qq{"$runperl"};
440 #- this allows, for example, to set PERL_RUNPERL_DEBUG=/usr/bin/valgrind
441 if ($ENV{PERL_RUNPERL_DEBUG}) {
442 $runperl = "$ENV{PERL_RUNPERL_DEBUG} $runperl";
444 unless ($args{nolib}) {
445 $runperl = $runperl . ' "-I../lib"'; # doublequotes because of VMS
447 if ($args{switches}) {
449 die "test.pl:runperl(): 'switches' must be an ARRAYREF " . _where()
450 unless ref $args{switches} eq "ARRAY";
451 $runperl = _quote_args($runperl, $args{switches});
453 if (defined $args{prog}) {
454 die "test.pl:runperl(): both 'prog' and 'progs' cannot be used " . _where()
455 if defined $args{progs};
456 $args{progs} = [$args{prog}]
458 if (defined $args{progs}) {
459 die "test.pl:runperl(): 'progs' must be an ARRAYREF " . _where()
460 unless ref $args{progs} eq "ARRAY";
461 foreach my $prog (@{$args{progs}}) {
462 if ($is_mswin || $is_netware || $is_vms) {
463 $runperl = $runperl . qq ( -e "$prog" );
466 $runperl = $runperl . qq ( -e '$prog' );
469 } elsif (defined $args{progfile}) {
470 $runperl = $runperl . qq( "$args{progfile}");
472 # You probaby didn't want to be sucking in from the upstream stdin
473 die "test.pl:runperl(): none of prog, progs, progfile, args, "
474 . " switches or stdin specified"
475 unless defined $args{args} or defined $args{switches}
476 or defined $args{stdin};
478 if (defined $args{stdin}) {
479 # so we don't try to put literal newlines and crs onto the
481 $args{stdin} =~ s/\n/\\n/g;
482 $args{stdin} =~ s/\r/\\r/g;
484 if ($is_mswin || $is_netware || $is_vms) {
485 $runperl = qq{$Perl -e "print qq(} .
486 $args{stdin} . q{)" | } . $runperl;
489 $runperl = qq{$Perl -e 'print qq(} .
490 $args{stdin} . q{)' | } . $runperl;
493 if (defined $args{args}) {
494 $runperl = _quote_args($runperl, $args{args});
496 $runperl = $runperl . ' 2>&1' if $args{stderr};
497 if ($args{verbose}) {
498 my $runperldisplay = $runperl;
499 $runperldisplay =~ s/\n/\n\#/g;
500 _print_stderr "# $runperldisplay\n";
506 die "test.pl:runperl() does not take a hashref"
507 if ref $_[0] and ref $_[0] eq 'HASH';
508 my $runperl = &_create_runperl;
511 my $tainted = ${^TAINT};
513 exists $args{switches} && grep m/^-T$/, @{$args{switches}} and $tainted = $tainted + 1;
516 # We will assume that if you're running under -T, you really mean to
517 # run a fresh perl, so we'll brute force launder everything for you
520 if (! eval 'require Config; 1') {
521 warn "test.pl had problems loading Config: $@";
524 $sep = $Config::Config{path_sep};
527 my @keys = grep {exists $ENV{$_}} qw(CDPATH IFS ENV BASH_ENV);
528 local @ENV{@keys} = ();
529 # Untaint, plus take out . and empty string:
530 local $ENV{'DCL$PATH'} = $1 if $is_vms && exists($ENV{'DCL$PATH'}) && ($ENV{'DCL$PATH'} =~ /(.*)/s);
531 $ENV{PATH} =~ /(.*)/s;
533 join $sep, grep { $_ ne "" and $_ ne "." and -d $_ and
534 ($is_mswin or $is_vms or !(stat && (stat _)[2]&0022)) }
535 split quotemeta ($sep), $1;
536 $ENV{PATH} = $ENV{PATH} . "$sep/bin" if $is_cygwin; # Must have /bin under Cygwin
541 $result = `$runperl`;
543 $result = `$runperl`;
545 $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
549 *run_perl = \&runperl; # Nice alias.
552 _print_stderr "# @_\n";
556 # A somewhat safer version of the sometimes wrong $^X.
558 unless (defined $Perl) {
561 # VMS should have 'perl' aliased properly
562 return $Perl if $^O eq 'VMS';
565 if (! eval 'require Config; 1') {
566 warn "test.pl had problems loading Config: $@";
569 $exe = $Config::Config{_exe};
571 $exe = '' unless defined $exe;
573 # This doesn't absolutize the path: beware of future chdirs().
574 # We could do File::Spec->abs2rel() but that does getcwd()s,
575 # which is a bit heavyweight to do here.
577 if ($Perl =~ /^perl\Q$exe\E$/i) {
578 my $perl = "perl$exe";
579 if (! eval 'require File::Spec; 1') {
580 warn "test.pl had problems loading File::Spec: $@";
583 $Perl = File::Spec->catfile(File::Spec->curdir(), $perl);
587 # Build up the name of the executable file from the name of
590 if ($Perl !~ /\Q$exe\E$/i) {
591 $Perl = $Perl . $exe;
594 warn "which_perl: cannot find $Perl from $^X" unless -f $Perl;
596 # For subcommands to use.
597 $ENV{PERLEXE} = $Perl;
603 foreach my $file (@_) {
604 1 while unlink $file;
605 _print_stderr "# Couldn't unlink '$file': $!\n" if -f $file;
610 END { unlink_all keys %tmpfiles }
612 # A regexp that matches the tempfile names
613 $::tempfile_regexp = 'tmp\d+[A-Z][A-Z]?';
615 # Avoid ++, avoid ranges, avoid split //
616 my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
623 $try = $try . $letters[$temp % 26];
624 $temp = int ($temp / 26);
626 # Need to note all the file names we allocated, as a second request may
627 # come before the first is created.
628 if (!-e $try && !$tmpfiles{$try}) {
634 } while $count < 26 * 26;
635 die "Can't find temporary file name starting 'tmp$$'";
638 # This is the temporary file for _fresh_perl
639 my $tmpfile = tempfile();
644 # The $resolve must be a subref that tests the first argument
645 # for success, or returns the definition of success (e.g. the
646 # expected scalar) if given no arguments.
650 my($prog, $resolve, $runperl_args, $name) = @_;
652 # Given the choice of the mis-parsable {}
653 # (we want an anon hash, but a borked lexer might think that it's a block)
654 # or relying on taking a reference to a lexical
655 # (\ might be mis-parsed, and the reference counting on the pad may go
657 # it feels like the least-worse thing is to assume that auto-vivification
658 # works. At least, this is only going to be a run-time failure, so won't
659 # affect tests using this file but not this function.
660 $runperl_args->{progfile} = $tmpfile;
661 $runperl_args->{stderr} = 1;
663 open TEST, ">$tmpfile" or die "Cannot open $tmpfile: $!";
667 $prog =~ s#/dev/null#NL:#;
670 $prog =~ s{if \(-e _ and -f _ and -r _\)}
675 close TEST or die "Cannot close $tmpfile: $!";
677 my $results = runperl(%$runperl_args);
680 # Clean up the results into something a bit more predictable.
681 $results =~ s/\n+$//;
682 $results =~ s/at\s+$::tempfile_regexp\s+line/at - line/g;
683 $results =~ s/of\s+$::tempfile_regexp\s+aborted/of - aborted/g;
685 # bison says 'parse error' instead of 'syntax error',
686 # various yaccs may or may not capitalize 'syntax'.
687 $results =~ s/^(syntax|parse) error/syntax error/mig;
690 # some tests will trigger VMS messages that won't be expected
691 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
693 # pipes double these sometimes
694 $results =~ s/\n\n/\n/g;
697 my $pass = $resolve->($results);
699 _diag "# PROG: \n$prog\n";
700 _diag "# EXPECTED:\n", $resolve->(), "\n";
701 _diag "# GOT:\n$results\n";
702 _diag "# STATUS: $status\n";
705 # Use the first line of the program as a name if none was given
707 ($first_line, $name) = $prog =~ /^((.{1,50}).*)/;
708 $name = $name . '...' if length $first_line > length $name;
711 _ok($pass, _where(), "fresh_perl - $name");
717 # Combination of run_perl() and is().
721 my($prog, $expected, $runperl_args, $name) = @_;
723 # _fresh_perl() is going to clip the trailing newlines off the result.
724 # This will make it so the test author doesn't have to know that.
725 $expected =~ s/\n+$//;
729 sub { @_ ? $_[0] eq $expected : $expected },
730 $runperl_args, $name);
736 # Combination of run_perl() and like().
739 sub fresh_perl_like {
740 my($prog, $expected, $runperl_args, $name) = @_;
743 sub { @_ ? $_[0] =~ $expected : $expected },
744 $runperl_args, $name);
748 my($proto, @methods) = @_;
749 my $class = ref $proto || $proto;
752 return _ok( 0, _where(), "$class->can(...)" );
756 foreach my $method (@methods) {
757 local($!, $@); # don't interfere with caller's $@
758 # eval sometimes resets $!
759 eval { $proto->can($method) } || push @nok, $method;
763 $name = @methods == 1 ? "$class->can('$methods[0]')"
764 : "$class->can(...)";
766 _ok( !@nok, _where(), $name );
770 my($object, $class, $obj_name) = @_;
773 $obj_name = 'The object' unless defined $obj_name;
774 my $name = "$obj_name isa $class";
775 if( !defined $object ) {
776 $diag = "$obj_name isn't defined";
778 elsif( !ref $object ) {
779 $diag = "$obj_name isn't a reference";
782 # We can't use UNIVERSAL::isa because we want to honor isa() overrides
783 local($@, $!); # eval sometimes resets $!
784 my $rslt = eval { $object->isa($class) };
786 if( $@ =~ /^Can't call method "isa" on unblessed reference/ ) {
787 if( !UNIVERSAL::isa($object, $class) ) {
788 my $ref = ref $object;
789 $diag = "$obj_name isn't a '$class' it's a '$ref'";
793 WHOA! I tried to call ->isa on your object and got some weird error.
794 This should never happen. Please contact the author immediately.
801 my $ref = ref $object;
802 $diag = "$obj_name isn't a '$class' it's a '$ref'";
806 _ok( !$diag, _where(), $name );
809 # Set a watchdog to timeout the entire test file
810 # NOTE: If the test file uses 'threads', then call the watchdog() function
811 # _AFTER_ the 'threads' module is loaded.
816 my $timeout_msg = 'Test process timed out - terminating';
818 # Valgrind slows perl way down so give it more time before dying.
819 $timeout *= 10 if $ENV{PERL_VALGRIND};
821 my $pid_to_kill = $$; # PID for this process
823 if ($method eq "alarm") {
824 goto WATCHDOG_VIA_ALARM;
827 # Don't use a watchdog process if 'threads' is loaded -
828 # use a watchdog thread instead
829 if (! $threads::threads) {
831 # On Windows and VMS, try launching a watchdog process
832 # using system(1, ...) (see perlport.pod)
833 if (($^O eq 'MSWin32') || ($^O eq 'VMS')) {
834 # On Windows, try to get the 'real' PID
835 if ($^O eq 'MSWin32') {
836 eval { require Win32; };
837 if (defined(&Win32::GetCurrentProcessId)) {
838 $pid_to_kill = Win32::GetCurrentProcessId();
842 # If we still have a fake PID, we can't use this method at all
843 return if ($pid_to_kill <= 0);
845 # Launch watchdog process
848 local $SIG{'__WARN__'} = sub {
849 _diag("Watchdog warning: $_[0]");
851 my $sig = $^O eq 'VMS' ? 'TERM' : 'KILL';
852 my $cmd = _create_runperl( prog => "sleep($timeout);" .
853 "warn qq/# $timeout_msg" . '\n/;' .
854 "kill($sig, $pid_to_kill);");
855 $watchdog = system(1, $cmd);
857 if ($@ || ($watchdog <= 0)) {
858 _diag('Failed to start watchdog');
864 # Add END block to parent to terminate and
865 # clean up watchdog process
866 eval "END { local \$! = 0; local \$? = 0;
867 wait() if kill('KILL', $watchdog); };";
871 # Try using fork() to generate a watchdog process
873 eval { $watchdog = fork() };
874 if (defined($watchdog)) {
875 if ($watchdog) { # Parent process
876 # Add END block to parent to terminate and
877 # clean up watchdog process
878 eval "END { local \$! = 0; local \$? = 0;
879 wait() if kill('KILL', $watchdog); };";
883 ### Watchdog process code
885 # Load POSIX if available
886 eval { require POSIX; };
888 # Execute the timeout
889 sleep($timeout - 2) if ($timeout > 2); # Workaround for perlbug #49073
892 # Kill test process if still running
893 if (kill(0, $pid_to_kill)) {
895 kill('KILL', $pid_to_kill);
898 # Don't execute END block (added at beginning of this file)
901 # Terminate ourself (i.e., the watchdog)
902 POSIX::_exit(1) if (defined(&POSIX::_exit));
906 # fork() failed - fall through and try using a thread
909 # Use a watchdog thread because either 'threads' is loaded,
911 if (eval 'require threads; 1') {
912 threads->create(sub {
913 # Load POSIX if available
914 eval { require POSIX; };
916 # Execute the timeout
917 my $time_left = $timeout;
919 $time_left = $time_left - sleep($time_left);
920 } while ($time_left > 0);
922 # Kill the parent (and ourself)
923 select(STDERR); $| = 1;
925 POSIX::_exit(1) if (defined(&POSIX::_exit));
926 my $sig = $^O eq 'VMS' ? 'TERM' : 'KILL';
927 kill($sig, $pid_to_kill);
932 # If everything above fails, then just use an alarm timeout
934 if (eval { alarm($timeout); 1; }) {
935 # Load POSIX if available
936 eval { require POSIX; };
938 # Alarm handler will do the actual 'killing'
940 select(STDERR); $| = 1;
942 POSIX::_exit(1) if (defined(&POSIX::_exit));
943 my $sig = $^O eq 'VMS' ? 'TERM' : 'KILL';
944 kill($sig, $pid_to_kill);
949 my $cp_0037 = # EBCDIC code page 0037
950 '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x25\x0B\x0C\x0D\x0E\x0F' .
951 '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
952 '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
953 '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
954 '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
955 '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xBA\xE0\xBB\xB0\x6D' .
956 '\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
957 '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07' .
958 '\x20\x21\x22\x23\x24\x15\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
959 '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF' .
960 '\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBD\xB4\x9A\x8A\x5F\xCA\xAF\xBC' .
961 '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
962 '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
963 '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xAD\xAE\x59' .
964 '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
965 '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF';
967 my $cp_1047 = # EBCDIC code page 1047
968 '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x15\x0B\x0C\x0D\x0E\x0F' .
969 '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
970 '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
971 '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
972 '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
973 '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xAD\xE0\xBD\x5F\x6D' .
974 '\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
975 '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07' .
976 '\x20\x21\x22\x23\x24\x25\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
977 '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\xFF' .
978 '\x41\xAA\x4A\xB1\x9F\xB2\x6A\xB5\xBB\xB4\x9A\x8A\xB0\xCA\xAF\xBC' .
979 '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
980 '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
981 '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xFD\xFE\xFB\xFC\xBA\xAE\x59' .
982 '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
983 '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xDD\xDE\xDB\xDC\x8D\x8E\xDF';
985 my $cp_bc = # EBCDIC code page POSiX-BC
986 '\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x15\x0B\x0C\x0D\x0E\x0F' .
987 '\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x1C\x1D\x1E\x1F' .
988 '\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61' .
989 '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F' .
990 '\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6' .
991 '\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xBB\xBC\xBD\x6A\x6D' .
992 '\x4A\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96' .
993 '\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xFB\x4F\xFD\xFF\x07' .
994 '\x20\x21\x22\x23\x24\x25\x06\x17\x28\x29\x2A\x2B\x2C\x09\x0A\x1B' .
995 '\x30\x31\x1A\x33\x34\x35\x36\x08\x38\x39\x3A\x3B\x04\x14\x3E\x5F' .
996 '\x41\xAA\xB0\xB1\x9F\xB2\xD0\xB5\x79\xB4\x9A\x8A\xBA\xCA\xAF\xA1' .
997 '\x90\x8F\xEA\xFA\xBE\xA0\xB6\xB3\x9D\xDA\x9B\x8B\xB7\xB8\xB9\xAB' .
998 '\x64\x65\x62\x66\x63\x67\x9E\x68\x74\x71\x72\x73\x78\x75\x76\x77' .
999 '\xAC\x69\xED\xEE\xEB\xEF\xEC\xBF\x80\xE0\xFE\xDD\xFC\xAD\xAE\x59' .
1000 '\x44\x45\x42\x46\x43\x47\x9C\x48\x54\x51\x52\x53\x58\x55\x56\x57' .
1001 '\x8C\x49\xCD\xCE\xCB\xCF\xCC\xE1\x70\xC0\xDE\xDB\xDC\x8D\x8E\xDF';
1003 my $straight = # Avoid ranges
1004 '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F' .
1005 '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F' .
1006 '\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F' .
1007 '\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F' .
1008 '\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F' .
1009 '\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F' .
1010 '\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F' .
1011 '\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F' .
1012 '\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F' .
1013 '\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F' .
1014 '\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF' .
1015 '\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF' .
1016 '\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF' .
1017 '\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF' .
1018 '\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF' .
1019 '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF';
1021 # The following 2 functions allow tests to work on both EBCDIC and
1022 # ASCII-ish platforms. They convert string scalars between the native
1023 # character set and the set of 256 characters which is usually called
1026 # These routines don't work on UTF-EBCDIC and UTF-8.
1028 sub native_to_latin1($) {
1031 return $string if ord('^') == 94; # ASCII, Latin1
1033 if (ord('^') == 95) { # EBCDIC 1047
1036 elsif (ord('^') == 106) { # EBCDIC POSIX-BC
1039 elsif (ord('^') == 176) { # EBCDIC 037 */
1043 die "Unknown native character set";
1046 eval '$string =~ tr/' . $$cp . '/' . $straight . '/';
1050 sub latin1_to_native($) {
1053 return $string if ord('^') == 94; # ASCII, Latin1
1055 if (ord('^') == 95) { # EBCDIC 1047
1058 elsif (ord('^') == 106) { # EBCDIC POSIX-BC
1061 elsif (ord('^') == 176) { # EBCDIC 037 */
1065 die "Unknown native character set";
1068 eval '$string =~ tr/' . $straight . '/' . $$cp . '/';