3 # This tests plain 'use locale' and adorned 'use locale ":not_characters"'
4 # Because these pragmas are compile time, and I (khw) am trying to test
5 # without using 'eval' as much as possible, which might cloud the issue, the
6 # crucial parts of the code are duplicated in a block for each pragma.
8 # To make a TODO test, add the string 'TODO' to its %test_names value
10 binmode STDOUT, ':utf8';
11 binmode STDERR, ':utf8';
17 require Config; import Config;
18 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
28 my $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
30 # Certain tests have been shown to be problematical for a few locales. Don't
31 # fail them unless at least this percentage of the tested locales fail.
32 my $acceptable_fold_failure_percentage = 5;
36 my $dumper = Dumpvalue->new(
43 my($mess) = join "", @_;
45 print $dumper->stringify($mess,1), "\n";
52 my $have_setlocale = 0;
55 import POSIX ':locale_h';
59 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
60 # and mingw32 uses said silly CRT
61 # This doesn't seem to be an issue any more, at least on Windows XP,
62 # so re-enable the tests for Windows XP onwards.
63 my $winxp = ($^O eq 'MSWin32' && defined &Win32::GetOSVersion &&
64 join('.', (Win32::GetOSVersion())[1..2]) >= 5.1);
65 $have_setlocale = 0 if ((($^O eq 'MSWin32' && !$winxp) || $^O eq 'NetWare') &&
66 $Config{cc} =~ /^(cl|gcc)/i);
68 # UWIN seems to loop after taint tests, just skip for now
69 $have_setlocale = 0 if ($^O =~ /^uwin/);
76 my ($result, $message) = @_;
77 $message = "" unless defined $message;
79 print 'not ' unless ($result);
80 print "ok " . ++$test_num;
85 # First we'll do a lot of taint checking for locales.
86 # This is the easiest to test, actually, as any locale,
87 # even the default locale will taint under 'use locale'.
89 sub is_tainted { # hello, camel two.
90 no warnings 'uninitialized' ;
93 not eval { $dummy = join("", @_), kill 0; 1 }
96 sub check_taint ($;$) {
97 my $message_tail = $_[1] // "";
98 $message_tail = ": $message_tail" if $message_tail;
99 ok is_tainted($_[0]), "verify that is tainted$message_tail";
102 sub check_taint_not ($;$) {
103 my $message_tail = $_[1] // "";
104 $message_tail = ": $message_tail" if $message_tail;
105 ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
108 "\tb\t" =~ /^m?(\s)(.*)\1$/;
109 check_taint_not $&, "not tainted outside 'use locale'";
112 use locale; # engage locale and therefore locale taint.
118 check_taint ucfirst($a);
124 check_taint lcfirst($a);
127 check_taint_not sprintf('%e', 123.456);
128 check_taint_not sprintf('%f', 123.456);
129 check_taint_not sprintf('%g', 123.456);
130 check_taint_not sprintf('%d', 123.456);
131 check_taint_not sprintf('%x', 123.456);
133 $_ = $a; # untaint $_
135 $_ = uc($a); # taint $_
139 /(\w)/; # taint $&, $`, $', $+, $1.
147 /(.)/; # untaint $&, $`, $', $+, $1.
155 /(\W)/; # taint $&, $`, $', $+, $1.
163 /(\s)/; # taint $&, $`, $', $+, $1.
171 /(\S)/; # taint $&, $`, $', $+, $1.
179 $_ = $a; # untaint $_
183 /(b)/; # this must not taint
191 $_ = $a; # untaint $_
195 $b = uc($a); # taint $b
196 s/(.+)/$b/; # this must taint only the $_
206 $_ = $a; # untaint $_
208 s/(.+)/b/; # this must not taint
217 $b = $a; # untaint $b
219 ($b = $a) =~ s/\w/$&/;
220 check_taint $b; # $b should be tainted.
221 check_taint_not $a; # $a should be not.
223 $_ = $a; # untaint $_
225 s/(\w)/\l$1/; # this must taint
234 $_ = $a; # untaint $_
236 s/(\w)/\L$1/; # this must taint
245 $_ = $a; # untaint $_
247 s/(\w)/\u$1/; # this must taint
256 $_ = $a; # untaint $_
258 s/(\w)/\U$1/; # this must taint
267 # After all this tainting $a should be cool.
271 { # This is just the previous tests copied here with a different
272 # compile-time pragma.
274 use locale ':not_characters'; # engage restricted locale with different
279 check_taint_not uc($a);
280 check_taint_not "\U$a";
281 check_taint_not ucfirst($a);
282 check_taint_not "\u$a";
283 check_taint_not lc($a);
284 check_taint_not fc($a);
285 check_taint_not "\L$a";
286 check_taint_not "\F$a";
287 check_taint_not lcfirst($a);
288 check_taint_not "\l$a";
290 check_taint_not sprintf('%e', 123.456);
291 check_taint_not sprintf('%f', 123.456);
292 check_taint_not sprintf('%g', 123.456);
293 check_taint_not sprintf('%d', 123.456);
294 check_taint_not sprintf('%x', 123.456);
296 $_ = $a; # untaint $_
298 $_ = uc($a); # taint $_
302 /(\w)/; # taint $&, $`, $', $+, $1.
310 /(.)/; # untaint $&, $`, $', $+, $1.
318 /(\W)/; # taint $&, $`, $', $+, $1.
326 /(\s)/; # taint $&, $`, $', $+, $1.
334 /(\S)/; # taint $&, $`, $', $+, $1.
342 $_ = $a; # untaint $_
346 /(b)/; # this must not taint
354 $_ = $a; # untaint $_
358 $b = uc($a); # taint $b
359 s/(.+)/$b/; # this must taint only the $_
369 $_ = $a; # untaint $_
371 s/(.+)/b/; # this must not taint
380 $b = $a; # untaint $b
382 ($b = $a) =~ s/\w/$&/;
383 check_taint_not $b; # $b should be tainted.
384 check_taint_not $a; # $a should be not.
386 $_ = $a; # untaint $_
388 s/(\w)/\l$1/; # this must taint
397 $_ = $a; # untaint $_
399 s/(\w)/\L$1/; # this must taint
408 $_ = $a; # untaint $_
410 s/(\w)/\u$1/; # this must taint
419 $_ = $a; # untaint $_
421 s/(\w)/\U$1/; # this must taint
430 # After all this tainting $a should be cool.
435 # Here are in scope of 'use locale'
437 # I think we've seen quite enough of taint.
438 # Let us do some *real* locale work now,
439 # unless setlocale() is missing (i.e. minitest).
441 unless ($have_setlocale) {
442 print "1..$test_num\n";
446 # The test number before our first setlocale()
447 my $final_without_setlocale = $test_num;
451 debug "# Scanning for locales...\n";
453 # Note that it's okay that some languages have their native names
454 # capitalized here even though that's not "right". They are lowercased
455 # anyway later during the scanning process (and besides, some clueless
456 # vendor might have them capitalized erroneously anyway).
460 Arabic:ar:dz eg sa:6 arabic8
461 Brezhoneg Breton:br:fr:1 15
462 Bulgarski Bulgarian:bg:bg:5
463 Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
464 Hrvatski Croatian:hr:hr:2
465 Cymraeg Welsh:cy:cy:1 14 15
467 Dansk Danish:da:dk:1 15
468 Nederlands Dutch:nl:be nl:1 15
469 English American British:en:au ca gb ie nz us uk zw:1 15 cp850
471 Eesti Estonian:et:ee:4 6 13
472 Suomi Finnish:fi:fi:1 15
474 Deutsch German:de:at be ch de lu:1 15
475 Euskaraz Basque:eu:es fr:1 15
476 Galego Galician:gl:es:1 15
477 Ellada Greek:el:gr:7 g8
479 Greenlandic:kl:gl:4 6
480 Hebrew:iw:il:8 hebrew8
482 Indonesian:id:id:1 15
483 Gaeilge Irish:ga:IE:1 14 15
484 Italiano Italian:it:ch it:1 15
485 Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
487 Latine Latin:la:va:1 15
489 Lithuanian:lt:lt:4 6 13
490 Macedonian:mk:mk:1 15
493 Norsk Norwegian:no no\@nynorsk nb nn:no:1 15
495 Polski Polish:pl:pl:2
497 Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
498 Serbski Serbian:sr:yu:5
500 Slovene Slovenian:sl:si:2
501 Sqhip Albanian:sq:sq:1 15
502 Svenska Swedish:sv:fi se:1 15
504 Turkish:tr:tr:9 turkish8
508 if ($^O eq 'os390') {
509 # These cause heartburn. Broken locales?
510 $locales =~ s/Svenska Swedish:sv:fi se:1 15\n//;
511 $locales =~ s/Thai:th:th:11 tis620\n//;
514 sub in_utf8 () { $^H & 0x08 || (${^OPEN} || "") =~ /:utf8/ }
517 require "lib/locale/utf8";
519 require "lib/locale/latin1";
529 return if grep { $locale eq $_ } @Locale;
530 return unless setlocale(&POSIX::LC_ALL, $locale);
533 local $SIG{__WARN__} = sub {
534 $badutf8 = $_[0] =~ /Malformed UTF-8/;
536 $Locale =~ /UTF-?8/i;
540 ok(0, "Locale name contains malformed utf8");
543 push @Locale, $locale;
546 sub decode_encodings {
549 foreach (split(/ /, shift)) {
551 push @enc, "ISO8859-$1";
552 push @enc, "iso8859$1"; # HP
554 push @enc, "roman8"; # HP
558 push @enc, "$_.UTF-8";
561 if ($^O eq 'os390') {
562 push @enc, qw(IBM-037 IBM-819 IBM-1047);
571 trylocale("ISO8859-$_");
572 trylocale("iso8859$_");
573 trylocale("iso8859-$_");
574 trylocale("iso_8859_$_");
575 trylocale("isolatin$_");
576 trylocale("isolatin-$_");
577 trylocale("iso_latin_$_");
580 # Sanitize the environment so that we can run the external 'locale'
581 # program without the taint mode getting grumpy.
583 # $ENV{PATH} is special in VMS.
584 delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
586 # Other subversive stuff.
587 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
589 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
591 # It seems that /usr/bin/locale steadfastly outputs 8 bit data, which
592 # ain't great when we're running this testPERL_UNICODE= so that utf8
593 # locales will cause all IO hadles to default to (assume) utf8
594 next unless utf8::valid($_);
599 } elsif ($^O eq 'VMS' && defined($ENV{'SYS$I18N_LOCALE'}) && -d 'SYS$I18N_LOCALE') {
600 # The SYS$I18N_LOCALE logical name search list was not present on
601 # VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
602 opendir(LOCALES, "SYS\$I18N_LOCALE:");
603 while ($_ = readdir(LOCALES)) {
608 } elsif ($^O eq 'openbsd' && -e '/usr/share/locale') {
610 # OpenBSD doesn't have a locale executable, so reading /usr/share/locale
611 # is much easier and faster than the last resort method.
613 opendir(LOCALES, '/usr/share/locale');
614 while ($_ = readdir(LOCALES)) {
621 # This is going to be slow.
623 foreach my $locale (split(/\n/, $locales)) {
624 my ($locale_name, $language_codes, $country_codes, $encodings) =
626 my @enc = decode_encodings($encodings);
627 foreach my $loc (split(/ /, $locale_name)) {
629 foreach my $enc (@enc) {
630 trylocale("$loc.$enc");
633 foreach my $enc (@enc) {
634 trylocale("$loc.$enc");
637 foreach my $lang (split(/ /, $language_codes)) {
639 foreach my $country (split(/ /, $country_codes)) {
640 my $lc = "${lang}_${country}";
642 foreach my $enc (@enc) {
643 trylocale("$lc.$enc");
645 my $lC = "${lang}_\U${country}";
647 foreach my $enc (@enc) {
648 trylocale("$lC.$enc");
655 setlocale(&POSIX::LC_ALL, "C");
657 if ($^O eq 'darwin') {
658 # Darwin 8/Mac OS X 10.4 and 10.5 have bad Basque locales: perl bug #35895,
659 # Apple bug ID# 4139653. It also has a problem in Byelorussian.
660 (my $v) = $Config{osvers} =~ /^(\d+)/;
661 if ($v >= 8 and $v < 10) {
662 debug "# Skipping eu_ES, be_BY locales -- buggy in Darwin\n";
663 @Locale = grep ! m/^(eu_ES(?:\..*)?|be_BY\.CP1131)$/, @Locale;
665 debug "# Skipping be_BY locales -- buggy in Darwin\n";
666 @Locale = grep ! m/^be_BY\.CP1131$/, @Locale;
670 @Locale = sort @Locale;
672 debug "# Locales =\n";
680 my @Added_alpha; # Alphas that aren't in the C locale.
683 sub display_characters {
684 # This returns a display string denoting the input parameter @_, each
685 # entry of which is a single character in the range 0-255. The first part
686 # of the output is a string of the characters in @_ that are ASCII
687 # graphics, and hence unambiguously displayable. They are given by code
688 # point order. The second part is the remaining code points, the ordinals
689 # of which are each displayed as 2-digit hex. Blanks are inserted so as
690 # to keep anything from the first part looking like a 2-digit hex number.
693 my @chars = sort { ord $a <=> ord $b } @_;
698 push @chars, chr(258); # This sentinel simplifies the loop termination
700 foreach my $i (0 .. @chars - 1) {
701 my $char = $chars[$i];
705 # We avoid using [:posix:] classes, as these are being tested in this
706 # file. Each equivalence class below is for things that can appear in
707 # a range; those that can't be in a range have class -1. 0 for those
708 # which should be output in hex; and >0 for the other ranges
709 if ($char =~ /[A-Z]/) {
712 elsif ($char =~ /[a-z]/) {
715 elsif ($char =~ /[0-9]/) {
718 elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
719 $class = -1; # Punct never appears in a range
722 $class = 0; # Output in hex
725 if (! defined $range_start) {
730 $range_start = ord $char;
731 $start_class = $class;
733 } # A range ends if not consecutive, or the class-type changes
734 elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
735 || $class != $start_class)
738 # Here, the current character is not in the range. This means the
739 # previous character must have been. Output the range up through
741 my $range_length = $range_end - $range_start + 1;
742 if ($start_class > 0) {
743 $output .= " " . chr($range_start);
744 $output .= "-" . chr($range_end) if $range_length > 1;
747 $hex .= sprintf(" %02X", $range_start);
748 $hex .= sprintf("-%02X", $range_end) if $range_length > 1;
751 # Handle the new current character, as potentially beginning a new
759 $hex =~ s/^ // if ! length $output;
760 return "$output$hex";
764 my ($Locale, $i, $pass_fail, $message) = @_;
766 $message = " ($message)" if $message;
767 unless ($pass_fail) {
768 $Problem{$i}{$Locale} = 1;
769 debug "# failed $i ($test_names{$i}) with locale '$Locale'$message\n";
771 push @{$Okay{$i}}, $Locale;
775 sub report_multi_result {
776 my ($Locale, $i, $results_ref) = @_;
778 # $results_ref points to an array, each element of which is a character that was
779 # in error for this test numbered '$i'. If empty, the test passed
783 $message = join " ", "for", display_characters(@$results_ref);
785 report_result($Locale, $i, @$results_ref == 0, $message);
788 my $first_locales_test_number = $final_without_setlocale + 1;
789 my $locales_test_number;
790 my $not_necessarily_a_problem_test_number;
791 my $first_casing_test_number;
792 my $final_casing_test_number;
793 my %setlocale_failed; # List of locales that setlocale() didn't work on
795 foreach $Locale (@Locale) {
796 $locales_test_number = $first_locales_test_number - 1;
797 debug "# Locale = $Locale\n";
799 unless (setlocale(&POSIX::LC_ALL, $Locale)) {
800 $setlocale_failed{$Locale} = $Locale;
804 # We test UTF-8 locales only under ':not_characters'; otherwise they have
805 # documented deficiencies. Non- UTF-8 locales are tested only under plain
806 # 'use locale', as otherwise we would have to convert everything in them
808 my $is_utf8_locale = $Locale =~ /UTF-?8/i;
810 my %UPPER = (); # All alpha X for which uc(X) == X and lc(X) != X
811 my %lower = (); # All alpha X for which lc(X) == X and uc(X) != X
812 my %BoThCaSe = (); # All alpha X for which uc(X) == lc(X) == X
814 if (! $is_utf8_locale) {
816 @Alnum_ = sort grep /\w/, map { chr } 0..255;
817 debug "# w = ", join("",@Alnum_), "\n";
818 @Digit_ = grep /\d/, map { chr } 0..255;
820 # Sieve the uppercase and the lowercase.
823 if (/[^\d_]/) { # skip digits and the _
834 use locale ':not_characters';
835 @Alnum_ = sort grep /\w/, map { chr } 0..255;
836 @Digit_ = grep /\d/, map { chr } 0..255;
837 debug "# w = ", join("",@Alnum_), "\n";
839 if (/[^\d_]/) { # skip digits and the _
849 foreach (keys %UPPER) {
850 $BoThCaSe{$_}++ if exists $lower{$_};
852 foreach (keys %lower) {
853 $BoThCaSe{$_}++ if exists $UPPER{$_};
855 foreach (keys %BoThCaSe) {
860 debug "# UPPER = ", display_characters(keys %UPPER), "\n";
861 debug "# lower = ", display_characters(keys %lower), "\n";
862 debug "# BoThCaSe = ", display_characters(keys %BoThCaSe), "\n";
866 foreach my $x (sort keys %UPPER) {
869 if ($is_utf8_locale) {
870 use locale ':not_characters';
871 $ok = $x =~ /[[:upper:]]/;
872 $fold_ok = $x =~ /[[:lower:]]/i;
876 $ok = $x =~ /[[:upper:]]/;
877 $fold_ok = $x =~ /[[:lower:]]/i;
879 push @failures, $x unless $ok;
880 push @fold_failures, $x unless $fold_ok;
882 $locales_test_number++;
883 $first_casing_test_number = $locales_test_number;
884 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches all alpha X for which uc(X) == X and lc(X) != X';
885 report_multi_result($Locale, $locales_test_number, \@failures);
887 $locales_test_number++;
889 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i matches all alpha X for which uc(X) == X and lc(X) != X';
890 report_multi_result($Locale, $locales_test_number, \@fold_failures);
893 undef @fold_failures;
895 foreach my $x (sort keys %lower) {
898 if ($is_utf8_locale) {
899 use locale ':not_characters';
900 $ok = $x =~ /[[:lower:]]/;
901 $fold_ok = $x =~ /[[:upper:]]/i;
905 $ok = $x =~ /[[:lower:]]/;
906 $fold_ok = $x =~ /[[:upper:]]/i;
908 push @failures, $x unless $ok;
909 push @fold_failures, $x unless $fold_ok;
912 $locales_test_number++;
913 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/ matches all alpha X for which lc(X) == X and uc(X) != X';
914 report_multi_result($Locale, $locales_test_number, \@failures);
916 $locales_test_number++;
917 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/i matches all alpha X for which lc(X) == X and uc(X) != X';
918 report_multi_result($Locale, $locales_test_number, \@fold_failures);
920 { # Find the alphabetic characters that are not considered alphabetics
921 # in the default (C) locale.
926 for (keys %UPPER, keys %lower, keys %BoThCaSe) {
927 push(@Added_alpha, $_) if (/\W/);
931 @Added_alpha = sort @Added_alpha;
933 debug "# Added_alpha = ", display_characters(@Added_alpha), "\n";
935 # Cross-check the whole 8-bit character set.
937 ++$locales_test_number;
939 $test_names{$locales_test_number} = 'Verify that \w and [:word:] are identical';
940 for (map { chr } 0..255) {
941 if ($is_utf8_locale) {
942 use locale ':not_characters';
943 push @f, $_ unless /[[:word:]]/ == /\w/;
946 push @f, $_ unless /[[:word:]]/ == /\w/;
949 report_multi_result($Locale, $locales_test_number, \@f);
951 ++$locales_test_number;
953 $test_names{$locales_test_number} = 'Verify that \d and [:digit:] are identical';
954 for (map { chr } 0..255) {
955 if ($is_utf8_locale) {
956 use locale ':not_characters';
957 push @f, $_ unless /[[:digit:]]/ == /\d/;
960 push @f, $_ unless /[[:digit:]]/ == /\d/;
963 report_multi_result($Locale, $locales_test_number, \@f);
965 ++$locales_test_number;
967 $test_names{$locales_test_number} = 'Verify that \s and [:space:] are identical';
968 for (map { chr } 0..255) {
969 if ($is_utf8_locale) {
970 use locale ':not_characters';
971 push @f, $_ unless /[[:space:]]/ == /\s/;
974 push @f, $_ unless /[[:space:]]/ == /\s/;
977 report_multi_result($Locale, $locales_test_number, \@f);
979 ++$locales_test_number;
981 $test_names{$locales_test_number} = 'Verify that [:posix:] and [:^posix:] are mutually exclusive';
982 for (map { chr } 0..255) {
983 if ($is_utf8_locale) {
984 use locale ':not_characters';
985 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
986 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
987 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
988 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
989 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
990 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
991 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
992 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
993 (/[[:print:]]/ xor /[[:^print:]]/) ||
994 (/[[:space:]]/ xor /[[:^space:]]/) ||
995 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
996 (/[[:word:]]/ xor /[[:^word:]]/) ||
997 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
999 # effectively is what [:cased:] would be if it existed.
1000 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1003 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1004 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1005 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1006 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1007 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1008 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1009 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1010 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1011 (/[[:print:]]/ xor /[[:^print:]]/) ||
1012 (/[[:space:]]/ xor /[[:^space:]]/) ||
1013 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1014 (/[[:word:]]/ xor /[[:^word:]]/) ||
1015 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1016 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1019 report_multi_result($Locale, $locales_test_number, \@f);
1021 # The rules for the relationships are given in:
1022 # http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
1024 ++$locales_test_number;
1026 $test_names{$locales_test_number} = 'Verify that [:lower:] is a subset of [:alpha:]';
1027 for (map { chr } 0..255) {
1028 if ($is_utf8_locale) {
1029 use locale ':not_characters';
1030 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1033 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1036 report_multi_result($Locale, $locales_test_number, \@f);
1038 ++$locales_test_number;
1040 $test_names{$locales_test_number} = 'Verify that [:upper:] is a subset of [:alpha:]';
1041 for (map { chr } 0..255) {
1042 if ($is_utf8_locale) {
1043 use locale ':not_characters';
1044 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1047 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1050 report_multi_result($Locale, $locales_test_number, \@f);
1052 ++$locales_test_number;
1054 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i is a subset of [:alpha:]';
1055 for (map { chr } 0..255) {
1056 if ($is_utf8_locale) {
1057 use locale ':not_characters';
1058 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1061 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1064 report_multi_result($Locale, $locales_test_number, \@f);
1066 ++$locales_test_number;
1068 $test_names{$locales_test_number} = 'Verify that [:alpha:] is a subset of [:alnum:]';
1069 for (map { chr } 0..255) {
1070 if ($is_utf8_locale) {
1071 use locale ':not_characters';
1072 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1075 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1078 report_multi_result($Locale, $locales_test_number, \@f);
1080 ++$locales_test_number;
1082 $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:alnum:]';
1083 for (map { chr } 0..255) {
1084 if ($is_utf8_locale) {
1085 use locale ':not_characters';
1086 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1089 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1092 report_multi_result($Locale, $locales_test_number, \@f);
1094 ++$locales_test_number;
1096 $test_names{$locales_test_number} = 'Verify that [:digit:] matches either 10 or 20 code points';
1097 report_result($Locale, $locales_test_number, @Digit_ == 10 || @Digit_ ==20);
1099 ++$locales_test_number;
1101 $test_names{$locales_test_number} = 'Verify that [:digit:] (if is 10 code points) is a subset of [:xdigit:]';
1102 if (@Digit_ == 10) {
1103 for (map { chr } 0..255) {
1104 if ($is_utf8_locale) {
1105 use locale ':not_characters';
1106 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1109 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1113 report_multi_result($Locale, $locales_test_number, \@f);
1115 ++$locales_test_number;
1117 $test_names{$locales_test_number} = 'Verify that [:alnum:] is a subset of [:graph:]';
1118 for (map { chr } 0..255) {
1119 if ($is_utf8_locale) {
1120 use locale ':not_characters';
1121 push @f, $_ if /[[:alnum:]]/ and ! /[[:graph:]]/;
1124 push @f, $_ if /[[:alnum:]]/ and ! /[[:graph:]]/;
1127 report_multi_result($Locale, $locales_test_number, \@f);
1129 # Note that xdigit doesn't have to be a subset of alnum
1131 ++$locales_test_number;
1133 $test_names{$locales_test_number} = 'Verify that [:xdigit:] is a subset of [:graph:]';
1134 for (map { chr } 0..255) {
1135 if ($is_utf8_locale) {
1136 use locale ':not_characters';
1137 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1140 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1143 report_multi_result($Locale, $locales_test_number, \@f);
1145 ++$locales_test_number;
1147 $test_names{$locales_test_number} = 'Verify that [:punct:] is a subset of [:graph:]';
1148 for (map { chr } 0..255) {
1149 if ($is_utf8_locale) {
1150 use locale ':not_characters';
1151 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1154 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1157 report_multi_result($Locale, $locales_test_number, \@f);
1159 ++$locales_test_number;
1161 $test_names{$locales_test_number} = 'Verify that [:blank:] is a subset of [:space:]';
1162 for (map { chr } 0..255) {
1163 if ($is_utf8_locale) {
1164 use locale ':not_characters';
1165 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1168 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1171 report_multi_result($Locale, $locales_test_number, \@f);
1173 ++$locales_test_number;
1175 $test_names{$locales_test_number} = 'Verify that [:graph:] is a subset of [:print:]';
1176 for (map { chr } 0..255) {
1177 if ($is_utf8_locale) {
1178 use locale ':not_characters';
1179 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1182 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1185 report_multi_result($Locale, $locales_test_number, \@f);
1187 ++$locales_test_number;
1189 $test_names{$locales_test_number} = 'Verify that isn\'t both [:cntrl:] and [:print:]';
1190 for (map { chr } 0..255) {
1191 if ($is_utf8_locale) {
1192 use locale ':not_characters';
1193 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1196 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1199 report_multi_result($Locale, $locales_test_number, \@f);
1201 ++$locales_test_number;
1203 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alnum:] and [:punct:]';
1204 for (map { chr } 0..255) {
1205 if ($is_utf8_locale) {
1206 use locale ':not_characters';
1207 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1210 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1213 report_multi_result($Locale, $locales_test_number, \@f);
1215 ++$locales_test_number;
1217 $test_names{$locales_test_number} = 'Verify that isn\'t both [:xdigit:] and [:punct:]';
1218 for (map { chr } 0..255) {
1219 if ($is_utf8_locale) {
1220 use locale ':not_characters';
1221 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1224 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1227 report_multi_result($Locale, $locales_test_number, \@f);
1229 ++$locales_test_number;
1231 $test_names{$locales_test_number} = 'Verify that isn\'t both [:graph:] and [:space:]';
1232 for (map { chr } 0..255) {
1233 if ($is_utf8_locale) {
1234 use locale ':not_characters';
1235 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1238 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1241 report_multi_result($Locale, $locales_test_number, \@f);
1243 $final_casing_test_number = $locales_test_number;
1245 # Test for read-only scalars' locale vs non-locale comparisons.
1251 if ($is_utf8_locale) {
1252 use locale ':not_characters';
1253 $ok = ($a cmp "qwerty") == 0;
1257 $ok = ($a cmp "qwerty") == 0;
1259 report_result($Locale, ++$locales_test_number, $ok);
1260 $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
1264 my ($from, $to, $lesser, $greater,
1265 @test, %test, $test, $yes, $no, $sign);
1267 ++$locales_test_number;
1268 $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
1269 $not_necessarily_a_problem_test_number = $locales_test_number;
1272 $from = int(($_*@Alnum_)/10);
1273 $to = $from + int(@Alnum_/10);
1274 $to = $#Alnum_ if ($to > $#Alnum_);
1275 $lesser = join('', @Alnum_[$from..$to]);
1276 # Select a slice one character on.
1278 $to = $#Alnum_ if ($to > $#Alnum_);
1279 $greater = join('', @Alnum_[$from..$to]);
1280 if ($is_utf8_locale) {
1281 use locale ':not_characters';
1282 ($yes, $no, $sign) = ($lesser lt $greater
1284 : ("not ", " ", -1));
1288 ($yes, $no, $sign) = ($lesser lt $greater
1290 : ("not ", " ", -1));
1292 # all these tests should FAIL (return 0). Exact lt or gt cannot
1293 # be tested because in some locales, say, eacute and E may test
1297 $no.' ($lesser le $greater)', # 1
1298 'not ($lesser ne $greater)', # 2
1299 ' ($lesser eq $greater)', # 3
1300 $yes.' ($lesser ge $greater)', # 4
1301 $yes.' ($lesser ge $greater)', # 5
1302 $yes.' ($greater le $lesser )', # 7
1303 'not ($greater ne $lesser )', # 8
1304 ' ($greater eq $lesser )', # 9
1305 $no.' ($greater ge $lesser )', # 10
1306 'not (($lesser cmp $greater) == -($sign))' # 11
1308 @test{@test} = 0 x @test;
1310 for my $ti (@test) {
1311 if ($is_utf8_locale) {
1312 use locale ':not_characters';
1313 $test{$ti} = eval $ti;
1316 # Already in 'use locale';
1317 $test{$ti} = eval $ti;
1319 $test ||= $test{$ti}
1321 report_result($Locale, $locales_test_number, $test == 0);
1323 debug "# lesser = '$lesser'\n";
1324 debug "# greater = '$greater'\n";
1325 debug "# lesser cmp greater = ",
1326 $lesser cmp $greater, "\n";
1327 debug "# greater cmp lesser = ",
1328 $greater cmp $lesser, "\n";
1329 debug "# (greater) from = $from, to = $to\n";
1330 for my $ti (@test) {
1331 debugf("# %-40s %-4s", $ti,
1332 $test{$ti} ? 'FAIL' : 'ok');
1333 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
1334 debugf("(%s == %4d)", $1, eval $1);
1367 if (! $is_utf8_locale) {
1370 my ($x, $y) = (1.23, 1.23);
1373 printf ''; # printf used to reset locale to "C"
1378 my $z = sprintf ''; # sprintf used to reset locale to "C"
1385 local $SIG{__WARN__} =
1391 # The == (among other ops) used to warn for locales
1392 # that had something else than "." as the radix character.
1413 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1415 $ok14 = $ok15 = $ok16 = 1; # Skip for non-utf8 locales
1419 use locale ':not_characters';
1421 my ($x, $y) = (1.23, 1.23);
1423 printf ''; # printf used to reset locale to "C"
1428 my $z = sprintf ''; # sprintf used to reset locale to "C"
1434 local $SIG{__WARN__} =
1457 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1460 # Look for non-ASCII error messages, and verify that the first
1461 # such is in UTF-8 (the others almost certainly will be like the
1464 foreach my $err (keys %!) {
1466 $! = eval "&Errno::$err"; # Convert to strerror() output
1467 my $strerror = "$!";
1468 if ("$strerror" =~ /\P{ASCII}/) {
1469 my $utf8_strerror = $strerror;
1470 utf8::upgrade($utf8_strerror);
1472 # If $! was already in UTF-8, the upgrade was a no-op;
1473 # otherwise they will be different byte strings.
1475 $ok14 = $utf8_strerror eq $strerror;
1480 # Similarly, we verify that a non-ASCII radix is in UTF-8. This
1481 # also catches if there is a disparity between sprintf and
1484 my $string_g = "$g";
1486 my $utf8_string_g = "$g";
1487 utf8::upgrade($utf8_string_g);
1489 my $utf8_sprintf_g = sprintf("%g", $g);
1490 utf8::upgrade($utf8_sprintf_g);
1492 $ok15 = $utf8_string_g eq $string_g;
1493 $ok16 = $utf8_sprintf_g eq $string_g;
1497 report_result($Locale, ++$locales_test_number, $ok1);
1498 $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
1499 my $first_a_test = $locales_test_number;
1501 debug "# $first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
1503 report_result($Locale, ++$locales_test_number, $ok2);
1504 $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
1506 my $first_c_test = $locales_test_number;
1508 report_result($Locale, ++$locales_test_number, $ok3);
1509 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
1511 report_result($Locale, ++$locales_test_number, $ok4);
1512 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
1514 report_result($Locale, ++$locales_test_number, $ok5);
1515 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
1517 debug "# $first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
1519 report_result($Locale, ++$locales_test_number, $ok6);
1520 $test_names{$locales_test_number} = 'Verify that can assign stringified under inner no-locale block';
1521 my $first_e_test = $locales_test_number;
1523 report_result($Locale, ++$locales_test_number, $ok7);
1524 $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
1526 report_result($Locale, ++$locales_test_number, $ok8);
1527 $test_names{$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
1529 debug "# $first_e_test..$locales_test_number: \$e = $e, no locale\n";
1531 report_result($Locale, ++$locales_test_number, $ok9);
1532 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
1533 my $first_f_test = $locales_test_number;
1535 report_result($Locale, ++$locales_test_number, $ok10);
1536 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
1538 report_result($Locale, ++$locales_test_number, $ok11);
1539 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar and an intervening sprintf';
1541 report_result($Locale, ++$locales_test_number, $ok12);
1542 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix can participate in an addition and function call as numeric';
1544 report_result($Locale, ++$locales_test_number, $ok13);
1545 $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
1547 report_result($Locale, ++$locales_test_number, $ok14);
1548 $test_names{$locales_test_number} = 'Verify that non-ASCII UTF-8 error messages are in UTF-8';
1550 report_result($Locale, ++$locales_test_number, $ok15);
1551 $test_names{$locales_test_number} = 'Verify that a number with a UTF-8 radix has a UTF-8 stringification';
1553 report_result($Locale, ++$locales_test_number, $ok16);
1554 $test_names{$locales_test_number} = 'Verify that a sprintf of a number with a UTF-8 radix yields UTF-8';
1556 debug "# $first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
1558 # Does taking lc separately differ from taking
1559 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
1560 # The bug was in the caching of the 'o'-magic.
1561 if (! $is_utf8_locale) {
1567 return $lc0 cmp $lc1;
1571 return lc($_[0]) cmp lc($_[1]);
1578 report_result($Locale, ++$locales_test_number,
1579 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
1580 lcA($x, $z) == 0 && lcB($x, $z) == 0);
1583 use locale ':not_characters';
1588 return $lc0 cmp $lc1;
1592 return lc($_[0]) cmp lc($_[1]);
1599 report_result($Locale, ++$locales_test_number,
1600 lcC($x, $y) == 1 && lcD($x, $y) == 1 ||
1601 lcC($x, $z) == 0 && lcD($x, $z) == 0);
1603 $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
1605 # Does lc of an UPPER (if different from the UPPER) match
1606 # case-insensitively the UPPER, and does the UPPER match
1607 # case-insensitively the lc of the UPPER. And vice versa.
1611 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
1614 ++$locales_test_number;
1615 $test_names{$locales_test_number} = 'Verify case insensitive matching works';
1616 foreach my $x (sort keys %UPPER) {
1617 if (! $is_utf8_locale) {
1619 next unless uc $y eq $x;
1620 print "# UPPER $x lc $y ",
1621 $x =~ /$y/i ? 1 : 0, " ",
1622 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1624 # If $x and $y contain regular expression characters
1625 # AND THEY lowercase (/i) to regular expression characters,
1626 # regcomp() will be mightily confused. No, the \Q doesn't
1627 # help here (maybe regex engine internal lowercasing
1628 # is done after the \Q?) An example of this happening is
1629 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
1630 # the chr(173) (the "[") is the lowercase of the chr(235).
1632 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
1633 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
1634 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
1635 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
1636 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
1637 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
1639 # Similar things can happen even under (bastardised)
1640 # non-EBCDIC locales: in many European countries before the
1641 # advent of ISO 8859-x nationally customised versions of
1642 # ISO 646 were devised, reusing certain punctuation
1643 # characters for modified characters needed by the
1644 # country/language. For example, the "|" might have
1645 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
1647 if ($x =~ $re || $y =~ $re) {
1648 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1651 # With utf8 both will fail since the locale concept
1652 # of upper/lower does not work well in Unicode.
1653 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
1655 # fc is not a locale concept, so Perl uses lc for it.
1656 push @f, $x unless lc $x eq fc $x;
1659 use locale ':not_characters';
1661 next unless uc $y eq $x;
1662 print "# UPPER $x lc $y ",
1663 $x =~ /$y/i ? 1 : 0, " ",
1664 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1666 # Here, we can fully test things, unlike plain 'use locale',
1667 # because this form does work well with Unicode
1668 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1670 # The places where Unicode's lc is different from fc are
1671 # skipped here by virtue of the 'next unless uc...' line above
1672 push @f, $x unless lc $x eq fc $x;
1676 foreach my $x (sort keys %lower) {
1677 if (! $is_utf8_locale) {
1679 next unless lc $y eq $x;
1680 print "# lower $x uc $y ",
1681 $x =~ /$y/i ? 1 : 0, " ",
1682 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1683 if ($x =~ $re || $y =~ $re) { # See above.
1684 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1687 # With utf8 both will fail since the locale concept
1688 # of upper/lower does not work well in Unicode.
1689 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
1691 push @f, $x unless lc $x eq fc $x;
1694 use locale ':not_characters';
1696 next unless lc $y eq $x;
1697 print "# lower $x uc $y ",
1698 $x =~ /$y/i ? 1 : 0, " ",
1699 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1700 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1702 push @f, $x unless lc $x eq fc $x;
1705 report_multi_result($Locale, $locales_test_number, \@f);
1711 ++$locales_test_number;
1712 $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
1714 my $radix = POSIX::localeconv()->{decimal_point};
1716 "3.14e+9", "3${radix}14e+9", "3.14e-9", "3${radix}14e-9",
1717 "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
1720 if (! $is_utf8_locale) {
1722 for my $num (@nums) {
1724 unless sprintf("%g", $num) =~ /3.+14/;
1728 use locale ':not_characters';
1729 for my $num (@nums) {
1731 unless sprintf("%g", $num) =~ /3.+14/;
1735 report_result($Locale, $locales_test_number, @f == 0);
1737 print "# failed $locales_test_number locale '$Locale' numbers @f\n"
1742 my $final_locales_test_number = $locales_test_number;
1744 # Recount the errors.
1746 foreach ($first_locales_test_number..$final_locales_test_number) {
1747 if (%setlocale_failed) {
1750 elsif ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
1751 if (defined $not_necessarily_a_problem_test_number
1752 && $_ == $not_necessarily_a_problem_test_number)
1754 print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
1755 print "# It usually indicates a problem in the environment,\n";
1756 print "# not in Perl itself.\n";
1758 if ($Okay{$_} && ($_ >= $first_casing_test_number
1759 && $_ <= $final_casing_test_number))
1761 # Round to nearest .1%
1762 my $percent_fail = (int(.5 + (1000 * scalar(keys $Problem{$_})
1763 / scalar(@Locale))))
1765 if (! $debug && $percent_fail < $acceptable_fold_failure_percentage)
1767 $test_names{$_} .= 'TODO';
1768 print "# ", 100 - $percent_fail, "% of locales pass the following test, so it is likely that the failures\n";
1769 print "# are errors in the locale definitions. The test is marked TODO, as the\n";
1770 print "# problem is not likely to be Perl's\n";
1775 print "# The code points that had this failure are given above. Look for lines\n";
1776 print "# that match 'failed $_'\n";
1779 print "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
1780 print "# Then look at that output for lines that match 'failed $_'\n";
1785 if (defined $test_names{$_}) {
1786 # If TODO is in the test name, make it thus
1787 my $todo = $test_names{$_} =~ s/TODO\s*//;
1788 print " $test_names{$_}";
1789 print " # TODO" if $todo;
1794 $test_num = $final_locales_test_number;
1799 local $SIG{__WARN__} = sub {
1800 $warned = $_[0] =~ /uninitialized/;
1802 my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy");
1803 ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized");
1806 # Test that tainting and case changing works on utf8 strings. These tests are
1807 # placed last to avoid disturbing the hard-coded test numbers that existed at
1808 # the time these were added above this in this file.
1809 # This also tests that locale overrides unicode_strings in the same scope for
1811 setlocale(&POSIX::LC_ALL, "C");
1814 use feature 'unicode_strings';
1816 foreach my $function ("uc", "ucfirst", "lc", "lcfirst", "fc") {
1817 my @list; # List of code points to test for $function
1819 # Used to calculate the changed case for ASCII characters by using the
1820 # ord, instead of using one of the functions under test.
1821 my $ascii_case_change_delta;
1822 my $above_latin1_case_change_delta; # Same for the specific ords > 255
1825 # We test an ASCII character, which should change case and be tainted;
1826 # a Latin1 character, which shouldn't change case under this C locale,
1828 # an above-Latin1 character that when the case is changed would cross
1829 # the 255/256 boundary, so doesn't change case and isn't tainted
1830 # (the \x{149} is one of these, but changes into 2 characters, the
1831 # first one of which doesn't cross the boundary.
1832 # the final one in each list is an above-Latin1 character whose case
1833 # does change, and shouldn't be tainted. The code below uses its
1834 # position in its list as a marker to indicate that it, unlike the
1835 # other code points above ASCII, has a successful case change
1836 if ($function =~ /^u/) {
1837 @list = ("", "a", "\xe0", "\xff", "\x{fb00}", "\x{149}", "\x{101}");
1838 $ascii_case_change_delta = -32;
1839 $above_latin1_case_change_delta = -1;
1842 @list = ("", "A", "\xC0", "\x{17F}", "\x{100}");
1843 $ascii_case_change_delta = +32;
1844 $above_latin1_case_change_delta = +1;
1846 foreach my $is_utf8_locale (0 .. 1) {
1847 foreach my $j (0 .. $#list) {
1848 my $char = $list[$j];
1850 for my $encoded_in_utf8 (0 .. 1) {
1853 if (! $is_utf8_locale) {
1854 $should_be = ($j == $#list)
1855 ? chr(ord($char) + $above_latin1_case_change_delta)
1856 : (length $char == 0 || ord($char) > 127)
1858 : chr(ord($char) + $ascii_case_change_delta);
1860 # This monstrosity is in order to avoid using an eval,
1861 # which might perturb the results
1862 $changed = ($function eq "uc")
1864 : ($function eq "ucfirst")
1866 : ($function eq "lc")
1868 : ($function eq "lcfirst")
1870 : ($function eq "fc")
1872 : die("Unexpected function \"$function\"");
1878 # For utf8-locales the case changing functions
1879 # should work just like they do outside of locale.
1880 # Can use eval here because not testing it when
1882 $should_be = eval "$function('$char')";
1883 die "Unexpected eval error $@ from 'eval \"$function('$char')\"'" if $@;
1886 use locale ':not_characters';
1887 $changed = ($function eq "uc")
1889 : ($function eq "ucfirst")
1891 : ($function eq "lc")
1893 : ($function eq "lcfirst")
1895 : ($function eq "fc")
1897 : die("Unexpected function \"$function\"");
1899 ok($changed eq $should_be,
1900 "$function(\"$char\") in C locale "
1901 . (($is_utf8_locale)
1902 ? "(use locale ':not_characters'"
1904 . (($encoded_in_utf8)
1905 ? "; encoded in utf8)"
1906 : "; not encoded in utf8)")
1907 . " should be \"$should_be\", got \"$changed\"");
1909 # Tainting shouldn't happen for utf8 locales, empty
1910 # strings, or those characters above 255.
1911 (! $is_utf8_locale && length($char) > 0 && ord($char) < 256)
1912 ? check_taint($changed)
1913 : check_taint_not($changed);
1915 # Use UTF-8 next time through the loop
1916 utf8::upgrade($char);
1923 # Give final advice.
1927 foreach ($first_locales_test_number..$final_locales_test_number) {
1929 my @f = sort keys %{ $Problem{$_} };
1930 my $f = join(" ", @f);
1931 $f =~ s/(.{50,60}) /$1\n#\t/g;
1934 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
1936 "# on your system may have errors because the locale test $_\n",
1937 "# \"$test_names{$_}\"\n",
1938 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
1942 # If your users are not using these locales you are safe for the moment,
1943 # but please report this failure first to perlbug\@perl.com using the
1944 # perlbug script (as described in the INSTALL file) so that the exact
1945 # details of the failures can be sorted out first and then your operating
1946 # system supplier can be alerted about these anomalies.
1953 # Tell which locales were okay and which were not.
1958 foreach my $l (@Locale) {
1960 if ($setlocale_failed{$l}) {
1965 ($first_locales_test_number..$final_locales_test_number)
1967 $p++ if $Problem{$t}{$l};
1970 push @s, $l if $p == 0;
1971 push @F, $l unless $p == 0;
1975 my $s = join(" ", @s);
1976 $s =~ s/(.{50,60}) /$1\n#\t/g;
1979 "# The following locales\n#\n",
1981 "# tested okay.\n#\n",
1983 warn "# None of your locales were fully okay.\n";
1987 my $F = join(" ", @F);
1988 $F =~ s/(.{50,60}) /$1\n#\t/g;
1991 "# The following locales\n#\n",
1993 "# had problems.\n#\n",
1994 "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
1996 warn "# None of your locales were broken.\n";
2000 print "1..$test_num\n";