Integrate change #10394 from maintperl; lexical file scope leakage.
[p5sagit/p5-mst-13.2.git] / t / pragma / locale.t
CommitLineData
8ebc5c01 1#!./perl -wT
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
f9cbebe1 6 unshift @INC, '.';
b002077a 7 require Config; import Config;
97a0514d 8 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
b002077a 9 print "1..0\n";
10 exit;
11 }
8ebc5c01 12}
13
14use strict;
15
284102e8 16my $debug = 1;
17
db4b7445 18use Dumpvalue;
19
20my $dumper = Dumpvalue->new(
21 tick => qq{"},
22 quoteHighBit => 0,
23 unctrl => "quote"
24 );
6be75cd7 25sub debug {
db4b7445 26 return unless $debug;
27 my($mess) = join "", @_;
28 chop $mess;
29 print $dumper->stringify($mess,1), "\n";
6be75cd7 30}
31
32sub debugf {
33 printf @_ if $debug;
34}
35
8ebc5c01 36my $have_setlocale = 0;
37eval {
38 require POSIX;
39 import POSIX ':locale_h';
40 $have_setlocale++;
41};
42
6dead956 43# Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
f6c6487a 44# and mingw32 uses said silly CRT
45$have_setlocale = 0 if $^O eq 'MSWin32' && $Config{cc} =~ /^(cl|gcc)/i;
6dead956 46
26d80d95 47my $last = $have_setlocale ? 116 : 98;
48
49print "1..$last\n";
8ebc5c01 50
097ee67d 51use vars qw(&LC_ALL);
8ebc5c01 52
097ee67d 53my $a = 'abc %';
8ebc5c01 54
55sub ok {
56 my ($n, $result) = @_;
57
58 print 'not ' unless ($result);
59 print "ok $n\n";
60}
61
62# First we'll do a lot of taint checking for locales.
63# This is the easiest to test, actually, as any locale,
64# even the default locale will taint under 'use locale'.
65
66sub is_tainted { # hello, camel two.
9f1b1f2d 67 no warnings 'uninitialized' ;
8ebc5c01 68 my $dummy;
69 not eval { $dummy = join("", @_), kill 0; 1 }
70}
71
72sub check_taint ($$) {
73 ok $_[0], is_tainted($_[1]);
74}
75
76sub check_taint_not ($$) {
77 ok $_[0], not is_tainted($_[1]);
78}
79
80use locale; # engage locale and therefore locale taint.
81
82check_taint_not 1, $a;
83
84check_taint 2, uc($a);
85check_taint 3, "\U$a";
86check_taint 4, ucfirst($a);
87check_taint 5, "\u$a";
88check_taint 6, lc($a);
89check_taint 7, "\L$a";
90check_taint 8, lcfirst($a);
91check_taint 9, "\l$a";
92
ff9121f8 93check_taint_not 10, sprintf('%e', 123.456);
94check_taint_not 11, sprintf('%f', 123.456);
95check_taint_not 12, sprintf('%g', 123.456);
8ebc5c01 96check_taint_not 13, sprintf('%d', 123.456);
97check_taint_not 14, sprintf('%x', 123.456);
98
99$_ = $a; # untaint $_
100
101$_ = uc($a); # taint $_
102
103check_taint 15, $_;
104
105/(\w)/; # taint $&, $`, $', $+, $1.
106check_taint 16, $&;
107check_taint 17, $`;
108check_taint 18, $';
109check_taint 19, $+;
110check_taint 20, $1;
111check_taint_not 21, $2;
112
113/(.)/; # untaint $&, $`, $', $+, $1.
114check_taint_not 22, $&;
115check_taint_not 23, $`;
116check_taint_not 24, $';
117check_taint_not 25, $+;
118check_taint_not 26, $1;
119check_taint_not 27, $2;
120
121/(\W)/; # taint $&, $`, $', $+, $1.
122check_taint 28, $&;
123check_taint 29, $`;
124check_taint 30, $';
125check_taint 31, $+;
126check_taint 32, $1;
127check_taint_not 33, $2;
128
129/(\s)/; # taint $&, $`, $', $+, $1.
130check_taint 34, $&;
131check_taint 35, $`;
132check_taint 36, $';
133check_taint 37, $+;
134check_taint 38, $1;
135check_taint_not 39, $2;
136
137/(\S)/; # taint $&, $`, $', $+, $1.
138check_taint 40, $&;
139check_taint 41, $`;
140check_taint 42, $';
141check_taint 43, $+;
142check_taint 44, $1;
143check_taint_not 45, $2;
144
145$_ = $a; # untaint $_
146
147check_taint_not 46, $_;
148
149/(b)/; # this must not taint
150check_taint_not 47, $&;
151check_taint_not 48, $`;
152check_taint_not 49, $';
153check_taint_not 50, $+;
154check_taint_not 51, $1;
155check_taint_not 52, $2;
156
157$_ = $a; # untaint $_
158
159check_taint_not 53, $_;
160
161$b = uc($a); # taint $b
162s/(.+)/$b/; # this must taint only the $_
163
164check_taint 54, $_;
165check_taint_not 55, $&;
166check_taint_not 56, $`;
167check_taint_not 57, $';
168check_taint_not 58, $+;
169check_taint_not 59, $1;
170check_taint_not 60, $2;
171
172$_ = $a; # untaint $_
173
174s/(.+)/b/; # this must not taint
175check_taint_not 61, $_;
176check_taint_not 62, $&;
177check_taint_not 63, $`;
178check_taint_not 64, $';
179check_taint_not 65, $+;
180check_taint_not 66, $1;
181check_taint_not 67, $2;
182
183$b = $a; # untaint $b
184
185($b = $a) =~ s/\w/$&/;
186check_taint 68, $b; # $b should be tainted.
187check_taint_not 69, $a; # $a should be not.
188
189$_ = $a; # untaint $_
190
191s/(\w)/\l$1/; # this must taint
192check_taint 70, $_;
193check_taint 71, $&;
194check_taint 72, $`;
195check_taint 73, $';
196check_taint 74, $+;
197check_taint 75, $1;
198check_taint_not 76, $2;
199
200$_ = $a; # untaint $_
201
202s/(\w)/\L$1/; # this must taint
203check_taint 77, $_;
204check_taint 78, $&;
205check_taint 79, $`;
206check_taint 80, $';
207check_taint 81, $+;
208check_taint 82, $1;
209check_taint_not 83, $2;
210
211$_ = $a; # untaint $_
212
213s/(\w)/\u$1/; # this must taint
214check_taint 84, $_;
215check_taint 85, $&;
216check_taint 86, $`;
217check_taint 87, $';
218check_taint 88, $+;
219check_taint 89, $1;
220check_taint_not 90, $2;
221
222$_ = $a; # untaint $_
223
224s/(\w)/\U$1/; # this must taint
225check_taint 91, $_;
226check_taint 92, $&;
227check_taint 93, $`;
228check_taint 94, $';
229check_taint 95, $+;
230check_taint 96, $1;
231check_taint_not 97, $2;
232
233# After all this tainting $a should be cool.
234
235check_taint_not 98, $a;
236
237# I think we've seen quite enough of taint.
238# Let us do some *real* locale work now,
284102e8 239# unless setlocale() is missing (i.e. minitest).
8ebc5c01 240
241exit unless $have_setlocale;
242
284102e8 243# Find locales.
244
6be75cd7 245debug "# Scanning for locales...\n";
246
247# Note that it's okay that some languages have their native names
248# capitalized here even though that's not "right". They are lowercased
249# anyway later during the scanning process (and besides, some clueless
250# vendor might have them capitalized errorneously anyway).
251
284102e8 252my $locales = <<EOF;
6be75cd7 253Afrikaans:af:za:1 15
284102e8 254Arabic:ar:dz eg sa:6 arabic8
6be75cd7 255Brezhoneg Breton:br:fr:1 15
256Bulgarski Bulgarian:bg:bg:5
dd8482fc 257Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
6be75cd7 258Hrvatski Croatian:hr:hr:2
259Cymraeg Welsh:cy:cy:1 14 15
284102e8 260Czech:cs:cz:2
6be75cd7 261Dansk Danish:dk:da:1 15
262Nederlands Dutch:nl:be nl:1 15
dd8482fc 263English American British:en:au ca gb ie nz us uk zw:1 15 cp850
6be75cd7 264Esperanto:eo:eo:3
265Eesti Estonian:et:ee:4 6 13
266Suomi Finnish:fi:fi:1 15
267Flamish::fl:1 15
6be75cd7 268Deutsch German:de:at be ch de lu:1 15
269Euskaraz Basque:eu:es fr:1 15
6be75cd7 270Galego Galician:gl:es:1 15
271Ellada Greek:el:gr:7 g8
6be75cd7 272Frysk:fy:nl:1 15
273Greenlandic:kl:gl:4 6
284102e8 274Hebrew:iw:il:8 hebrew8
275Hungarian:hu:hu:2
6be75cd7 276Indonesian:in:id:1 15
277Gaeilge Irish:ga:IE:1 14 15
278Italiano Italian:it:ch it:1 15
279Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
284102e8 280Korean:ko:kr:
6be75cd7 281Latine Latin:la:va:1 15
282Latvian:lv:lv:4 6 13
283Lithuanian:lt:lt:4 6 13
284Macedonian:mk:mk:1 15
285Maltese:mt:mt:3
dd8482fc 286Moldovan:mo:mo:2
287Norsk Norwegian:no no\@nynorsk:no:1 15
6be75cd7 288Occitan:oc:es:1 15
289Polski Polish:pl:pl:2
284102e8 290Rumanian:ro:ro:2
a528dad0 291Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
6be75cd7 292Serbski Serbian:sr:yu:5
284102e8 293Slovak:sk:sk:2
6be75cd7 294Slovene Slovenian:sl:si:2
d43ce814 295Sqhip Albanian:sq:sq:1 15
296Svenska Swedish:sv:fi se:1 15
6be75cd7 297Thai:th:th:11 tis620
284102e8 298Turkish:tr:tr:9 turkish8
dd8482fc 299Yiddish:yi::1 15
284102e8 300EOF
301
ee50adbe 302if ($^O eq 'os390') {
dd8482fc 303 # These cause heartburn. Broken locales?
ee50adbe 304 $locales =~ s/Svenska Swedish:sv:fi se:1 15\n//;
305 $locales =~ s/Thai:th:th:11 tis620\n//;
306}
307
f9cbebe1 308sub in_utf8 () { $^H & 0x08 }
309
310if (in_utf8) {
311 require "pragma/locale/utf8";
312} else {
313 require "pragma/locale/latin1";
314}
315
284102e8 316my @Locale;
317my $Locale;
318my @Alnum_;
319
320sub getalnum_ {
8ebc5c01 321 sort grep /\w/, map { chr } 0..255
322}
323
284102e8 324sub trylocale {
325 my $locale = shift;
326 if (setlocale(LC_ALL, $locale)) {
327 push @Locale, $locale;
328 }
329}
8ebc5c01 330
284102e8 331sub decode_encodings {
332 my @enc;
8ebc5c01 333
284102e8 334 foreach (split(/ /, shift)) {
335 if (/^(\d+)$/) {
336 push @enc, "ISO8859-$1";
337 push @enc, "iso8859$1"; # HP
338 if ($1 eq '1') {
339 push @enc, "roman8"; # HP
340 }
341 } else {
342 push @enc, $_;
dd8482fc 343 push @enc, "$_.UTF-8";
8ebc5c01 344 }
345 }
ee50adbe 346 if ($^O eq 'os390') {
347 push @enc, qw(IBM-037 IBM-819 IBM-1047);
348 }
8ebc5c01 349
284102e8 350 return @enc;
8ebc5c01 351}
352
284102e8 353trylocale("C");
354trylocale("POSIX");
355foreach (0..15) {
356 trylocale("ISO8859-$_");
284102e8 357 trylocale("iso8859$_");
097ee67d 358 trylocale("iso8859-$_");
359 trylocale("iso_8859_$_");
360 trylocale("isolatin$_");
361 trylocale("isolatin-$_");
362 trylocale("iso_latin_$_");
8ebc5c01 363}
364
645e49ed 365# Sanitize the environment so that we can run the external 'locale'
366# program without the taint mode getting grumpy.
cce5967e 367
368# $ENV{PATH} is special in VMS.
369delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
370
371# Other subversive stuff.
372delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
dd8482fc 373
21477fb4 374if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
dd8482fc 375 while (<LOCALES>) {
376 chomp;
377 trylocale($_);
284102e8 378 }
dd8482fc 379 close(LOCALES);
a6259068 380} elsif ($^O eq 'VMS' && defined($ENV{'SYS$I18N_LOCALE'}) && -d 'SYS$I18N_LOCALE') {
381# The SYS$I18N_LOCALE logical name search list was not present on
382# VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
383 opendir(LOCALES, "SYS\$I18N_LOCALE:");
384 while ($_ = readdir(LOCALES)) {
385 chomp;
386 trylocale($_);
387 }
388 close(LOCALES);
dd8482fc 389} else {
390
391 # This is going to be slow.
392
393 foreach my $locale (split(/\n/, $locales)) {
394 my ($locale_name, $language_codes, $country_codes, $encodings) =
395 split(/:/, $locale);
396 my @enc = decode_encodings($encodings);
397 foreach my $loc (split(/ /, $locale_name)) {
398 trylocale($loc);
284102e8 399 foreach my $enc (@enc) {
dd8482fc 400 trylocale("$loc.$enc");
284102e8 401 }
dd8482fc 402 $loc = lc $loc;
284102e8 403 foreach my $enc (@enc) {
dd8482fc 404 trylocale("$loc.$enc");
405 }
406 }
407 foreach my $lang (split(/ /, $language_codes)) {
408 trylocale($lang);
409 foreach my $country (split(/ /, $country_codes)) {
410 my $lc = "${lang}_${country}";
411 trylocale($lc);
412 foreach my $enc (@enc) {
413 trylocale("$lc.$enc");
414 }
415 my $lC = "${lang}_\U${country}";
416 trylocale($lC);
417 foreach my $enc (@enc) {
418 trylocale("$lC.$enc");
419 }
284102e8 420 }
421 }
422 }
423}
4599a1de 424
d43ce814 425setlocale(LC_ALL, "C");
426
8ac0d9e6 427sub utf8locale { $_[0] =~ /utf-?8/i }
428
4599a1de 429@Locale = sort @Locale;
430
284102e8 431debug "# Locales = @Locale\n";
8ebc5c01 432
284102e8 433my %Problem;
2a680da6 434my %Okay;
435my %Testing;
097ee67d 436my @Neoalpha;
d8093b23 437my %Neoalpha;
284102e8 438
2a680da6 439sub tryneoalpha {
440 my ($Locale, $i, $test) = @_;
2a680da6 441 unless ($test) {
442 $Problem{$i}{$Locale} = 1;
443 debug "# failed $i with locale '$Locale'\n";
444 } else {
445 push @{$Okay{$i}}, $Locale;
446 }
447}
448
284102e8 449foreach $Locale (@Locale) {
450 debug "# Locale = $Locale\n";
451 @Alnum_ = getalnum_();
db4b7445 452 debug "# w = ", join("",@Alnum_), "\n";
284102e8 453
454 unless (setlocale(LC_ALL, $Locale)) {
455 foreach (99..103) {
456 $Problem{$_}{$Locale} = -1;
8ebc5c01 457 }
284102e8 458 next;
8ebc5c01 459 }
8ebc5c01 460
284102e8 461 # Sieve the uppercase and the lowercase.
462
097ee67d 463 my %UPPER = ();
464 my %lower = ();
465 my %BoThCaSe = ();
284102e8 466 for (@Alnum_) {
467 if (/[^\d_]/) { # skip digits and the _
468 if (uc($_) eq $_) {
469 $UPPER{$_} = $_;
470 }
471 if (lc($_) eq $_) {
472 $lower{$_} = $_;
473 }
474 }
475 }
476 foreach (keys %UPPER) {
097ee67d 477 $BoThCaSe{$_}++ if exists $lower{$_};
284102e8 478 }
479 foreach (keys %lower) {
097ee67d 480 $BoThCaSe{$_}++ if exists $UPPER{$_};
284102e8 481 }
097ee67d 482 foreach (keys %BoThCaSe) {
284102e8 483 delete $UPPER{$_};
484 delete $lower{$_};
485 }
486
db4b7445 487 debug "# UPPER = ", join("", sort keys %UPPER ), "\n";
488 debug "# lower = ", join("", sort keys %lower ), "\n";
489 debug "# BoThCaSe = ", join("", sort keys %BoThCaSe), "\n";
284102e8 490
491 # Find the alphabets that are not alphabets in the default locale.
8ebc5c01 492
284102e8 493 {
494 no locale;
8ebc5c01 495
284102e8 496 @Neoalpha = ();
497 for (keys %UPPER, keys %lower) {
498 push(@Neoalpha, $_) if (/\W/);
d8093b23 499 $Neoalpha{$_} = $_;
284102e8 500 }
8ebc5c01 501 }
8ebc5c01 502
284102e8 503 @Neoalpha = sort @Neoalpha;
8ebc5c01 504
db4b7445 505 debug "# Neoalpha = ", join("",@Neoalpha), "\n";
8ebc5c01 506
284102e8 507 if (@Neoalpha == 0) {
508 # If we have no Neoalphas the remaining tests are no-ops.
6be75cd7 509 debug "# no Neoalpha, skipping tests 99..102 for locale '$Locale'\n";
a88c3d7c 510 foreach (99..102) {
511 push @{$Okay{$_}}, $Locale;
512 }
6be75cd7 513 } else {
8ebc5c01 514
6be75cd7 515 # Test \w.
284102e8 516
8ac0d9e6 517 if (utf8locale($Locale)) {
518 # utf8 and locales do not mix.
519 debug "# skipping UTF-8 locale '$Locale'\n";
520 } else {
521 my $word = join('', @Neoalpha);
8ebc5c01 522
8ac0d9e6 523 $word =~ /^(\w+)$/;
524
525 tryneoalpha($Locale, 99, $1 eq $word);
526 }
2a680da6 527 # Cross-check the whole 8-bit character set.
8ebc5c01 528
6be75cd7 529 for (map { chr } 0..255) {
2a680da6 530 tryneoalpha($Locale, 100,
531 (/\w/ xor /\W/) ||
532 (/\d/ xor /\D/) ||
533 (/\s/ xor /\S/));
284102e8 534 }
8ebc5c01 535
6be75cd7 536 # Test for read-only scalars' locale vs non-locale comparisons.
284102e8 537
284102e8 538 {
6be75cd7 539 no locale;
540 $a = "qwerty";
541 {
542 use locale;
2a680da6 543 tryneoalpha($Locale, 101, ($a cmp "qwerty") == 0);
8ebc5c01 544 }
545 }
8ebc5c01 546
6be75cd7 547 {
548 my ($from, $to, $lesser, $greater,
549 @test, %test, $test, $yes, $no, $sign);
550
551 for (0..9) {
552 # Select a slice.
553 $from = int(($_*@Alnum_)/10);
554 $to = $from + int(@Alnum_/10);
555 $to = $#Alnum_ if ($to > $#Alnum_);
556 $lesser = join('', @Alnum_[$from..$to]);
557 # Select a slice one character on.
558 $from++; $to++;
559 $to = $#Alnum_ if ($to > $#Alnum_);
560 $greater = join('', @Alnum_[$from..$to]);
561 ($yes, $no, $sign) = ($lesser lt $greater
562 ? (" ", "not ", 1)
563 : ("not ", " ", -1));
564 # all these tests should FAIL (return 0).
565 # Exact lt or gt cannot be tested because
566 # in some locales, say, eacute and E may test equal.
567 @test =
568 (
569 $no.' ($lesser le $greater)', # 1
570 'not ($lesser ne $greater)', # 2
571 ' ($lesser eq $greater)', # 3
572 $yes.' ($lesser ge $greater)', # 4
573 $yes.' ($lesser ge $greater)', # 5
574 $yes.' ($greater le $lesser )', # 7
575 'not ($greater ne $lesser )', # 8
576 ' ($greater eq $lesser )', # 9
577 $no.' ($greater ge $lesser )', # 10
578 'not (($lesser cmp $greater) == -$sign)' # 12
579 );
580 @test{@test} = 0 x @test;
581 $test = 0;
284102e8 582 for my $ti (@test) {
6be75cd7 583 $test{$ti} = eval $ti;
584 $test ||= $test{$ti}
284102e8 585 }
2a680da6 586 tryneoalpha($Locale, 102, $test == 0);
6be75cd7 587 if ($test) {
6be75cd7 588 debug "# lesser = '$lesser'\n";
589 debug "# greater = '$greater'\n";
590 debug "# lesser cmp greater = ",
591 $lesser cmp $greater, "\n";
592 debug "# greater cmp lesser = ",
593 $greater cmp $lesser, "\n";
594 debug "# (greater) from = $from, to = $to\n";
595 for my $ti (@test) {
596 debugf("# %-40s %-4s", $ti,
597 $test{$ti} ? 'FAIL' : 'ok');
598 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
599 debugf("(%s == %4d)", $1, eval $1);
600 }
601 debug "\n#";
602 }
284102e8 603
6be75cd7 604 last;
605 }
284102e8 606 }
8ebc5c01 607 }
608 }
6be75cd7 609
610 use locale;
611
612 my ($x, $y) = (1.23, 1.23);
613
614 my $a = "$x";
615 printf ''; # printf used to reset locale to "C"
616 my $b = "$y";
617
2a680da6 618 debug "# 103..107: a = $a, b = $b, Locale = $Locale\n";
619
620 tryneoalpha($Locale, 103, $a eq $b);
6be75cd7 621
622 my $c = "$x";
623 my $z = sprintf ''; # sprintf used to reset locale to "C"
624 my $d = "$y";
625
2a680da6 626 debug "# 104..107: c = $c, d = $d, Locale = $Locale\n";
6be75cd7 627
2a680da6 628 tryneoalpha($Locale, 104, $c eq $d);
6be75cd7 629
2a680da6 630 {
9f1b1f2d 631 use warnings;
2a680da6 632 my $w = 0;
633 local $SIG{__WARN__} = sub { $w++ };
6be75cd7 634
2a680da6 635 # the == (among other ops) used to warn for locales
636 # that had something else than "." as the radix character
6be75cd7 637
2a680da6 638 tryneoalpha($Locale, 105, $c == 1.23);
6be75cd7 639
2a680da6 640 tryneoalpha($Locale, 106, $c == $x);
6be75cd7 641
2a680da6 642 tryneoalpha($Locale, 107, $c == $d);
6be75cd7 643
2a680da6 644 {
645 no locale;
6be75cd7 646
2a680da6 647 my $e = "$x";
6be75cd7 648
2a680da6 649 debug "# 108..110: e = $e, Locale = $Locale\n";
6be75cd7 650
2a680da6 651 tryneoalpha($Locale, 108, $e == 1.23);
6be75cd7 652
2a680da6 653 tryneoalpha($Locale, 109, $e == $x);
654
655 tryneoalpha($Locale, 110, $e == $c);
6be75cd7 656 }
2a680da6 657
658 tryneoalpha($Locale, 111, $w == 0);
6be75cd7 659
2a680da6 660 my $f = "1.23";
661
662 debug "# 112..114: f = $f, locale = $Locale\n";
663
664 tryneoalpha($Locale, 112, $f == 1.23);
6be75cd7 665
2a680da6 666 tryneoalpha($Locale, 113, $f == $x);
667
668 tryneoalpha($Locale, 114, $f == $c);
6be75cd7 669 }
670
26d80d95 671 # Does taking lc separately differ from taking
672 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
673 # The bug was in the caching of the 'o'-magic.
2a680da6 674 {
675 use locale;
6be75cd7 676
2a680da6 677 sub lcA {
678 my $lc0 = lc $_[0];
679 my $lc1 = lc $_[1];
680 return $lc0 cmp $lc1;
681 }
6be75cd7 682
2a680da6 683 sub lcB {
684 return lc($_[0]) cmp lc($_[1]);
685 }
6be75cd7 686
2a680da6 687 my $x = "ab";
688 my $y = "aa";
689 my $z = "AB";
6be75cd7 690
2a680da6 691 tryneoalpha($Locale, 115,
692 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
693 lcA($x, $z) == 0 && lcB($x, $z) == 0);
6be75cd7 694 }
d8093b23 695
26d80d95 696 # Does lc of an UPPER (if different from the UPPER) match
697 # case-insensitively the UPPER, and does the UPPER match
698 # case-insensitively the lc of the UPPER. And vice versa.
3ba0e062 699 {
8ac0d9e6 700 if (utf8locale($Locale)) {
701 # utf8 and locales do not mix.
702 debug "# skipping UTF-8 locale '$Locale'\n";
703 } else {
704 use locale;
705 use locale;
706 no utf8; # so that the native 8-bit characters work
707
708 my @f = ();
709 foreach my $x (keys %UPPER) {
710 my $y = lc $x;
711 next unless uc $y eq $x;
712 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
713 }
714 foreach my $x (keys %lower) {
715 my $y = uc $x;
716 next unless lc $y eq $x;
717 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
718 }
719 tryneoalpha($Locale, 116, @f == 0);
720 if (@f) {
721 print "# failed 116 locale '$Locale' characters @f\n"
722 }
26d80d95 723 }
d8093b23 724 }
8ebc5c01 725}
284102e8 726
2a680da6 727# Recount the errors.
728
26d80d95 729foreach (99..$last) {
2a680da6 730 if ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
097ee67d 731 if ($_ == 102) {
732 print "# The failure of test 102 is not necessarily fatal.\n";
284102e8 733 print "# It usually indicates a problem in the enviroment,\n";
734 print "# not in Perl itself.\n";
735 }
736 print "not ";
8ebc5c01 737 }
284102e8 738 print "ok $_\n";
8ebc5c01 739}
fb73857a 740
2a680da6 741# Give final advice.
742
284102e8 743my $didwarn = 0;
744
26d80d95 745foreach (99..$last) {
284102e8 746 if ($Problem{$_}) {
747 my @f = sort keys %{ $Problem{$_} };
748 my $f = join(" ", @f);
749 $f =~ s/(.{50,60}) /$1\n#\t/g;
2a680da6 750 print
751 "#\n",
752 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
284102e8 753 "#\t", $f, "\n#\n",
754 "# on your system may have errors because the locale test $_\n",
755 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
756 ".\n";
2a680da6 757 print <<EOW;
284102e8 758#
759# If your users are not using these locales you are safe for the moment,
760# but please report this failure first to perlbug\@perl.com using the
761# perlbug script (as described in the INSTALL file) so that the exact
762# details of the failures can be sorted out first and then your operating
763# system supplier can be alerted about these anomalies.
764#
765EOW
766 $didwarn = 1;
fb73857a 767 }
768}
774d564b 769
26d80d95 770# Tell which locales were okay and which were not.
2a680da6 771
284102e8 772if ($didwarn) {
26d80d95 773 my (@s, @F);
284102e8 774
775 foreach my $l (@Locale) {
776 my $p = 0;
26d80d95 777 foreach my $t (102..$last) {
284102e8 778 $p++ if $Problem{$t}{$l};
8ebc5c01 779 }
284102e8 780 push @s, $l if $p == 0;
26d80d95 781 push @F, $l unless $p == 0;
8ebc5c01 782 }
284102e8 783
68d47915 784 if (@s) {
785 my $s = join(" ", @s);
786 $s =~ s/(.{50,60}) /$1\n#\t/g;
787
788 warn
789 "# The following locales\n#\n",
790 "#\t", $s, "\n#\n",
791 "# tested okay.\n#\n",
792 } else {
26d80d95 793 warn "# None of your locales were fully okay.\n";
794 }
795
796 if (@F) {
797 my $F = join(" ", @F);
798 $F =~ s/(.{50,60}) /$1\n#\t/g;
799
800 warn
801 "# The following locales\n#\n",
802 "#\t", $F, "\n#\n",
803 "# had problems.\n#\n",
804 } else {
805 warn "# None of your locales were broken.\n";
68d47915 806 }
8ebc5c01 807}
90248788 808
809# eof