cwd.t (was: Cwd has no tests?)
[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
f760b1c1 427sub utf8locale { $_[0] =~ /utf-?8/i }
06b2af23 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
f760b1c1 517 if (utf8locale($Locale)) {
518 # Until the polymorphic regexen arrive.
519 debug "# skipping UTF-8 locale '$Locale'\n";
520 } else {
6be75cd7 521 my $word = join('', @Neoalpha);
8ebc5c01 522
6be75cd7 523 $word =~ /^(\w+)$/;
8ebc5c01 524
2a680da6 525 tryneoalpha($Locale, 99, $1 eq $word);
284102e8 526 }
8ebc5c01 527
2a680da6 528 # Cross-check the whole 8-bit character set.
8ebc5c01 529
6be75cd7 530 for (map { chr } 0..255) {
2a680da6 531 tryneoalpha($Locale, 100,
532 (/\w/ xor /\W/) ||
533 (/\d/ xor /\D/) ||
534 (/\s/ xor /\S/));
284102e8 535 }
8ebc5c01 536
6be75cd7 537 # Test for read-only scalars' locale vs non-locale comparisons.
284102e8 538
284102e8 539 {
6be75cd7 540 no locale;
541 $a = "qwerty";
542 {
543 use locale;
2a680da6 544 tryneoalpha($Locale, 101, ($a cmp "qwerty") == 0);
8ebc5c01 545 }
546 }
8ebc5c01 547
6be75cd7 548 {
549 my ($from, $to, $lesser, $greater,
550 @test, %test, $test, $yes, $no, $sign);
551
552 for (0..9) {
553 # Select a slice.
554 $from = int(($_*@Alnum_)/10);
555 $to = $from + int(@Alnum_/10);
556 $to = $#Alnum_ if ($to > $#Alnum_);
557 $lesser = join('', @Alnum_[$from..$to]);
558 # Select a slice one character on.
559 $from++; $to++;
560 $to = $#Alnum_ if ($to > $#Alnum_);
561 $greater = join('', @Alnum_[$from..$to]);
562 ($yes, $no, $sign) = ($lesser lt $greater
563 ? (" ", "not ", 1)
564 : ("not ", " ", -1));
565 # all these tests should FAIL (return 0).
566 # Exact lt or gt cannot be tested because
567 # in some locales, say, eacute and E may test equal.
568 @test =
569 (
570 $no.' ($lesser le $greater)', # 1
571 'not ($lesser ne $greater)', # 2
572 ' ($lesser eq $greater)', # 3
573 $yes.' ($lesser ge $greater)', # 4
574 $yes.' ($lesser ge $greater)', # 5
575 $yes.' ($greater le $lesser )', # 7
576 'not ($greater ne $lesser )', # 8
577 ' ($greater eq $lesser )', # 9
578 $no.' ($greater ge $lesser )', # 10
579 'not (($lesser cmp $greater) == -$sign)' # 12
580 );
581 @test{@test} = 0 x @test;
582 $test = 0;
284102e8 583 for my $ti (@test) {
6be75cd7 584 $test{$ti} = eval $ti;
585 $test ||= $test{$ti}
284102e8 586 }
2a680da6 587 tryneoalpha($Locale, 102, $test == 0);
6be75cd7 588 if ($test) {
6be75cd7 589 debug "# lesser = '$lesser'\n";
590 debug "# greater = '$greater'\n";
591 debug "# lesser cmp greater = ",
592 $lesser cmp $greater, "\n";
593 debug "# greater cmp lesser = ",
594 $greater cmp $lesser, "\n";
595 debug "# (greater) from = $from, to = $to\n";
596 for my $ti (@test) {
597 debugf("# %-40s %-4s", $ti,
598 $test{$ti} ? 'FAIL' : 'ok');
599 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
600 debugf("(%s == %4d)", $1, eval $1);
601 }
602 debug "\n#";
603 }
284102e8 604
6be75cd7 605 last;
606 }
284102e8 607 }
8ebc5c01 608 }
609 }
6be75cd7 610
611 use locale;
612
613 my ($x, $y) = (1.23, 1.23);
614
615 my $a = "$x";
616 printf ''; # printf used to reset locale to "C"
617 my $b = "$y";
618
2a680da6 619 debug "# 103..107: a = $a, b = $b, Locale = $Locale\n";
620
621 tryneoalpha($Locale, 103, $a eq $b);
6be75cd7 622
623 my $c = "$x";
624 my $z = sprintf ''; # sprintf used to reset locale to "C"
625 my $d = "$y";
626
2a680da6 627 debug "# 104..107: c = $c, d = $d, Locale = $Locale\n";
6be75cd7 628
2a680da6 629 tryneoalpha($Locale, 104, $c eq $d);
6be75cd7 630
2a680da6 631 {
9f1b1f2d 632 use warnings;
2a680da6 633 my $w = 0;
634 local $SIG{__WARN__} = sub { $w++ };
6be75cd7 635
2a680da6 636 # the == (among other ops) used to warn for locales
637 # that had something else than "." as the radix character
6be75cd7 638
2a680da6 639 tryneoalpha($Locale, 105, $c == 1.23);
6be75cd7 640
2a680da6 641 tryneoalpha($Locale, 106, $c == $x);
6be75cd7 642
2a680da6 643 tryneoalpha($Locale, 107, $c == $d);
6be75cd7 644
2a680da6 645 {
646 no locale;
6be75cd7 647
2a680da6 648 my $e = "$x";
6be75cd7 649
2a680da6 650 debug "# 108..110: e = $e, Locale = $Locale\n";
6be75cd7 651
2a680da6 652 tryneoalpha($Locale, 108, $e == 1.23);
6be75cd7 653
2a680da6 654 tryneoalpha($Locale, 109, $e == $x);
655
656 tryneoalpha($Locale, 110, $e == $c);
6be75cd7 657 }
2a680da6 658
659 tryneoalpha($Locale, 111, $w == 0);
6be75cd7 660
2a680da6 661 my $f = "1.23";
662
663 debug "# 112..114: f = $f, locale = $Locale\n";
664
665 tryneoalpha($Locale, 112, $f == 1.23);
6be75cd7 666
2a680da6 667 tryneoalpha($Locale, 113, $f == $x);
668
669 tryneoalpha($Locale, 114, $f == $c);
6be75cd7 670 }
671
26d80d95 672 # Does taking lc separately differ from taking
673 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
674 # The bug was in the caching of the 'o'-magic.
2a680da6 675 {
676 use locale;
6be75cd7 677
2a680da6 678 sub lcA {
679 my $lc0 = lc $_[0];
680 my $lc1 = lc $_[1];
681 return $lc0 cmp $lc1;
682 }
6be75cd7 683
2a680da6 684 sub lcB {
685 return lc($_[0]) cmp lc($_[1]);
686 }
6be75cd7 687
2a680da6 688 my $x = "ab";
689 my $y = "aa";
690 my $z = "AB";
6be75cd7 691
2a680da6 692 tryneoalpha($Locale, 115,
693 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
694 lcA($x, $z) == 0 && lcB($x, $z) == 0);
6be75cd7 695 }
d8093b23 696
26d80d95 697 # Does lc of an UPPER (if different from the UPPER) match
698 # case-insensitively the UPPER, and does the UPPER match
699 # case-insensitively the lc of the UPPER. And vice versa.
f760b1c1 700 if (utf8locale($Locale)) {
701 # Until the polymorphic regexen arrive.
702 debug "# skipping UTF-8 locale '$Locale'\n";
703 } else {
d8093b23 704 use locale;
705
706 my @f = ();
707 foreach my $x (keys %UPPER) {
708 my $y = lc $x;
709 next unless uc $y eq $x;
710 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
711 }
712 foreach my $x (keys %lower) {
713 my $y = uc $x;
714 next unless lc $y eq $x;
715 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
716 }
717 tryneoalpha($Locale, 116, @f == 0);
26d80d95 718 if (@f) {
719 print "# failed 116 locale '$Locale' characters @f\n"
720 }
d8093b23 721 }
68d47915 722
8ebc5c01 723}
284102e8 724
2a680da6 725# Recount the errors.
726
26d80d95 727foreach (99..$last) {
2a680da6 728 if ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
097ee67d 729 if ($_ == 102) {
730 print "# The failure of test 102 is not necessarily fatal.\n";
284102e8 731 print "# It usually indicates a problem in the enviroment,\n";
732 print "# not in Perl itself.\n";
733 }
734 print "not ";
8ebc5c01 735 }
284102e8 736 print "ok $_\n";
8ebc5c01 737}
fb73857a 738
2a680da6 739# Give final advice.
740
284102e8 741my $didwarn = 0;
742
26d80d95 743foreach (99..$last) {
284102e8 744 if ($Problem{$_}) {
745 my @f = sort keys %{ $Problem{$_} };
746 my $f = join(" ", @f);
747 $f =~ s/(.{50,60}) /$1\n#\t/g;
2a680da6 748 print
749 "#\n",
750 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
284102e8 751 "#\t", $f, "\n#\n",
752 "# on your system may have errors because the locale test $_\n",
753 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
754 ".\n";
2a680da6 755 print <<EOW;
284102e8 756#
757# If your users are not using these locales you are safe for the moment,
758# but please report this failure first to perlbug\@perl.com using the
759# perlbug script (as described in the INSTALL file) so that the exact
760# details of the failures can be sorted out first and then your operating
761# system supplier can be alerted about these anomalies.
762#
763EOW
764 $didwarn = 1;
fb73857a 765 }
766}
774d564b 767
26d80d95 768# Tell which locales were okay and which were not.
2a680da6 769
284102e8 770if ($didwarn) {
26d80d95 771 my (@s, @F);
284102e8 772
773 foreach my $l (@Locale) {
774 my $p = 0;
26d80d95 775 foreach my $t (102..$last) {
284102e8 776 $p++ if $Problem{$t}{$l};
8ebc5c01 777 }
284102e8 778 push @s, $l if $p == 0;
26d80d95 779 push @F, $l unless $p == 0;
8ebc5c01 780 }
284102e8 781
68d47915 782 if (@s) {
783 my $s = join(" ", @s);
784 $s =~ s/(.{50,60}) /$1\n#\t/g;
785
786 warn
787 "# The following locales\n#\n",
788 "#\t", $s, "\n#\n",
789 "# tested okay.\n#\n",
790 } else {
26d80d95 791 warn "# None of your locales were fully okay.\n";
792 }
793
794 if (@F) {
795 my $F = join(" ", @F);
796 $F =~ s/(.{50,60}) /$1\n#\t/g;
797
798 warn
799 "# The following locales\n#\n",
800 "#\t", $F, "\n#\n",
801 "# had problems.\n#\n",
802 } else {
803 warn "# None of your locales were broken.\n";
68d47915 804 }
8ebc5c01 805}
90248788 806
807# eof