5 unshift @INC, '../lib';
6 require Config; import Config;
7 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
25 my $have_setlocale = 0;
28 import POSIX ':locale_h';
32 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
33 # and mingw32 uses said silly CRT
34 $have_setlocale = 0 if $^O eq 'MSWin32' && $Config{cc} =~ /^(cl|gcc)/i;
36 print "1..", ($have_setlocale ? 115 : 98), "\n";
43 my ($n, $result) = @_;
45 print 'not ' unless ($result);
49 # First we'll do a lot of taint checking for locales.
50 # This is the easiest to test, actually, as any locale,
51 # even the default locale will taint under 'use locale'.
53 sub is_tainted { # hello, camel two.
54 local $^W; # no warnings 'undef'
56 not eval { $dummy = join("", @_), kill 0; 1 }
59 sub check_taint ($$) {
60 ok $_[0], is_tainted($_[1]);
63 sub check_taint_not ($$) {
64 ok $_[0], not is_tainted($_[1]);
67 use locale; # engage locale and therefore locale taint.
69 check_taint_not 1, $a;
71 check_taint 2, uc($a);
72 check_taint 3, "\U$a";
73 check_taint 4, ucfirst($a);
74 check_taint 5, "\u$a";
75 check_taint 6, lc($a);
76 check_taint 7, "\L$a";
77 check_taint 8, lcfirst($a);
78 check_taint 9, "\l$a";
80 check_taint 10, sprintf('%e', 123.456);
81 check_taint 11, sprintf('%f', 123.456);
82 check_taint 12, sprintf('%g', 123.456);
83 check_taint_not 13, sprintf('%d', 123.456);
84 check_taint_not 14, sprintf('%x', 123.456);
88 $_ = uc($a); # taint $_
92 /(\w)/; # taint $&, $`, $', $+, $1.
98 check_taint_not 21, $2;
100 /(.)/; # untaint $&, $`, $', $+, $1.
101 check_taint_not 22, $&;
102 check_taint_not 23, $`;
103 check_taint_not 24, $';
104 check_taint_not 25, $+;
105 check_taint_not 26, $1;
106 check_taint_not 27, $2;
108 /(\W)/; # taint $&, $`, $', $+, $1.
114 check_taint_not 33, $2;
116 /(\s)/; # taint $&, $`, $', $+, $1.
122 check_taint_not 39, $2;
124 /(\S)/; # taint $&, $`, $', $+, $1.
130 check_taint_not 45, $2;
132 $_ = $a; # untaint $_
134 check_taint_not 46, $_;
136 /(b)/; # this must not taint
137 check_taint_not 47, $&;
138 check_taint_not 48, $`;
139 check_taint_not 49, $';
140 check_taint_not 50, $+;
141 check_taint_not 51, $1;
142 check_taint_not 52, $2;
144 $_ = $a; # untaint $_
146 check_taint_not 53, $_;
148 $b = uc($a); # taint $b
149 s/(.+)/$b/; # this must taint only the $_
152 check_taint_not 55, $&;
153 check_taint_not 56, $`;
154 check_taint_not 57, $';
155 check_taint_not 58, $+;
156 check_taint_not 59, $1;
157 check_taint_not 60, $2;
159 $_ = $a; # untaint $_
161 s/(.+)/b/; # this must not taint
162 check_taint_not 61, $_;
163 check_taint_not 62, $&;
164 check_taint_not 63, $`;
165 check_taint_not 64, $';
166 check_taint_not 65, $+;
167 check_taint_not 66, $1;
168 check_taint_not 67, $2;
170 $b = $a; # untaint $b
172 ($b = $a) =~ s/\w/$&/;
173 check_taint 68, $b; # $b should be tainted.
174 check_taint_not 69, $a; # $a should be not.
176 $_ = $a; # untaint $_
178 s/(\w)/\l$1/; # this must taint
185 check_taint_not 76, $2;
187 $_ = $a; # untaint $_
189 s/(\w)/\L$1/; # this must taint
196 check_taint_not 83, $2;
198 $_ = $a; # untaint $_
200 s/(\w)/\u$1/; # this must taint
207 check_taint_not 90, $2;
209 $_ = $a; # untaint $_
211 s/(\w)/\U$1/; # this must taint
218 check_taint_not 97, $2;
220 # After all this tainting $a should be cool.
222 check_taint_not 98, $a;
224 # I think we've seen quite enough of taint.
225 # Let us do some *real* locale work now,
226 # unless setlocale() is missing (i.e. minitest).
228 exit unless $have_setlocale;
232 debug "# Scanning for locales...\n";
234 # Note that it's okay that some languages have their native names
235 # capitalized here even though that's not "right". They are lowercased
236 # anyway later during the scanning process (and besides, some clueless
237 # vendor might have them capitalized errorneously anyway).
241 Arabic:ar:dz eg sa:6 arabic8
242 Brezhoneg Breton:br:fr:1 15
243 Bulgarski Bulgarian:bg:bg:5
244 Català Catalan:ca:es:1 15
245 Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW GB2312 tw.EUC
246 Hrvatski Croatian:hr:hr:2
247 Cymraeg Welsh:cy:cy:1 14 15
249 Dansk Danish:dk:da:1 15
250 Nederlands Dutch:nl:be nl:1 15
251 English American British:en:au ca gb ie nz us uk:1 15 cp850
253 Eesti Estonian:et:ee:4 6 13
254 Suomi Finnish:fi:fi:1 15
256 Français French:fr:be ca ch fr lu:1 15
257 Deutsch German:de:at be ch de lu:1 15
258 Euskaraz Basque:eu:es fr:1 15
259 Gáidhlig Gaelic:gd:gb uk:1 14 15
260 Galego Galician:gl:es:1 15
261 Ellada Greek:el:gr:7 g8
262 Føroyskt Faroese:fo:fo:1 15
264 Greenlandic:kl:gl:4 6
265 Hebrew:iw:il:8 hebrew8
267 Íslensku Icelandic:is:is:1 15
268 Indonesian:in:id:1 15
269 Gaeilge Irish:ga:IE:1 14 15
270 Italiano Italian:it:ch it:1 15
271 Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
273 Sámi Lappish:::4 6 13
274 Latine Latin:la:va:1 15
276 Lithuanian:lt:lt:4 6 13
277 Macedonian:mk:mk:1 15
279 Norsk Norwegian:no:no:1 15
281 Polski Polish:pl:pl:2
282 Português Portuguese:po:po br:1 15
284 Russki Russian:ru:ru su ua:5 koi8 koi8r koi8u cp1251
285 Serbski Serbian:sr:yu:5
287 Slovene Slovenian:sl:si:2
288 Espanõl Spanish:es:ar bo cl co cr do ec es gt hn mx ni pa pe py sv uy ve:1 15
289 Sqhip Albanian:sq:sq:1 15
290 Svenska Swedish:sv:fi se:1 15
292 Turkish:tr:tr:9 turkish8
301 sort grep /\w/, map { chr } 0..255
306 if (setlocale(LC_ALL, $locale)) {
307 push @Locale, $locale;
311 sub decode_encodings {
314 foreach (split(/ /, shift)) {
316 push @enc, "ISO8859-$1";
317 push @enc, "iso8859$1"; # HP
319 push @enc, "roman8"; # HP
332 trylocale("ISO8859-$_");
333 trylocale("iso8859$_");
334 trylocale("iso8859-$_");
335 trylocale("iso_8859_$_");
336 trylocale("isolatin$_");
337 trylocale("isolatin-$_");
338 trylocale("iso_latin_$_");
341 foreach my $locale (split(/\n/, $locales)) {
342 my ($locale_name, $language_codes, $country_codes, $encodings) =
344 my @enc = decode_encodings($encodings);
345 foreach my $loc (split(/ /, $locale_name)) {
347 foreach my $enc (@enc) {
348 trylocale("$loc.$enc");
351 foreach my $enc (@enc) {
352 trylocale("$loc.$enc");
355 foreach my $lang (split(/ /, $language_codes)) {
357 foreach my $country (split(/ /, $country_codes)) {
358 my $lc = "${lang}_${country}";
360 foreach my $enc (@enc) {
361 trylocale("$lc.$enc");
363 my $lC = "${lang}_\U${country}";
365 foreach my $enc (@enc) {
366 trylocale("$lC.$enc");
372 setlocale(LC_ALL, "C");
374 @Locale = sort @Locale;
376 debug "# Locales = @Locale\n";
384 my ($Locale, $i, $test) = @_;
385 debug "# testing $i with locale '$Locale'\n"
386 unless $Testing{$i}{$Locale}++;
388 $Problem{$i}{$Locale} = 1;
389 debug "# failed $i with locale '$Locale'\n";
391 push @{$Okay{$i}}, $Locale;
395 foreach $Locale (@Locale) {
396 debug "# Locale = $Locale\n";
397 @Alnum_ = getalnum_();
398 debug "# \\w = @Alnum_\n";
400 unless (setlocale(LC_ALL, $Locale)) {
402 $Problem{$_}{$Locale} = -1;
407 # Sieve the uppercase and the lowercase.
413 if (/[^\d_]/) { # skip digits and the _
422 foreach (keys %UPPER) {
423 $BoThCaSe{$_}++ if exists $lower{$_};
425 foreach (keys %lower) {
426 $BoThCaSe{$_}++ if exists $UPPER{$_};
428 foreach (keys %BoThCaSe) {
433 debug "# UPPER = ", join(" ", sort keys %UPPER ), "\n";
434 debug "# lower = ", join(" ", sort keys %lower ), "\n";
435 debug "# BoThCaSe = ", join(" ", sort keys %BoThCaSe), "\n";
437 # Find the alphabets that are not alphabets in the default locale.
443 for (keys %UPPER, keys %lower) {
444 push(@Neoalpha, $_) if (/\W/);
448 @Neoalpha = sort @Neoalpha;
450 debug "# Neoalpha = @Neoalpha\n";
452 if (@Neoalpha == 0) {
453 # If we have no Neoalphas the remaining tests are no-ops.
454 debug "# no Neoalpha, skipping tests 99..102 for locale '$Locale'\n";
456 push @{$Okay{$_}}, $Locale;
463 my $word = join('', @Neoalpha);
467 tryneoalpha($Locale, 99, $1 eq $word);
470 # Cross-check the whole 8-bit character set.
472 for (map { chr } 0..255) {
473 tryneoalpha($Locale, 100,
479 # Test for read-only scalars' locale vs non-locale comparisons.
486 tryneoalpha($Locale, 101, ($a cmp "qwerty") == 0);
491 my ($from, $to, $lesser, $greater,
492 @test, %test, $test, $yes, $no, $sign);
496 $from = int(($_*@Alnum_)/10);
497 $to = $from + int(@Alnum_/10);
498 $to = $#Alnum_ if ($to > $#Alnum_);
499 $lesser = join('', @Alnum_[$from..$to]);
500 # Select a slice one character on.
502 $to = $#Alnum_ if ($to > $#Alnum_);
503 $greater = join('', @Alnum_[$from..$to]);
504 ($yes, $no, $sign) = ($lesser lt $greater
506 : ("not ", " ", -1));
507 # all these tests should FAIL (return 0).
508 # Exact lt or gt cannot be tested because
509 # in some locales, say, eacute and E may test equal.
512 $no.' ($lesser le $greater)', # 1
513 'not ($lesser ne $greater)', # 2
514 ' ($lesser eq $greater)', # 3
515 $yes.' ($lesser ge $greater)', # 4
516 $yes.' ($lesser ge $greater)', # 5
517 $yes.' ($greater le $lesser )', # 7
518 'not ($greater ne $lesser )', # 8
519 ' ($greater eq $lesser )', # 9
520 $no.' ($greater ge $lesser )', # 10
521 'not (($lesser cmp $greater) == -$sign)' # 12
523 @test{@test} = 0 x @test;
526 $test{$ti} = eval $ti;
529 tryneoalpha($Locale, 102, $test == 0);
531 debug "# lesser = '$lesser'\n";
532 debug "# greater = '$greater'\n";
533 debug "# lesser cmp greater = ",
534 $lesser cmp $greater, "\n";
535 debug "# greater cmp lesser = ",
536 $greater cmp $lesser, "\n";
537 debug "# (greater) from = $from, to = $to\n";
539 debugf("# %-40s %-4s", $ti,
540 $test{$ti} ? 'FAIL' : 'ok');
541 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
542 debugf("(%s == %4d)", $1, eval $1);
555 my ($x, $y) = (1.23, 1.23);
558 printf ''; # printf used to reset locale to "C"
561 debug "# 103..107: a = $a, b = $b, Locale = $Locale\n";
563 tryneoalpha($Locale, 103, $a eq $b);
566 my $z = sprintf ''; # sprintf used to reset locale to "C"
569 debug "# 104..107: c = $c, d = $d, Locale = $Locale\n";
571 tryneoalpha($Locale, 104, $c eq $d);
575 local $SIG{__WARN__} = sub { $w++ };
578 # the == (among other ops) used to warn for locales
579 # that had something else than "." as the radix character
581 tryneoalpha($Locale, 105, $c == 1.23);
583 tryneoalpha($Locale, 106, $c == $x);
585 tryneoalpha($Locale, 107, $c == $d);
592 debug "# 108..110: e = $e, Locale = $Locale\n";
594 tryneoalpha($Locale, 108, $e == 1.23);
596 tryneoalpha($Locale, 109, $e == $x);
598 tryneoalpha($Locale, 110, $e == $c);
601 tryneoalpha($Locale, 111, $w == 0);
605 debug "# 112..114: f = $f, locale = $Locale\n";
607 tryneoalpha($Locale, 112, $f == 1.23);
609 tryneoalpha($Locale, 113, $f == $x);
611 tryneoalpha($Locale, 114, $f == $c);
614 debug "# testing 115 with locale '$Locale'\n";
621 return $lc0 cmp $lc1;
625 return lc($_[0]) cmp lc($_[1]);
632 tryneoalpha($Locale, 115,
633 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
634 lcA($x, $z) == 0 && lcB($x, $z) == 0);
638 # Recount the errors.
641 if ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
643 print "# The failure of test 102 is not necessarily fatal.\n";
644 print "# It usually indicates a problem in the enviroment,\n";
645 print "# not in Perl itself.\n";
658 my @f = sort keys %{ $Problem{$_} };
659 my $f = join(" ", @f);
660 $f =~ s/(.{50,60}) /$1\n#\t/g;
663 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
665 "# on your system may have errors because the locale test $_\n",
666 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
670 # If your users are not using these locales you are safe for the moment,
671 # but please report this failure first to perlbug\@perl.com using the
672 # perlbug script (as described in the INSTALL file) so that the exact
673 # details of the failures can be sorted out first and then your operating
674 # system supplier can be alerted about these anomalies.
681 # Tell which locales ere okay.
686 foreach my $l (@Locale) {
688 foreach my $t (102..102) {
689 $p++ if $Problem{$t}{$l};
691 push @s, $l if $p == 0;
694 my $s = join(" ", @s);
695 $s =~ s/(.{50,60}) /$1\n#\t/g;
698 "# The following locales\n#\n",
700 "# tested okay.\n#\n",