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