3 binmode STDOUT, ':utf8';
4 binmode STDERR, ':utf8';
10 require Config; import Config;
11 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
24 my $dumper = Dumpvalue->new(
31 my($mess) = join "", @_;
33 print $dumper->stringify($mess,1), "\n";
40 my $have_setlocale = 0;
43 import POSIX ':locale_h';
47 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
48 # and mingw32 uses said silly CRT
49 # This doesn't seem to be an issue any more, at least on Windows XP,
50 # so re-enable the tests for Windows XP onwards.
51 my $winxp = ($^O eq 'MSWin32' && defined &Win32::GetOSVersion &&
52 join('.', (Win32::GetOSVersion())[1..2]) >= 5.1);
53 $have_setlocale = 0 if ((($^O eq 'MSWin32' && !$winxp) || $^O eq 'NetWare') &&
54 $Config{cc} =~ /^(cl|gcc)/i);
56 # UWIN seems to loop after taint tests, just skip for now
57 $have_setlocale = 0 if ($^O =~ /^uwin/);
66 my ($result, $message) = @_;
67 $message = "" unless defined $message;
69 print 'not ' unless ($result);
70 print "ok " . ++$test_num;
75 # First we'll do a lot of taint checking for locales.
76 # This is the easiest to test, actually, as any locale,
77 # even the default locale will taint under 'use locale'.
79 sub is_tainted { # hello, camel two.
80 no warnings 'uninitialized' ;
83 not eval { $dummy = join("", @_), kill 0; 1 }
87 ok is_tainted($_[0]), "verify that is tainted";
90 sub check_taint_not ($) {
91 ok((not is_tainted($_[0])), "verify that isn't tainted");
94 use locale; # engage locale and therefore locale taint.
100 check_taint ucfirst($a);
104 check_taint lcfirst($a);
107 check_taint_not sprintf('%e', 123.456);
108 check_taint_not sprintf('%f', 123.456);
109 check_taint_not sprintf('%g', 123.456);
110 check_taint_not sprintf('%d', 123.456);
111 check_taint_not sprintf('%x', 123.456);
113 $_ = $a; # untaint $_
115 $_ = uc($a); # taint $_
119 /(\w)/; # taint $&, $`, $', $+, $1.
127 /(.)/; # untaint $&, $`, $', $+, $1.
135 /(\W)/; # taint $&, $`, $', $+, $1.
143 /(\s)/; # taint $&, $`, $', $+, $1.
151 /(\S)/; # taint $&, $`, $', $+, $1.
159 $_ = $a; # untaint $_
163 /(b)/; # this must not taint
171 $_ = $a; # untaint $_
175 $b = uc($a); # taint $b
176 s/(.+)/$b/; # this must taint only the $_
186 $_ = $a; # untaint $_
188 s/(.+)/b/; # this must not taint
197 $b = $a; # untaint $b
199 ($b = $a) =~ s/\w/$&/;
200 check_taint $b; # $b should be tainted.
201 check_taint_not $a; # $a should be not.
203 $_ = $a; # untaint $_
205 s/(\w)/\l$1/; # this must taint
214 $_ = $a; # untaint $_
216 s/(\w)/\L$1/; # this must taint
225 $_ = $a; # untaint $_
227 s/(\w)/\u$1/; # this must taint
236 $_ = $a; # untaint $_
238 s/(\w)/\U$1/; # this must taint
247 # After all this tainting $a should be cool.
251 # I think we've seen quite enough of taint.
252 # Let us do some *real* locale work now,
253 # unless setlocale() is missing (i.e. minitest).
255 unless ($have_setlocale) {
256 print "1..$test_num\n";
260 # The test number before our first setlocale()
261 my $final_without_setlocale = $test_num;
265 debug "# Scanning for locales...\n";
267 # Note that it's okay that some languages have their native names
268 # capitalized here even though that's not "right". They are lowercased
269 # anyway later during the scanning process (and besides, some clueless
270 # vendor might have them capitalized erroneously anyway).
274 Arabic:ar:dz eg sa:6 arabic8
275 Brezhoneg Breton:br:fr:1 15
276 Bulgarski Bulgarian:bg:bg:5
277 Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
278 Hrvatski Croatian:hr:hr:2
279 Cymraeg Welsh:cy:cy:1 14 15
281 Dansk Danish:dk:da:1 15
282 Nederlands Dutch:nl:be nl:1 15
283 English American British:en:au ca gb ie nz us uk zw:1 15 cp850
285 Eesti Estonian:et:ee:4 6 13
286 Suomi Finnish:fi:fi:1 15
288 Deutsch German:de:at be ch de lu:1 15
289 Euskaraz Basque:eu:es fr:1 15
290 Galego Galician:gl:es:1 15
291 Ellada Greek:el:gr:7 g8
293 Greenlandic:kl:gl:4 6
294 Hebrew:iw:il:8 hebrew8
296 Indonesian:in:id:1 15
297 Gaeilge Irish:ga:IE:1 14 15
298 Italiano Italian:it:ch it:1 15
299 Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
301 Latine Latin:la:va:1 15
303 Lithuanian:lt:lt:4 6 13
304 Macedonian:mk:mk:1 15
307 Norsk Norwegian:no no\@nynorsk:no:1 15
309 Polski Polish:pl:pl:2
311 Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
312 Serbski Serbian:sr:yu:5
314 Slovene Slovenian:sl:si:2
315 Sqhip Albanian:sq:sq:1 15
316 Svenska Swedish:sv:fi se:1 15
318 Turkish:tr:tr:9 turkish8
322 if ($^O eq 'os390') {
323 # These cause heartburn. Broken locales?
324 $locales =~ s/Svenska Swedish:sv:fi se:1 15\n//;
325 $locales =~ s/Thai:th:th:11 tis620\n//;
328 sub in_utf8 () { $^H & 0x08 || (${^OPEN} || "") =~ /:utf8/ }
331 require "lib/locale/utf8";
333 require "lib/locale/latin1";
342 return if grep { $locale eq $_ } @Locale;
343 if (setlocale(LC_ALL, $locale)) {
344 push @Locale, $locale;
348 sub decode_encodings {
351 foreach (split(/ /, shift)) {
353 push @enc, "ISO8859-$1";
354 push @enc, "iso8859$1"; # HP
356 push @enc, "roman8"; # HP
360 push @enc, "$_.UTF-8";
363 if ($^O eq 'os390') {
364 push @enc, qw(IBM-037 IBM-819 IBM-1047);
373 trylocale("ISO8859-$_");
374 trylocale("iso8859$_");
375 trylocale("iso8859-$_");
376 trylocale("iso_8859_$_");
377 trylocale("isolatin$_");
378 trylocale("isolatin-$_");
379 trylocale("iso_latin_$_");
382 # Sanitize the environment so that we can run the external 'locale'
383 # program without the taint mode getting grumpy.
385 # $ENV{PATH} is special in VMS.
386 delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
388 # Other subversive stuff.
389 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
391 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
393 # It seems that /usr/bin/locale steadfastly outputs 8 bit data, which
394 # ain't great when we're running this testPERL_UNICODE= so that utf8
395 # locales will cause all IO hadles to default to (assume) utf8
396 next unless utf8::valid($_);
401 } elsif ($^O eq 'VMS' && defined($ENV{'SYS$I18N_LOCALE'}) && -d 'SYS$I18N_LOCALE') {
402 # The SYS$I18N_LOCALE logical name search list was not present on
403 # VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
404 opendir(LOCALES, "SYS\$I18N_LOCALE:");
405 while ($_ = readdir(LOCALES)) {
410 } elsif ($^O eq 'openbsd' && -e '/usr/share/locale') {
412 # OpenBSD doesn't have a locale executable, so reading /usr/share/locale
413 # is much easier and faster than the last resort method.
415 opendir(LOCALES, '/usr/share/locale');
416 while ($_ = readdir(LOCALES)) {
423 # This is going to be slow.
425 foreach my $locale (split(/\n/, $locales)) {
426 my ($locale_name, $language_codes, $country_codes, $encodings) =
428 my @enc = decode_encodings($encodings);
429 foreach my $loc (split(/ /, $locale_name)) {
431 foreach my $enc (@enc) {
432 trylocale("$loc.$enc");
435 foreach my $enc (@enc) {
436 trylocale("$loc.$enc");
439 foreach my $lang (split(/ /, $language_codes)) {
441 foreach my $country (split(/ /, $country_codes)) {
442 my $lc = "${lang}_${country}";
444 foreach my $enc (@enc) {
445 trylocale("$lc.$enc");
447 my $lC = "${lang}_\U${country}";
449 foreach my $enc (@enc) {
450 trylocale("$lC.$enc");
457 setlocale(LC_ALL, "C");
459 if ($^O eq 'darwin') {
460 # Darwin 8/Mac OS X 10.4 and 10.5 have bad Basque locales: perl bug #35895,
461 # Apple bug ID# 4139653. It also has a problem in Byelorussian.
462 (my $v) = $Config{osvers} =~ /^(\d+)/;
463 if ($v >= 8 and $v < 10) {
464 debug "# Skipping eu_ES, be_BY locales -- buggy in Darwin\n";
465 @Locale = grep ! m/^(eu_ES(?:\..*)?|be_BY\.CP1131)$/, @Locale;
467 debug "# Skipping be_BY locales -- buggy in Darwin\n";
468 @Locale = grep ! m/^be_BY\.CP1131$/, @Locale;
472 @Locale = sort @Locale;
474 debug "# Locales =\n";
482 my @Neoalpha; # Alnums that aren't in the C locale.
486 my ($Locale, $i, $test) = @_;
488 $Problem{$i}{$Locale} = 1;
489 debug "# failed $i with locale '$Locale'\n";
491 push @{$Okay{$i}}, $Locale;
495 my $first_locales_test_number = $final_without_setlocale + 1;
496 my $locales_test_number;
497 my $not_necessarily_a_problem_test_number;
498 my %setlocale_failed; # List of locales that setlocale() didn't work on
500 foreach $Locale (@Locale) {
501 $locales_test_number = $first_locales_test_number - 1;
502 debug "# Locale = $Locale\n";
504 unless (setlocale(LC_ALL, $Locale)) {
505 $setlocale_failed{$Locale} = $Locale;
509 @Alnum_ = sort grep /\w/, map { chr } 0..255;
511 debug "# w = ", join("",@Alnum_), "\n";
513 # Sieve the uppercase and the lowercase.
519 if (/[^\d_]/) { # skip digits and the _
528 foreach (keys %UPPER) {
529 $BoThCaSe{$_}++ if exists $lower{$_};
531 foreach (keys %lower) {
532 $BoThCaSe{$_}++ if exists $UPPER{$_};
534 foreach (keys %BoThCaSe) {
539 debug "# UPPER = ", join("", sort keys %UPPER ), "\n";
540 debug "# lower = ", join("", sort keys %lower ), "\n";
541 debug "# BoThCaSe = ", join("", sort keys %BoThCaSe), "\n";
543 { # Find the alphabetic characters that are not considered alphabetics
544 # in the default (C) locale.
549 for (keys %UPPER, keys %lower) {
550 push(@Neoalpha, $_) if (/\W/);
554 @Neoalpha = sort @Neoalpha;
556 debug "# Neoalpha = ", join("",@Neoalpha), "\n";
558 my $first_Neoalpha_test_number = $locales_test_number;
559 my $final_Neoalpha_test_number = $first_Neoalpha_test_number + 4;
560 if (@Neoalpha == 0) {
561 # If we have no Neoalphas the remaining tests are no-ops.
562 debug "# no Neoalpha, skipping tests $locales_test_number..$final_Neoalpha_test_number for locale '$Locale'\n";
563 foreach ($locales_test_number+1..$final_Neoalpha_test_number) {
564 push @{$Okay{$_}}, $Locale;
565 $locales_test_number++;
571 my $word = join('', @Neoalpha);
575 local $SIG{__WARN__} = sub {
576 $badutf8 = $_[0] =~ /Malformed UTF-8/;
578 $Locale =~ /utf-?8/i;
581 ++$locales_test_number;
582 $test_names{$locales_test_number} = 'Verify that alnums outside the C locale match \w';
584 debug "# Locale name contains bad UTF-8, skipping test $locales_test_number for locale '$Locale'\n";
585 } elsif ($Locale =~ /utf-?8/i) {
586 push @{$Okay{$locales_test_number}}, $Locale;
587 debug "# unknown whether locale and Unicode have the same \\w, skipping test $locales_test_number for locale '$Locale'\n";
589 if ($word =~ /^(\w+)$/) {
590 tryneoalpha($Locale, $locales_test_number, 1);
592 tryneoalpha($Locale, $locales_test_number, 0);
596 # Cross-check the whole 8-bit character set.
598 ++$locales_test_number;
599 $test_names{$locales_test_number} = 'Verify that \w and \W are mutually exclusive, as are \d, \D; \s, \S';
600 for (map { chr } 0..255) {
601 tryneoalpha($Locale, $locales_test_number,
607 # Test for read-only scalars' locale vs non-locale comparisons.
614 tryneoalpha($Locale, ++$locales_test_number, ($a cmp "qwerty") == 0);
615 $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
620 my ($from, $to, $lesser, $greater,
621 @test, %test, $test, $yes, $no, $sign);
623 ++$locales_test_number;
624 $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
625 $not_necessarily_a_problem_test_number = $locales_test_number;
628 $from = int(($_*@Alnum_)/10);
629 $to = $from + int(@Alnum_/10);
630 $to = $#Alnum_ if ($to > $#Alnum_);
631 $lesser = join('', @Alnum_[$from..$to]);
632 # Select a slice one character on.
634 $to = $#Alnum_ if ($to > $#Alnum_);
635 $greater = join('', @Alnum_[$from..$to]);
636 ($yes, $no, $sign) = ($lesser lt $greater
638 : ("not ", " ", -1));
639 # all these tests should FAIL (return 0).
640 # Exact lt or gt cannot be tested because
641 # in some locales, say, eacute and E may test equal.
644 $no.' ($lesser le $greater)', # 1
645 'not ($lesser ne $greater)', # 2
646 ' ($lesser eq $greater)', # 3
647 $yes.' ($lesser ge $greater)', # 4
648 $yes.' ($lesser ge $greater)', # 5
649 $yes.' ($greater le $lesser )', # 7
650 'not ($greater ne $lesser )', # 8
651 ' ($greater eq $lesser )', # 9
652 $no.' ($greater ge $lesser )', # 10
653 'not (($lesser cmp $greater) == -($sign))' # 11
655 @test{@test} = 0 x @test;
658 $test{$ti} = eval $ti;
661 tryneoalpha($Locale, $locales_test_number, $test == 0);
663 debug "# lesser = '$lesser'\n";
664 debug "# greater = '$greater'\n";
665 debug "# lesser cmp greater = ",
666 $lesser cmp $greater, "\n";
667 debug "# greater cmp lesser = ",
668 $greater cmp $lesser, "\n";
669 debug "# (greater) from = $from, to = $to\n";
671 debugf("# %-40s %-4s", $ti,
672 $test{$ti} ? 'FAIL' : 'ok');
673 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
674 debugf("(%s == %4d)", $1, eval $1);
685 if ($locales_test_number != $final_Neoalpha_test_number) {
686 die("The delta for \$final_Neoalpha needs to be updated from "
687 . ($final_Neoalpha_test_number - $first_Neoalpha_test_number)
689 . ($locales_test_number - $first_Neoalpha_test_number)
695 my ($x, $y) = (1.23, 1.23);
698 printf ''; # printf used to reset locale to "C"
701 tryneoalpha($Locale, ++$locales_test_number, $a eq $b);
702 $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
703 my $first_a_test = $locales_test_number;
705 debug "# $first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
708 my $z = sprintf ''; # sprintf used to reset locale to "C"
712 tryneoalpha($Locale, ++$locales_test_number, $c eq $d);
713 $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
714 my $first_c_test = $locales_test_number;
719 local $SIG{__WARN__} =
725 # The == (among other ops) used to warn for locales
726 # that had something else than "." as the radix character.
728 tryneoalpha($Locale, ++$locales_test_number, $c == 1.23);
729 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
731 tryneoalpha($Locale, ++$locales_test_number, $c == $x);
732 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
734 tryneoalpha($Locale, ++$locales_test_number, $c == $d);
735 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
737 debug "# $first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
742 # The earlier test was $e = "$x". But this fails [perl #108378],
743 # and the "no locale" was commented out. But doing that made all
744 # the tests in the block after this one meaningless, as originally
745 # it was testing the nesting of a "no locale" scope, and how it
746 # recovers after that scope is done. So I (khw) filed a bug
747 # report and changed this so it wouldn't fail. It seemed too much
748 # work to add TODOs instead. Should this be fixed, the following
749 # test names would need to be revised; they mostly don't really
750 # test anything currently.
753 tryneoalpha($Locale, ++$locales_test_number, $e == 1.23);
754 $test_names{$locales_test_number} = 'Verify that can assign numerically under inner no-locale block';
755 my $first_e_test = $locales_test_number;
757 tryneoalpha($Locale, ++$locales_test_number, $e == $x);
758 $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
760 tryneoalpha($Locale, ++$locales_test_number, $e == $c);
761 $test_names{$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
763 debug "# $first_e_test..$locales_test_number: e = \$e, no locale\n";
769 tryneoalpha($Locale, ++$locales_test_number, $f == 1.23);
770 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
771 my $first_f_test = $locales_test_number;
773 tryneoalpha($Locale, ++$locales_test_number, $f == $x);
774 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
776 tryneoalpha($Locale, ++$locales_test_number, $f == $c);
777 $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';
779 tryneoalpha($Locale, ++$locales_test_number, abs(($f + $g) - 3.57) < 0.01);
780 $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';
782 tryneoalpha($Locale, ++$locales_test_number, $w == 0);
783 $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
785 debug "# $first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
789 # Does taking lc separately differ from taking
790 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
791 # The bug was in the caching of the 'o'-magic.
798 return $lc0 cmp $lc1;
802 return lc($_[0]) cmp lc($_[1]);
809 tryneoalpha($Locale, ++$locales_test_number,
810 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
811 lcA($x, $z) == 0 && lcB($x, $z) == 0);
812 $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
815 # Does lc of an UPPER (if different from the UPPER) match
816 # case-insensitively the UPPER, and does the UPPER match
817 # case-insensitively the lc of the UPPER. And vice versa.
821 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
824 ++$locales_test_number;
825 $test_names{$locales_test_number} = 'Verify case insensitive matching works';
826 foreach my $x (keys %UPPER) {
828 next unless uc $y eq $x;
829 print "# UPPER $x lc $y ",
830 $x =~ /$y/i ? 1 : 0, " ",
831 $y =~ /$x/i ? 1 : 0, "\n" if 0;
833 # If $x and $y contain regular expression characters
834 # AND THEY lowercase (/i) to regular expression characters,
835 # regcomp() will be mightily confused. No, the \Q doesn't
836 # help here (maybe regex engine internal lowercasing
837 # is done after the \Q?) An example of this happening is
838 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
839 # the chr(173) (the "[") is the lowercase of the chr(235).
841 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
842 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
843 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
844 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
845 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
846 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
848 # Similar things can happen even under (bastardised)
849 # non-EBCDIC locales: in many European countries before the
850 # advent of ISO 8859-x nationally customised versions of
851 # ISO 646 were devised, reusing certain punctuation
852 # characters for modified characters needed by the
853 # country/language. For example, the "|" might have
854 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
856 if ($x =~ $re || $y =~ $re) {
857 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
860 # With utf8 both will fail since the locale concept
861 # of upper/lower does not work well in Unicode.
862 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
865 foreach my $x (keys %lower) {
867 next unless lc $y eq $x;
868 print "# lower $x uc $y ",
869 $x =~ /$y/i ? 1 : 0, " ",
870 $y =~ /$x/i ? 1 : 0, "\n" if 0;
871 if ($x =~ $re || $y =~ $re) { # See above.
872 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
875 # With utf8 both will fail since the locale concept
876 # of upper/lower does not work well in Unicode.
877 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
879 tryneoalpha($Locale, $locales_test_number, @f == 0);
881 print "# failed $locales_test_number locale '$Locale' characters @f\n"
886 my $final_locales_test_number = $locales_test_number;
888 # Recount the errors.
890 foreach ($first_locales_test_number..$final_locales_test_number) {
891 if (%setlocale_failed) {
894 elsif ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
895 if (defined $not_necessarily_a_problem_test_number
896 && $_ == $not_necessarily_a_problem_test_number)
898 print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
899 print "# It usually indicates a problem in the environment,\n";
900 print "# not in Perl itself.\n";
905 print " $test_names{$_}" if defined $test_names{$_};
913 foreach ($first_locales_test_number..$final_locales_test_number) {
915 my @f = sort keys %{ $Problem{$_} };
916 my $f = join(" ", @f);
917 $f =~ s/(.{50,60}) /$1\n#\t/g;
920 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
922 "# on your system may have errors because the locale test $_\n",
923 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
927 # If your users are not using these locales you are safe for the moment,
928 # but please report this failure first to perlbug\@perl.com using the
929 # perlbug script (as described in the INSTALL file) so that the exact
930 # details of the failures can be sorted out first and then your operating
931 # system supplier can be alerted about these anomalies.
938 # Tell which locales were okay and which were not.
943 foreach my $l (@Locale) {
945 if ($setlocale_failed{$l}) {
950 ($first_locales_test_number..$final_locales_test_number)
952 $p++ if $Problem{$t}{$l};
955 push @s, $l if $p == 0;
956 push @F, $l unless $p == 0;
960 my $s = join(" ", @s);
961 $s =~ s/(.{50,60}) /$1\n#\t/g;
964 "# The following locales\n#\n",
966 "# tested okay.\n#\n",
968 warn "# None of your locales were fully okay.\n";
972 my $F = join(" ", @F);
973 $F =~ s/(.{50,60}) /$1\n#\t/g;
976 "# The following locales\n#\n",
978 "# had problems.\n#\n",
980 warn "# None of your locales were broken.\n";
984 $test_num = $final_locales_test_number;
986 # Test that tainting and case changing works on utf8 strings. These tests are
987 # placed last to avoid disturbing the hard-coded test numbers that existed at
988 # the time these were added above this in this file.
989 setlocale(LC_ALL, "C");
993 foreach my $function ("uc", "ucfirst", "lc", "lcfirst") {
994 my @list; # List of code points to test for $function
996 # Used to calculate the changed case for ASCII characters by using the
997 # ord, instead of using one of the functions under test.
998 my $ascii_case_change_delta;
999 my $above_latin1_case_change_delta; # Same for the specific ords > 255
1002 # We test an ASCII character, which should change case and be tainted;
1003 # a Latin1 character, which shouldn't change case under this C locale,
1005 # an above-Latin1 character that when the case is changed would cross
1006 # the 255/256 boundary, so doesn't change case and isn't tainted
1007 # (the \x{149} is one of these, but changes into 2 characters, the
1008 # first one of which doesn't cross the boundary.
1009 # the final one in each list is an above-Latin1 character whose case
1010 # does change, and shouldn't be tainted. The code below uses its
1011 # position in its list as a marker to indicate that it, unlike the
1012 # other code points above ASCII, has a successful case change
1013 if ($function =~ /^u/) {
1014 @list = ("", "a", "\xe0", "\xff", "\x{fb00}", "\x{149}", "\x{101}");
1015 $ascii_case_change_delta = -32;
1016 $above_latin1_case_change_delta = -1;
1019 @list = ("", "A", "\xC0", "\x{1E9E}", "\x{100}");
1020 $ascii_case_change_delta = +32;
1021 $above_latin1_case_change_delta = +1;
1023 foreach my $j (0 .. $#list) {
1024 my $char = $list[$j];
1025 utf8::upgrade($char);
1026 my $should_be = ($j == $#list)
1027 ? chr(ord($char) + $above_latin1_case_change_delta)
1028 : (length $char == 0 || ord($char) > 127)
1030 : chr(ord($char) + $ascii_case_change_delta);
1032 # This monstrosity is in order to avoid using an eval, which might
1033 # perturb the results
1034 my $changed = ($function eq "uc")
1036 : ($function eq "ucfirst")
1038 : ($function eq "lc")
1040 : ($function eq "lcfirst")
1042 : die("Unexpected function \"$function\"");
1043 ok($changed eq $should_be, "$function(\"$char\") in C locale should be \"$should_be\", got \"$changed\"");
1045 # Tainting shouldn't happen for empty strings, or those characters
1047 (length($char) > 0 && ord($char) < 256)
1048 ? check_taint($changed)
1049 : check_taint_not($changed);
1054 print "1..$test_num\n";