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 # Some Windows machines are defective in every in every locale but the C,
33 # calling \t printable; superscripts to be digits, etc. See
34 # http://markmail.org/message/5jwam4xsx4amsdnv
35 # (There aren't 1000 locales currently in existence, so 99.9 works)
36 my $acceptable_fold_failure_percentage = $^O eq 'MSWin32' ? 99.9 : 5;
40 my $dumper = Dumpvalue->new(
47 my($mess) = join "", @_;
49 print $dumper->stringify($mess,1), "\n";
56 my $have_setlocale = 0;
59 import POSIX ':locale_h';
63 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
64 # and mingw32 uses said silly CRT
65 # This doesn't seem to be an issue any more, at least on Windows XP,
66 # so re-enable the tests for Windows XP onwards.
67 my $winxp = ($^O eq 'MSWin32' && defined &Win32::GetOSVersion &&
68 join('.', (Win32::GetOSVersion())[1..2]) >= 5.1);
69 $have_setlocale = 0 if ((($^O eq 'MSWin32' && !$winxp) || $^O eq 'NetWare') &&
70 $Config{cc} =~ /^(cl|gcc)/i);
72 # UWIN seems to loop after taint tests, just skip for now
73 $have_setlocale = 0 if ($^O =~ /^uwin/);
80 my ($result, $message) = @_;
81 $message = "" unless defined $message;
83 print 'not ' unless ($result);
84 print "ok " . ++$test_num;
89 # First we'll do a lot of taint checking for locales.
90 # This is the easiest to test, actually, as any locale,
91 # even the default locale will taint under 'use locale'.
93 sub is_tainted { # hello, camel two.
94 no warnings 'uninitialized' ;
97 not eval { $dummy = join("", @_), kill 0; 1 }
100 sub check_taint ($;$) {
101 my $message_tail = $_[1] // "";
102 $message_tail = ": $message_tail" if $message_tail;
103 ok is_tainted($_[0]), "verify that is tainted$message_tail";
106 sub check_taint_not ($;$) {
107 my $message_tail = $_[1] // "";
108 $message_tail = ": $message_tail" if $message_tail;
109 ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
112 "\tb\t" =~ /^m?(\s)(.*)\1$/;
113 check_taint_not $&, "not tainted outside 'use locale'";
116 use locale; # engage locale and therefore locale taint.
122 check_taint ucfirst($a);
128 check_taint lcfirst($a);
131 check_taint_not sprintf('%e', 123.456);
132 check_taint_not sprintf('%f', 123.456);
133 check_taint_not sprintf('%g', 123.456);
134 check_taint_not sprintf('%d', 123.456);
135 check_taint_not sprintf('%x', 123.456);
137 $_ = $a; # untaint $_
139 $_ = uc($a); # taint $_
143 /(\w)/; # taint $&, $`, $', $+, $1.
151 /(.)/; # untaint $&, $`, $', $+, $1.
159 /(\W)/; # taint $&, $`, $', $+, $1.
167 /(\s)/; # taint $&, $`, $', $+, $1.
175 /(\S)/; # taint $&, $`, $', $+, $1.
183 $_ = $a; # untaint $_
187 /(b)/; # this must not taint
195 $_ = $a; # untaint $_
199 $b = uc($a); # taint $b
200 s/(.+)/$b/; # this must taint only the $_
210 $_ = $a; # untaint $_
212 s/(.+)/b/; # this must not taint
221 $b = $a; # untaint $b
223 ($b = $a) =~ s/\w/$&/;
224 check_taint $b; # $b should be tainted.
225 check_taint_not $a; # $a should be not.
227 $_ = $a; # untaint $_
229 s/(\w)/\l$1/; # this must taint
238 $_ = $a; # untaint $_
240 s/(\w)/\L$1/; # this must taint
249 $_ = $a; # untaint $_
251 s/(\w)/\u$1/; # this must taint
260 $_ = $a; # untaint $_
262 s/(\w)/\U$1/; # this must taint
271 # After all this tainting $a should be cool.
275 { # This is just the previous tests copied here with a different
276 # compile-time pragma.
278 use locale ':not_characters'; # engage restricted locale with different
283 check_taint_not uc($a);
284 check_taint_not "\U$a";
285 check_taint_not ucfirst($a);
286 check_taint_not "\u$a";
287 check_taint_not lc($a);
288 check_taint_not fc($a);
289 check_taint_not "\L$a";
290 check_taint_not "\F$a";
291 check_taint_not lcfirst($a);
292 check_taint_not "\l$a";
294 check_taint_not sprintf('%e', 123.456);
295 check_taint_not sprintf('%f', 123.456);
296 check_taint_not sprintf('%g', 123.456);
297 check_taint_not sprintf('%d', 123.456);
298 check_taint_not sprintf('%x', 123.456);
300 $_ = $a; # untaint $_
302 $_ = uc($a); # taint $_
306 /(\w)/; # taint $&, $`, $', $+, $1.
314 /(.)/; # untaint $&, $`, $', $+, $1.
322 /(\W)/; # taint $&, $`, $', $+, $1.
330 /(\s)/; # taint $&, $`, $', $+, $1.
338 /(\S)/; # taint $&, $`, $', $+, $1.
346 $_ = $a; # untaint $_
350 /(b)/; # this must not taint
358 $_ = $a; # untaint $_
362 $b = uc($a); # taint $b
363 s/(.+)/$b/; # this must taint only the $_
373 $_ = $a; # untaint $_
375 s/(.+)/b/; # this must not taint
384 $b = $a; # untaint $b
386 ($b = $a) =~ s/\w/$&/;
387 check_taint_not $b; # $b should be tainted.
388 check_taint_not $a; # $a should be not.
390 $_ = $a; # untaint $_
392 s/(\w)/\l$1/; # this must taint
401 $_ = $a; # untaint $_
403 s/(\w)/\L$1/; # this must taint
412 $_ = $a; # untaint $_
414 s/(\w)/\u$1/; # this must taint
423 $_ = $a; # untaint $_
425 s/(\w)/\U$1/; # this must taint
434 # After all this tainting $a should be cool.
439 # Here are in scope of 'use locale'
441 # I think we've seen quite enough of taint.
442 # Let us do some *real* locale work now,
443 # unless setlocale() is missing (i.e. minitest).
445 unless ($have_setlocale) {
446 print "1..$test_num\n";
450 # The test number before our first setlocale()
451 my $final_without_setlocale = $test_num;
455 debug "# Scanning for locales...\n";
457 # Note that it's okay that some languages have their native names
458 # capitalized here even though that's not "right". They are lowercased
459 # anyway later during the scanning process (and besides, some clueless
460 # vendor might have them capitalized erroneously anyway).
464 Arabic:ar:dz eg sa:6 arabic8
465 Brezhoneg Breton:br:fr:1 15
466 Bulgarski Bulgarian:bg:bg:5
467 Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
468 Hrvatski Croatian:hr:hr:2
469 Cymraeg Welsh:cy:cy:1 14 15
471 Dansk Danish:da:dk:1 15
472 Nederlands Dutch:nl:be nl:1 15
473 English American British:en:au ca gb ie nz us uk zw:1 15 cp850
475 Eesti Estonian:et:ee:4 6 13
476 Suomi Finnish:fi:fi:1 15
478 Deutsch German:de:at be ch de lu:1 15
479 Euskaraz Basque:eu:es fr:1 15
480 Galego Galician:gl:es:1 15
481 Ellada Greek:el:gr:7 g8
483 Greenlandic:kl:gl:4 6
484 Hebrew:iw:il:8 hebrew8
486 Indonesian:id:id:1 15
487 Gaeilge Irish:ga:IE:1 14 15
488 Italiano Italian:it:ch it:1 15
489 Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
491 Latine Latin:la:va:1 15
493 Lithuanian:lt:lt:4 6 13
494 Macedonian:mk:mk:1 15
497 Norsk Norwegian:no no\@nynorsk nb nn:no:1 15
499 Polski Polish:pl:pl:2
501 Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
502 Serbski Serbian:sr:yu:5
504 Slovene Slovenian:sl:si:2
505 Sqhip Albanian:sq:sq:1 15
506 Svenska Swedish:sv:fi se:1 15
508 Turkish:tr:tr:9 turkish8
512 if ($^O eq 'os390') {
513 # These cause heartburn. Broken locales?
514 $locales =~ s/Svenska Swedish:sv:fi se:1 15\n//;
515 $locales =~ s/Thai:th:th:11 tis620\n//;
518 sub in_utf8 () { $^H & 0x08 || (${^OPEN} || "") =~ /:utf8/ }
521 require "lib/locale/utf8";
523 require "lib/locale/latin1";
532 return if grep { $locale eq $_ } @Locale;
533 return unless setlocale(&POSIX::LC_ALL, $locale);
536 local $SIG{__WARN__} = sub {
537 $badutf8 = $_[0] =~ /Malformed UTF-8/;
539 $Locale =~ /UTF-?8/i;
543 ok(0, "Locale name contains malformed utf8");
546 push @Locale, $locale;
549 sub decode_encodings {
552 foreach (split(/ /, shift)) {
554 push @enc, "ISO8859-$1";
555 push @enc, "iso8859$1"; # HP
557 push @enc, "roman8"; # HP
561 push @enc, "$_.UTF-8";
564 if ($^O eq 'os390') {
565 push @enc, qw(IBM-037 IBM-819 IBM-1047);
574 trylocale("ISO8859-$_");
575 trylocale("iso8859$_");
576 trylocale("iso8859-$_");
577 trylocale("iso_8859_$_");
578 trylocale("isolatin$_");
579 trylocale("isolatin-$_");
580 trylocale("iso_latin_$_");
583 # Sanitize the environment so that we can run the external 'locale'
584 # program without the taint mode getting grumpy.
586 # $ENV{PATH} is special in VMS.
587 delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
589 # Other subversive stuff.
590 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
592 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
594 # It seems that /usr/bin/locale steadfastly outputs 8 bit data, which
595 # ain't great when we're running this testPERL_UNICODE= so that utf8
596 # locales will cause all IO hadles to default to (assume) utf8
597 next unless utf8::valid($_);
602 } elsif ($^O eq 'VMS' && defined($ENV{'SYS$I18N_LOCALE'}) && -d 'SYS$I18N_LOCALE') {
603 # The SYS$I18N_LOCALE logical name search list was not present on
604 # VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
605 opendir(LOCALES, "SYS\$I18N_LOCALE:");
606 while ($_ = readdir(LOCALES)) {
611 } elsif (($^O eq 'openbsd' || $^O eq 'bitrig' ) && -e '/usr/share/locale') {
613 # OpenBSD doesn't have a locale executable, so reading /usr/share/locale
614 # is much easier and faster than the last resort method.
616 opendir(LOCALES, '/usr/share/locale');
617 while ($_ = readdir(LOCALES)) {
624 # This is going to be slow.
626 foreach my $locale (split(/\n/, $locales)) {
627 my ($locale_name, $language_codes, $country_codes, $encodings) =
629 my @enc = decode_encodings($encodings);
630 foreach my $loc (split(/ /, $locale_name)) {
632 foreach my $enc (@enc) {
633 trylocale("$loc.$enc");
636 foreach my $enc (@enc) {
637 trylocale("$loc.$enc");
640 foreach my $lang (split(/ /, $language_codes)) {
642 foreach my $country (split(/ /, $country_codes)) {
643 my $lc = "${lang}_${country}";
645 foreach my $enc (@enc) {
646 trylocale("$lc.$enc");
648 my $lC = "${lang}_\U${country}";
650 foreach my $enc (@enc) {
651 trylocale("$lC.$enc");
658 setlocale(&POSIX::LC_ALL, "C");
660 if ($^O eq 'darwin') {
661 # Darwin 8/Mac OS X 10.4 and 10.5 have bad Basque locales: perl bug #35895,
662 # Apple bug ID# 4139653. It also has a problem in Byelorussian.
663 (my $v) = $Config{osvers} =~ /^(\d+)/;
664 if ($v >= 8 and $v < 10) {
665 debug "# Skipping eu_ES, be_BY locales -- buggy in Darwin\n";
666 @Locale = grep ! m/^(eu_ES(?:\..*)?|be_BY\.CP1131)$/, @Locale;
668 debug "# Skipping be_BY locales -- buggy in Darwin\n";
669 @Locale = grep ! m/^be_BY\.CP1131$/, @Locale;
673 @Locale = sort @Locale;
675 debug "# Locales =\n";
683 my @Added_alpha; # Alphas that aren't in the C locale.
686 sub display_characters {
687 # This returns a display string denoting the input parameter @_, each
688 # entry of which is a single character in the range 0-255. The first part
689 # of the output is a string of the characters in @_ that are ASCII
690 # graphics, and hence unambiguously displayable. They are given by code
691 # point order. The second part is the remaining code points, the ordinals
692 # of which are each displayed as 2-digit hex. Blanks are inserted so as
693 # to keep anything from the first part looking like a 2-digit hex number.
696 my @chars = sort { ord $a <=> ord $b } @_;
700 push @chars, chr(258); # This sentinel simplifies the loop termination
702 foreach my $i (0 .. @chars - 1) {
703 my $char = $chars[$i];
707 # We avoid using [:posix:] classes, as these are being tested in this
708 # file. Each equivalence class below is for things that can appear in
709 # a range; those that can't be in a range have class -1. 0 for those
710 # which should be output in hex; and >0 for the other ranges
711 if ($char =~ /[A-Z]/) {
714 elsif ($char =~ /[a-z]/) {
717 elsif ($char =~ /[0-9]/) {
720 # Uncomment to get literal punctuation displayed instead of hex
721 #elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
722 # $class = -1; # Punct never appears in a range
725 $class = 0; # Output in hex
728 if (! defined $range_start) {
730 $output .= " " . $char;
733 $range_start = ord $char;
734 $start_class = $class;
736 } # A range ends if not consecutive, or the class-type changes
737 elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
738 || $class != $start_class)
741 # Here, the current character is not in the range. This means the
742 # previous character must have been. Output the range up through
744 my $range_length = $range_end - $range_start + 1;
745 if ($start_class > 0) {
746 $output .= " " . chr($range_start);
747 $output .= "-" . chr($range_end) if $range_length > 1;
750 $output .= sprintf(" %02X", $range_start);
751 $output .= sprintf("-%02X", $range_end) if $range_length > 1;
754 # Handle the new current character, as potentially beginning a new
766 my ($Locale, $i, $pass_fail, $message) = @_;
768 $message = " ($message)" if $message;
769 unless ($pass_fail) {
770 $Problem{$i}{$Locale} = 1;
771 debug "# failed $i ($test_names{$i}) with locale '$Locale'$message\n";
773 push @{$Okay{$i}}, $Locale;
777 sub report_multi_result {
778 my ($Locale, $i, $results_ref) = @_;
780 # $results_ref points to an array, each element of which is a character that was
781 # in error for this test numbered '$i'. If empty, the test passed
785 $message = join " ", "for", display_characters(@$results_ref);
787 report_result($Locale, $i, @$results_ref == 0, $message);
790 my $first_locales_test_number = $final_without_setlocale + 1;
791 my $locales_test_number;
792 my $not_necessarily_a_problem_test_number;
793 my $first_casing_test_number;
794 my $final_casing_test_number;
795 my %setlocale_failed; # List of locales that setlocale() didn't work on
797 foreach $Locale (@Locale) {
798 $locales_test_number = $first_locales_test_number - 1;
800 debug "# Locale = $Locale\n";
802 unless (setlocale(&POSIX::LC_ALL, $Locale)) {
803 $setlocale_failed{$Locale} = $Locale;
807 # We test UTF-8 locales only under ':not_characters'; otherwise they have
808 # documented deficiencies. Non- UTF-8 locales are tested only under plain
809 # 'use locale', as otherwise we would have to convert everything in them
811 # The locale name doesn't necessarily have to have "utf8" in it to be a
812 # UTF-8 locale, but it works mostly.
813 my $is_utf8_locale = $Locale =~ /UTF-?8/i;
815 my %UPPER = (); # All alpha X for which uc(X) == X and lc(X) != X
816 my %lower = (); # All alpha X for which lc(X) == X and uc(X) != X
817 my %BoThCaSe = (); # All alpha X for which uc(X) == lc(X) == X
819 if (! $is_utf8_locale) {
821 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
822 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
823 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
824 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
825 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
826 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
827 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
828 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
829 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
830 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
831 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
832 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
833 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
834 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
835 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
837 # Sieve the uppercase and the lowercase.
839 for (@{$posixes{'word'}}) {
840 if (/[^\d_]/) { # skip digits and the _
851 use locale ':not_characters';
852 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
853 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
854 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
855 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
856 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
857 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
858 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
859 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
860 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
861 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
862 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
863 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
864 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
865 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
866 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
867 for (@{$posixes{'word'}}) {
868 if (/[^\d_]/) { # skip digits and the _
879 # Ordered, where possible, in groups of "this is a subset of the next
881 debug "# :upper: = ", display_characters(@{$posixes{'upper'}}), "\n";
882 debug "# :lower: = ", display_characters(@{$posixes{'lower'}}), "\n";
883 debug "# :cased: = ", display_characters(@{$posixes{'cased'}}), "\n";
884 debug "# :alpha: = ", display_characters(@{$posixes{'alpha'}}), "\n";
885 debug "# :alnum: = ", display_characters(@{$posixes{'alnum'}}), "\n";
886 debug "# w = ", display_characters(@{$posixes{'word'}}), "\n";
887 debug "# :graph: = ", display_characters(@{$posixes{'graph'}}), "\n";
888 debug "# :print: = ", display_characters(@{$posixes{'print'}}), "\n";
889 debug "# d = ", display_characters(@{$posixes{'digit'}}), "\n";
890 debug "# :xdigit: = ", display_characters(@{$posixes{'xdigit'}}), "\n";
891 debug "# :blank: = ", display_characters(@{$posixes{'blank'}}), "\n";
892 debug "# s = ", display_characters(@{$posixes{'space'}}), "\n";
893 debug "# :punct: = ", display_characters(@{$posixes{'punct'}}), "\n";
894 debug "# :cntrl: = ", display_characters(@{$posixes{'cntrl'}}), "\n";
895 debug "# :ascii: = ", display_characters(@{$posixes{'ascii'}}), "\n";
897 foreach (keys %UPPER) {
899 $BoThCaSe{$_}++ if exists $lower{$_};
901 foreach (keys %lower) {
902 $BoThCaSe{$_}++ if exists $UPPER{$_};
904 foreach (keys %BoThCaSe) {
910 foreach my $ord ( 0 .. 255 ) {
911 $Unassigned{chr $ord} = 1;
913 foreach my $class (keys %posixes) {
914 foreach my $char (@{$posixes{$class}}) {
915 delete $Unassigned{$char};
919 debug "# UPPER = ", display_characters(keys %UPPER), "\n";
920 debug "# lower = ", display_characters(keys %lower), "\n";
921 debug "# BoThCaSe = ", display_characters(keys %BoThCaSe), "\n";
922 debug "# Unassigned = ", display_characters(sort { ord $a <=> ord $b } keys %Unassigned), "\n";
926 foreach my $x (sort keys %UPPER) {
929 if ($is_utf8_locale) {
930 use locale ':not_characters';
931 $ok = $x =~ /[[:upper:]]/;
932 $fold_ok = $x =~ /[[:lower:]]/i;
936 $ok = $x =~ /[[:upper:]]/;
937 $fold_ok = $x =~ /[[:lower:]]/i;
939 push @failures, $x unless $ok;
940 push @fold_failures, $x unless $fold_ok;
942 $locales_test_number++;
943 $first_casing_test_number = $locales_test_number;
944 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches all alpha X for which uc(X) == X and lc(X) != X';
945 report_multi_result($Locale, $locales_test_number, \@failures);
947 $locales_test_number++;
949 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i matches all alpha X for which uc(X) == X and lc(X) != X';
950 report_multi_result($Locale, $locales_test_number, \@fold_failures);
953 undef @fold_failures;
955 foreach my $x (sort keys %lower) {
958 if ($is_utf8_locale) {
959 use locale ':not_characters';
960 $ok = $x =~ /[[:lower:]]/;
961 $fold_ok = $x =~ /[[:upper:]]/i;
965 $ok = $x =~ /[[:lower:]]/;
966 $fold_ok = $x =~ /[[:upper:]]/i;
968 push @failures, $x unless $ok;
969 push @fold_failures, $x unless $fold_ok;
972 $locales_test_number++;
973 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/ matches all alpha X for which lc(X) == X and uc(X) != X';
974 report_multi_result($Locale, $locales_test_number, \@failures);
976 $locales_test_number++;
977 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/i matches all alpha X for which lc(X) == X and uc(X) != X';
978 report_multi_result($Locale, $locales_test_number, \@fold_failures);
980 { # Find the alphabetic characters that are not considered alphabetics
981 # in the default (C) locale.
986 for (keys %UPPER, keys %lower, keys %BoThCaSe) {
987 push(@Added_alpha, $_) if (/\W/);
991 @Added_alpha = sort @Added_alpha;
993 debug "# Added_alpha = ", display_characters(@Added_alpha), "\n";
995 # Cross-check the whole 8-bit character set.
997 ++$locales_test_number;
999 $test_names{$locales_test_number} = 'Verify that \w and [:word:] are identical';
1000 for (map { chr } 0..255) {
1001 if ($is_utf8_locale) {
1002 use locale ':not_characters';
1003 push @f, $_ unless /[[:word:]]/ == /\w/;
1006 push @f, $_ unless /[[:word:]]/ == /\w/;
1009 report_multi_result($Locale, $locales_test_number, \@f);
1011 ++$locales_test_number;
1013 $test_names{$locales_test_number} = 'Verify that \d and [:digit:] are identical';
1014 for (map { chr } 0..255) {
1015 if ($is_utf8_locale) {
1016 use locale ':not_characters';
1017 push @f, $_ unless /[[:digit:]]/ == /\d/;
1020 push @f, $_ unless /[[:digit:]]/ == /\d/;
1023 report_multi_result($Locale, $locales_test_number, \@f);
1025 ++$locales_test_number;
1027 $test_names{$locales_test_number} = 'Verify that \s and [:space:] are identical';
1028 for (map { chr } 0..255) {
1029 if ($is_utf8_locale) {
1030 use locale ':not_characters';
1031 push @f, $_ unless /[[:space:]]/ == /\s/;
1034 push @f, $_ unless /[[:space:]]/ == /\s/;
1037 report_multi_result($Locale, $locales_test_number, \@f);
1039 ++$locales_test_number;
1041 $test_names{$locales_test_number} = 'Verify that [:posix:] and [:^posix:] are mutually exclusive';
1042 for (map { chr } 0..255) {
1043 if ($is_utf8_locale) {
1044 use locale ':not_characters';
1045 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1046 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1047 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1048 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1049 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1050 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1051 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1052 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1053 (/[[:print:]]/ xor /[[:^print:]]/) ||
1054 (/[[:space:]]/ xor /[[:^space:]]/) ||
1055 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1056 (/[[:word:]]/ xor /[[:^word:]]/) ||
1057 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1059 # effectively is what [:cased:] would be if it existed.
1060 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1063 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1064 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1065 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1066 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1067 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1068 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1069 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1070 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1071 (/[[:print:]]/ xor /[[:^print:]]/) ||
1072 (/[[:space:]]/ xor /[[:^space:]]/) ||
1073 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1074 (/[[:word:]]/ xor /[[:^word:]]/) ||
1075 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1076 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1079 report_multi_result($Locale, $locales_test_number, \@f);
1081 # The rules for the relationships are given in:
1082 # http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
1085 ++$locales_test_number;
1087 $test_names{$locales_test_number} = 'Verify that [:lower:] contains at least a-z';
1089 if ($is_utf8_locale) {
1090 use locale ':not_characters';
1091 push @f, $_ unless /[[:lower:]]/;
1094 push @f, $_ unless /[[:lower:]]/;
1097 report_multi_result($Locale, $locales_test_number, \@f);
1099 ++$locales_test_number;
1101 $test_names{$locales_test_number} = 'Verify that [:lower:] is a subset of [:alpha:]';
1102 for (map { chr } 0..255) {
1103 if ($is_utf8_locale) {
1104 use locale ':not_characters';
1105 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1108 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1111 report_multi_result($Locale, $locales_test_number, \@f);
1113 ++$locales_test_number;
1115 $test_names{$locales_test_number} = 'Verify that [:upper:] contains at least A-Z';
1117 if ($is_utf8_locale) {
1118 use locale ':not_characters';
1119 push @f, $_ unless /[[:upper:]]/;
1122 push @f, $_ unless /[[:upper:]]/;
1125 report_multi_result($Locale, $locales_test_number, \@f);
1127 ++$locales_test_number;
1129 $test_names{$locales_test_number} = 'Verify that [:upper:] is a subset of [:alpha:]';
1130 for (map { chr } 0..255) {
1131 if ($is_utf8_locale) {
1132 use locale ':not_characters';
1133 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1136 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1139 report_multi_result($Locale, $locales_test_number, \@f);
1141 ++$locales_test_number;
1143 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i is a subset of [:alpha:]';
1144 for (map { chr } 0..255) {
1145 if ($is_utf8_locale) {
1146 use locale ':not_characters';
1147 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1150 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1153 report_multi_result($Locale, $locales_test_number, \@f);
1155 ++$locales_test_number;
1157 $test_names{$locales_test_number} = 'Verify that [:alpha:] is a subset of [:alnum:]';
1158 for (map { chr } 0..255) {
1159 if ($is_utf8_locale) {
1160 use locale ':not_characters';
1161 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1164 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1167 report_multi_result($Locale, $locales_test_number, \@f);
1169 ++$locales_test_number;
1171 $test_names{$locales_test_number} = 'Verify that [:digit:] contains at least 0-9';
1173 if ($is_utf8_locale) {
1174 use locale ':not_characters';
1175 push @f, $_ unless /[[:digit:]]/;
1178 push @f, $_ unless /[[:digit:]]/;
1181 report_multi_result($Locale, $locales_test_number, \@f);
1183 ++$locales_test_number;
1185 $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:alnum:]';
1186 for (map { chr } 0..255) {
1187 if ($is_utf8_locale) {
1188 use locale ':not_characters';
1189 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1192 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1195 report_multi_result($Locale, $locales_test_number, \@f);
1197 ++$locales_test_number;
1199 $test_names{$locales_test_number} = 'Verify that [:digit:] matches either 10 or 20 code points';
1200 report_result($Locale, $locales_test_number, @{$posixes{'digit'}} == 10 || @{$posixes{'digit'}} == 20);
1202 ++$locales_test_number;
1204 $test_names{$locales_test_number} = 'Verify that if there is a second set of digits in [:digit:], they are consecutive';
1205 if (@{$posixes{'digit'}} == 20) {
1207 for (map { chr } 0..255) {
1208 next unless /[[:digit:]]/;
1210 if (defined $previous_ord) {
1211 if ($is_utf8_locale) {
1212 use locale ':not_characters';
1213 push @f, $_ if ord $_ != $previous_ord + 1;
1216 push @f, $_ if ord $_ != $previous_ord + 1;
1219 $previous_ord = ord $_;
1222 report_multi_result($Locale, $locales_test_number, \@f);
1224 ++$locales_test_number;
1226 $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:xdigit:]';
1227 for (map { chr } 0..255) {
1228 if ($is_utf8_locale) {
1229 use locale ':not_characters';
1230 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1233 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1236 report_multi_result($Locale, $locales_test_number, \@f);
1238 ++$locales_test_number;
1240 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains at least A-F, a-f';
1241 for ('A' .. 'F', 'a' .. 'f') {
1242 if ($is_utf8_locale) {
1243 use locale ':not_characters';
1244 push @f, $_ unless /[[:xdigit:]]/;
1247 push @f, $_ unless /[[:xdigit:]]/;
1250 report_multi_result($Locale, $locales_test_number, \@f);
1252 ++$locales_test_number;
1254 $test_names{$locales_test_number} = 'Verify that any additional members of [:xdigit:], are in groups of 6 consecutive code points';
1257 for (map { chr } 0..255) {
1258 next unless /[[:xdigit:]]/;
1259 next if /[[:digit:]]/;
1261 if (defined $previous_ord) {
1262 if ($is_utf8_locale) {
1263 use locale ':not_characters';
1264 push @f, $_ if ord $_ != $previous_ord + 1;
1267 push @f, $_ if ord $_ != $previous_ord + 1;
1272 undef $previous_ord;
1275 $previous_ord = ord $_;
1278 report_multi_result($Locale, $locales_test_number, \@f);
1280 ++$locales_test_number;
1282 $test_names{$locales_test_number} = 'Verify that [:xdigit:] is a subset of [:graph:]';
1283 for (map { chr } 0..255) {
1284 if ($is_utf8_locale) {
1285 use locale ':not_characters';
1286 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1289 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1292 report_multi_result($Locale, $locales_test_number, \@f);
1294 # Note that xdigit doesn't have to be a subset of alnum
1296 ++$locales_test_number;
1298 $test_names{$locales_test_number} = 'Verify that [:punct:] is a subset of [:graph:]';
1299 for (map { chr } 0..255) {
1300 if ($is_utf8_locale) {
1301 use locale ':not_characters';
1302 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1305 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1308 report_multi_result($Locale, $locales_test_number, \@f);
1310 ++$locales_test_number;
1312 $test_names{$locales_test_number} = 'Verify that the space character is not in [:graph:]';
1313 if ($is_utf8_locale) {
1314 use locale ':not_characters';
1315 push @f, " " if " " =~ /[[:graph:]]/;
1318 push @f, " " if " " =~ /[[:graph:]]/;
1320 report_multi_result($Locale, $locales_test_number, \@f);
1322 ++$locales_test_number;
1324 $test_names{$locales_test_number} = 'Verify that [:space:] contains at least [\f\n\r\t\cK ]';
1325 for (' ', "\f", "\n", "\r", "\t", "\cK") {
1326 if ($is_utf8_locale) {
1327 use locale ':not_characters';
1328 push @f, $_ unless /[[:space:]]/;
1331 push @f, $_ unless /[[:space:]]/;
1334 report_multi_result($Locale, $locales_test_number, \@f);
1336 ++$locales_test_number;
1338 $test_names{$locales_test_number} = 'Verify that [:blank:] contains at least [\t ]';
1340 if ($is_utf8_locale) {
1341 use locale ':not_characters';
1342 push @f, $_ unless /[[:blank:]]/;
1345 push @f, $_ unless /[[:blank:]]/;
1348 report_multi_result($Locale, $locales_test_number, \@f);
1350 ++$locales_test_number;
1352 $test_names{$locales_test_number} = 'Verify that [:blank:] is a subset of [:space:]';
1353 for (map { chr } 0..255) {
1354 if ($is_utf8_locale) {
1355 use locale ':not_characters';
1356 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1359 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1362 report_multi_result($Locale, $locales_test_number, \@f);
1364 ++$locales_test_number;
1366 $test_names{$locales_test_number} = 'Verify that [:graph:] is a subset of [:print:]';
1367 for (map { chr } 0..255) {
1368 if ($is_utf8_locale) {
1369 use locale ':not_characters';
1370 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1373 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1376 report_multi_result($Locale, $locales_test_number, \@f);
1378 ++$locales_test_number;
1380 $test_names{$locales_test_number} = 'Verify that the space character is in [:print:]';
1381 if ($is_utf8_locale) {
1382 use locale ':not_characters';
1383 push @f, " " if " " !~ /[[:print:]]/;
1386 push @f, " " if " " !~ /[[:print:]]/;
1388 report_multi_result($Locale, $locales_test_number, \@f);
1390 ++$locales_test_number;
1392 $test_names{$locales_test_number} = 'Verify that isn\'t both [:cntrl:] and [:print:]';
1393 for (map { chr } 0..255) {
1394 if ($is_utf8_locale) {
1395 use locale ':not_characters';
1396 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1399 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1402 report_multi_result($Locale, $locales_test_number, \@f);
1404 ++$locales_test_number;
1406 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alpha:] and [:digit:]';
1407 for (map { chr } 0..255) {
1408 if ($is_utf8_locale) {
1409 use locale ':not_characters';
1410 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1413 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1416 report_multi_result($Locale, $locales_test_number, \@f);
1418 ++$locales_test_number;
1420 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alnum:] and [:punct:]';
1421 for (map { chr } 0..255) {
1422 if ($is_utf8_locale) {
1423 use locale ':not_characters';
1424 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1427 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1430 report_multi_result($Locale, $locales_test_number, \@f);
1432 ++$locales_test_number;
1434 $test_names{$locales_test_number} = 'Verify that isn\'t both [:xdigit:] and [:punct:]';
1435 for (map { chr } 0..255) {
1436 if ($is_utf8_locale) {
1437 use locale ':not_characters';
1438 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1441 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1444 report_multi_result($Locale, $locales_test_number, \@f);
1446 ++$locales_test_number;
1448 $test_names{$locales_test_number} = 'Verify that isn\'t both [:graph:] and [:space:]';
1449 for (map { chr } 0..255) {
1450 if ($is_utf8_locale) {
1451 use locale ':not_characters';
1452 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1455 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1458 report_multi_result($Locale, $locales_test_number, \@f);
1460 $final_casing_test_number = $locales_test_number;
1462 # Test for read-only scalars' locale vs non-locale comparisons.
1468 if ($is_utf8_locale) {
1469 use locale ':not_characters';
1470 $ok = ($a cmp "qwerty") == 0;
1474 $ok = ($a cmp "qwerty") == 0;
1476 report_result($Locale, ++$locales_test_number, $ok);
1477 $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
1481 my ($from, $to, $lesser, $greater,
1482 @test, %test, $test, $yes, $no, $sign);
1484 ++$locales_test_number;
1485 $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
1486 $not_necessarily_a_problem_test_number = $locales_test_number;
1489 $from = int(($_*@{$posixes{'word'}})/10);
1490 $to = $from + int(@{$posixes{'word'}}/10);
1491 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1492 $lesser = join('', @{$posixes{'word'}}[$from..$to]);
1493 # Select a slice one character on.
1495 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1496 $greater = join('', @{$posixes{'word'}}[$from..$to]);
1497 if ($is_utf8_locale) {
1498 use locale ':not_characters';
1499 ($yes, $no, $sign) = ($lesser lt $greater
1501 : ("not ", " ", -1));
1505 ($yes, $no, $sign) = ($lesser lt $greater
1507 : ("not ", " ", -1));
1509 # all these tests should FAIL (return 0). Exact lt or gt cannot
1510 # be tested because in some locales, say, eacute and E may test
1514 $no.' ($lesser le $greater)', # 1
1515 'not ($lesser ne $greater)', # 2
1516 ' ($lesser eq $greater)', # 3
1517 $yes.' ($lesser ge $greater)', # 4
1518 $yes.' ($lesser ge $greater)', # 5
1519 $yes.' ($greater le $lesser )', # 7
1520 'not ($greater ne $lesser )', # 8
1521 ' ($greater eq $lesser )', # 9
1522 $no.' ($greater ge $lesser )', # 10
1523 'not (($lesser cmp $greater) == -($sign))' # 11
1525 @test{@test} = 0 x @test;
1527 for my $ti (@test) {
1528 if ($is_utf8_locale) {
1529 use locale ':not_characters';
1530 $test{$ti} = eval $ti;
1533 # Already in 'use locale';
1534 $test{$ti} = eval $ti;
1536 $test ||= $test{$ti}
1538 report_result($Locale, $locales_test_number, $test == 0);
1540 debug "# lesser = '$lesser'\n";
1541 debug "# greater = '$greater'\n";
1542 debug "# lesser cmp greater = ",
1543 $lesser cmp $greater, "\n";
1544 debug "# greater cmp lesser = ",
1545 $greater cmp $lesser, "\n";
1546 debug "# (greater) from = $from, to = $to\n";
1547 for my $ti (@test) {
1548 debugf("# %-40s %-4s", $ti,
1549 $test{$ti} ? 'FAIL' : 'ok');
1550 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
1551 debugf("(%s == %4d)", $1, eval $1);
1589 if (! $is_utf8_locale) {
1592 my ($x, $y) = (1.23, 1.23);
1595 printf ''; # printf used to reset locale to "C"
1600 my $z = sprintf ''; # sprintf used to reset locale to "C"
1607 local $SIG{__WARN__} =
1613 # The == (among other ops) used to warn for locales
1614 # that had something else than "." as the radix character.
1638 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1640 $ok14 = $ok15 = $ok16 = 1; # Skip for non-utf8 locales
1644 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1646 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1649 use locale ':not_characters';
1651 my ($x, $y) = (1.23, 1.23);
1653 printf ''; # printf used to reset locale to "C"
1658 my $z = sprintf ''; # sprintf used to reset locale to "C"
1664 local $SIG{__WARN__} =
1690 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1693 # Look for non-ASCII error messages, and verify that the first
1694 # such is in UTF-8 (the others almost certainly will be like the
1697 foreach my $err (keys %!) {
1699 $! = eval "&Errno::$err"; # Convert to strerror() output
1700 my $strerror = "$!";
1701 if ("$strerror" =~ /\P{ASCII}/) {
1702 $ok14 = utf8::is_utf8($strerror);
1707 # Similarly, we verify that a non-ASCII radix is in UTF-8. This
1708 # also catches if there is a disparity between sprintf and
1711 my $string_g = "$g";
1712 my $sprintf_g = sprintf("%g", $g);
1714 $ok15 = $string_g =~ / ^ \p{ASCII}+ $ /x || utf8::is_utf8($string_g);
1715 $ok16 = $sprintf_g eq $string_g;
1719 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1721 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1724 report_result($Locale, ++$locales_test_number, $ok1);
1725 $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
1726 my $first_a_test = $locales_test_number;
1728 debug "# $first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
1730 report_result($Locale, ++$locales_test_number, $ok2);
1731 $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
1733 my $first_c_test = $locales_test_number;
1735 report_result($Locale, ++$locales_test_number, $ok3);
1736 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
1738 report_result($Locale, ++$locales_test_number, $ok4);
1739 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
1741 report_result($Locale, ++$locales_test_number, $ok5);
1742 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
1744 debug "# $first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
1746 report_result($Locale, ++$locales_test_number, $ok6);
1747 $test_names{$locales_test_number} = 'Verify that can assign stringified under inner no-locale block';
1748 my $first_e_test = $locales_test_number;
1750 report_result($Locale, ++$locales_test_number, $ok7);
1751 $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
1753 report_result($Locale, ++$locales_test_number, $ok8);
1754 $test_names{$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
1756 debug "# $first_e_test..$locales_test_number: \$e = $e, no locale\n";
1758 report_result($Locale, ++$locales_test_number, $ok9);
1759 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
1760 my $first_f_test = $locales_test_number;
1762 report_result($Locale, ++$locales_test_number, $ok10);
1763 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
1765 report_result($Locale, ++$locales_test_number, $ok11);
1766 $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';
1768 report_result($Locale, ++$locales_test_number, $ok12);
1769 $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';
1771 report_result($Locale, ++$locales_test_number, $ok13);
1772 $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
1774 report_result($Locale, ++$locales_test_number, $ok14);
1775 $test_names{$locales_test_number} = 'Verify that non-ASCII UTF-8 error messages are in UTF-8';
1777 report_result($Locale, ++$locales_test_number, $ok15);
1778 $test_names{$locales_test_number} = 'Verify that a number with a UTF-8 radix has a UTF-8 stringification';
1780 report_result($Locale, ++$locales_test_number, $ok16);
1781 $test_names{$locales_test_number} = 'Verify that a sprintf of a number with a UTF-8 radix yields UTF-8';
1783 report_result($Locale, ++$locales_test_number, $ok17);
1784 $test_names{$locales_test_number} = 'Verify that a sprintf of a number outside locale scope uses a dot radix';
1786 report_result($Locale, ++$locales_test_number, $ok18);
1787 $test_names{$locales_test_number} = 'Verify that a sprintf of a number back within locale scope uses locale radix';
1789 debug "# $first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
1791 # Does taking lc separately differ from taking
1792 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
1793 # The bug was in the caching of the 'o'-magic.
1794 if (! $is_utf8_locale) {
1800 return $lc0 cmp $lc1;
1804 return lc($_[0]) cmp lc($_[1]);
1811 report_result($Locale, ++$locales_test_number,
1812 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
1813 lcA($x, $z) == 0 && lcB($x, $z) == 0);
1816 use locale ':not_characters';
1821 return $lc0 cmp $lc1;
1825 return lc($_[0]) cmp lc($_[1]);
1832 report_result($Locale, ++$locales_test_number,
1833 lcC($x, $y) == 1 && lcD($x, $y) == 1 ||
1834 lcC($x, $z) == 0 && lcD($x, $z) == 0);
1836 $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
1838 # Does lc of an UPPER (if different from the UPPER) match
1839 # case-insensitively the UPPER, and does the UPPER match
1840 # case-insensitively the lc of the UPPER. And vice versa.
1844 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
1847 ++$locales_test_number;
1848 $test_names{$locales_test_number} = 'Verify case insensitive matching works';
1849 foreach my $x (sort keys %UPPER) {
1850 if (! $is_utf8_locale) {
1852 next unless uc $y eq $x;
1853 print "# UPPER $x lc $y ",
1854 $x =~ /$y/i ? 1 : 0, " ",
1855 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1857 # If $x and $y contain regular expression characters
1858 # AND THEY lowercase (/i) to regular expression characters,
1859 # regcomp() will be mightily confused. No, the \Q doesn't
1860 # help here (maybe regex engine internal lowercasing
1861 # is done after the \Q?) An example of this happening is
1862 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
1863 # the chr(173) (the "[") is the lowercase of the chr(235).
1865 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
1866 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
1867 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
1868 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
1869 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
1870 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
1872 # Similar things can happen even under (bastardised)
1873 # non-EBCDIC locales: in many European countries before the
1874 # advent of ISO 8859-x nationally customised versions of
1875 # ISO 646 were devised, reusing certain punctuation
1876 # characters for modified characters needed by the
1877 # country/language. For example, the "|" might have
1878 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
1880 if ($x =~ $re || $y =~ $re) {
1881 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1884 # With utf8 both will fail since the locale concept
1885 # of upper/lower does not work well in Unicode.
1886 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
1888 # fc is not a locale concept, so Perl uses lc for it.
1889 push @f, $x unless lc $x eq fc $x;
1892 use locale ':not_characters';
1894 next unless uc $y eq $x;
1895 print "# UPPER $x lc $y ",
1896 $x =~ /$y/i ? 1 : 0, " ",
1897 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1899 # Here, we can fully test things, unlike plain 'use locale',
1900 # because this form does work well with Unicode
1901 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1903 # The places where Unicode's lc is different from fc are
1904 # skipped here by virtue of the 'next unless uc...' line above
1905 push @f, $x unless lc $x eq fc $x;
1909 foreach my $x (sort keys %lower) {
1910 if (! $is_utf8_locale) {
1912 next unless lc $y eq $x;
1913 print "# lower $x uc $y ",
1914 $x =~ /$y/i ? 1 : 0, " ",
1915 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1916 if ($x =~ $re || $y =~ $re) { # See above.
1917 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1920 # With utf8 both will fail since the locale concept
1921 # of upper/lower does not work well in Unicode.
1922 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
1924 push @f, $x unless lc $x eq fc $x;
1927 use locale ':not_characters';
1929 next unless lc $y eq $x;
1930 print "# lower $x uc $y ",
1931 $x =~ /$y/i ? 1 : 0, " ",
1932 $y =~ /$x/i ? 1 : 0, "\n" if 0;
1933 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1935 push @f, $x unless lc $x eq fc $x;
1938 report_multi_result($Locale, $locales_test_number, \@f);
1944 ++$locales_test_number;
1945 $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
1947 my $radix = POSIX::localeconv()->{decimal_point};
1949 "3.14e+9", "3${radix}14e+9", "3.14e-9", "3${radix}14e-9",
1950 "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
1953 if (! $is_utf8_locale) {
1955 for my $num (@nums) {
1957 unless sprintf("%g", $num) =~ /3.+14/;
1961 use locale ':not_characters';
1962 for my $num (@nums) {
1964 unless sprintf("%g", $num) =~ /3.+14/;
1968 report_result($Locale, $locales_test_number, @f == 0);
1970 print "# failed $locales_test_number locale '$Locale' numbers @f\n"
1975 my $final_locales_test_number = $locales_test_number;
1977 # Recount the errors.
1979 foreach ($first_locales_test_number..$final_locales_test_number) {
1980 if (%setlocale_failed) {
1983 elsif ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
1984 if (defined $not_necessarily_a_problem_test_number
1985 && $_ == $not_necessarily_a_problem_test_number)
1987 print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
1988 print "# It usually indicates a problem in the environment,\n";
1989 print "# not in Perl itself.\n";
1991 if ($Okay{$_} && ($_ >= $first_casing_test_number
1992 && $_ <= $final_casing_test_number))
1994 # Round to nearest .1%
1995 my $percent_fail = (int(.5 + (1000 * scalar(keys $Problem{$_})
1996 / scalar(@Locale))))
1998 if (! $debug && $percent_fail < $acceptable_fold_failure_percentage)
2000 $test_names{$_} .= 'TODO';
2001 print "# ", 100 - $percent_fail, "% of locales pass the following test, so it is likely that the failures\n";
2002 print "# are errors in the locale definitions. The test is marked TODO, as the\n";
2003 print "# problem is not likely to be Perl's\n";
2008 print "# The code points that had this failure are given above. Look for lines\n";
2009 print "# that match 'failed $_'\n";
2012 print "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2013 print "# Then look at that output for lines that match 'failed $_'\n";
2018 if (defined $test_names{$_}) {
2019 # If TODO is in the test name, make it thus
2020 my $todo = $test_names{$_} =~ s/TODO\s*//;
2021 print " $test_names{$_}";
2022 print " # TODO" if $todo;
2027 $test_num = $final_locales_test_number;
2029 unless ( $^O eq 'dragonfly' ) {
2033 local $SIG{__WARN__} = sub {
2034 $warned = $_[0] =~ /uninitialized/;
2036 my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy");
2037 ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized");
2040 # Test that tainting and case changing works on utf8 strings. These tests are
2041 # placed last to avoid disturbing the hard-coded test numbers that existed at
2042 # the time these were added above this in this file.
2043 # This also tests that locale overrides unicode_strings in the same scope for
2045 setlocale(&POSIX::LC_ALL, "C");
2048 use feature 'unicode_strings';
2050 foreach my $function ("uc", "ucfirst", "lc", "lcfirst", "fc") {
2051 my @list; # List of code points to test for $function
2053 # Used to calculate the changed case for ASCII characters by using the
2054 # ord, instead of using one of the functions under test.
2055 my $ascii_case_change_delta;
2056 my $above_latin1_case_change_delta; # Same for the specific ords > 255
2059 # We test an ASCII character, which should change case and be tainted;
2060 # a Latin1 character, which shouldn't change case under this C locale,
2062 # an above-Latin1 character that when the case is changed would cross
2063 # the 255/256 boundary, so doesn't change case and isn't tainted
2064 # (the \x{149} is one of these, but changes into 2 characters, the
2065 # first one of which doesn't cross the boundary.
2066 # the final one in each list is an above-Latin1 character whose case
2067 # does change, and shouldn't be tainted. The code below uses its
2068 # position in its list as a marker to indicate that it, unlike the
2069 # other code points above ASCII, has a successful case change
2070 if ($function =~ /^u/) {
2071 @list = ("", "a", "\xe0", "\xff", "\x{fb00}", "\x{149}", "\x{101}");
2072 $ascii_case_change_delta = -32;
2073 $above_latin1_case_change_delta = -1;
2076 @list = ("", "A", "\xC0", "\x{17F}", "\x{100}");
2077 $ascii_case_change_delta = +32;
2078 $above_latin1_case_change_delta = +1;
2080 foreach my $is_utf8_locale (0 .. 1) {
2081 foreach my $j (0 .. $#list) {
2082 my $char = $list[$j];
2084 for my $encoded_in_utf8 (0 .. 1) {
2087 if (! $is_utf8_locale) {
2088 $should_be = ($j == $#list)
2089 ? chr(ord($char) + $above_latin1_case_change_delta)
2090 : (length $char == 0 || ord($char) > 127)
2092 : chr(ord($char) + $ascii_case_change_delta);
2094 # This monstrosity is in order to avoid using an eval,
2095 # which might perturb the results
2096 $changed = ($function eq "uc")
2098 : ($function eq "ucfirst")
2100 : ($function eq "lc")
2102 : ($function eq "lcfirst")
2104 : ($function eq "fc")
2106 : die("Unexpected function \"$function\"");
2112 # For utf8-locales the case changing functions
2113 # should work just like they do outside of locale.
2114 # Can use eval here because not testing it when
2116 $should_be = eval "$function('$char')";
2117 die "Unexpected eval error $@ from 'eval \"$function('$char')\"'" if $@;
2120 use locale ':not_characters';
2121 $changed = ($function eq "uc")
2123 : ($function eq "ucfirst")
2125 : ($function eq "lc")
2127 : ($function eq "lcfirst")
2129 : ($function eq "fc")
2131 : die("Unexpected function \"$function\"");
2133 ok($changed eq $should_be,
2134 "$function(\"$char\") in C locale "
2135 . (($is_utf8_locale)
2136 ? "(use locale ':not_characters'"
2138 . (($encoded_in_utf8)
2139 ? "; encoded in utf8)"
2140 : "; not encoded in utf8)")
2141 . " should be \"$should_be\", got \"$changed\"");
2143 # Tainting shouldn't happen for utf8 locales, empty
2144 # strings, or those characters above 255.
2145 (! $is_utf8_locale && length($char) > 0 && ord($char) < 256)
2146 ? check_taint($changed)
2147 : check_taint_not($changed);
2149 # Use UTF-8 next time through the loop
2150 utf8::upgrade($char);
2157 # Give final advice.
2161 foreach ($first_locales_test_number..$final_locales_test_number) {
2163 my @f = sort keys %{ $Problem{$_} };
2164 my $f = join(" ", @f);
2165 $f =~ s/(.{50,60}) /$1\n#\t/g;
2168 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
2170 "# on your system may have errors because the locale test $_\n",
2171 "# \"$test_names{$_}\"\n",
2172 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
2176 # If your users are not using these locales you are safe for the moment,
2177 # but please report this failure first to perlbug\@perl.com using the
2178 # perlbug script (as described in the INSTALL file) so that the exact
2179 # details of the failures can be sorted out first and then your operating
2180 # system supplier can be alerted about these anomalies.
2187 # Tell which locales were okay and which were not.
2192 foreach my $l (@Locale) {
2194 if ($setlocale_failed{$l}) {
2199 ($first_locales_test_number..$final_locales_test_number)
2201 $p++ if $Problem{$t}{$l};
2204 push @s, $l if $p == 0;
2205 push @F, $l unless $p == 0;
2209 my $s = join(" ", @s);
2210 $s =~ s/(.{50,60}) /$1\n#\t/g;
2213 "# The following locales\n#\n",
2215 "# tested okay.\n#\n",
2217 warn "# None of your locales were fully okay.\n";
2221 my $F = join(" ", @F);
2222 $F =~ s/(.{50,60}) /$1\n#\t/g;
2225 "# The following locales\n#\n",
2227 "# had problems.\n#\n",
2228 "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2230 warn "# None of your locales were broken.\n";
2234 print "1..$test_num\n";