This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
lib/locale.t: Improve debug output
[perl5.git] / lib / locale.t
1 #!./perl -wT
2
3 # This tests plain 'use locale' and adorned 'use locale ":not_characters"'
4 # Because these pragmas are compile time, and I (khw) am trying to test
5 # without using 'eval' as much as possible, which might cloud the issue,  the
6 # crucial parts of the code are duplicated in a block for each pragma.
7
8 # To make a TODO test, add the string 'TODO' to its %test_names value
9
10 binmode STDOUT, ':utf8';
11 binmode STDERR, ':utf8';
12
13 BEGIN {
14     chdir 't' if -d 't';
15     @INC = '../lib';
16     unshift @INC, '.';
17     require Config; import Config;
18     if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
19         print "1..0\n";
20         exit;
21     }
22     $| = 1;
23 }
24
25 use strict;
26 use feature 'fc';
27
28 my $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
29
30 # Certain tests have been shown to be problematical for a few locales.  Don't
31 # fail them unless at least this percentage of the tested locales fail.
32 my $acceptable_fold_failure_percentage = 5;
33
34 use Dumpvalue;
35
36 my $dumper = Dumpvalue->new(
37                             tick => qq{"},
38                             quoteHighBit => 0,
39                             unctrl => "quote"
40                            );
41 sub debug {
42   return unless $debug;
43   my($mess) = join "", @_;
44   chop $mess;
45   print $dumper->stringify($mess,1), "\n";
46 }
47
48 sub debugf {
49     printf @_ if $debug;
50 }
51
52 my $have_setlocale = 0;
53 eval {
54     require POSIX;
55     import POSIX ':locale_h';
56     $have_setlocale++;
57 };
58
59 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
60 # and mingw32 uses said silly CRT
61 # This doesn't seem to be an issue any more, at least on Windows XP,
62 # so re-enable the tests for Windows XP onwards.
63 my $winxp = ($^O eq 'MSWin32' && defined &Win32::GetOSVersion &&
64                 join('.', (Win32::GetOSVersion())[1..2]) >= 5.1);
65 $have_setlocale = 0 if ((($^O eq 'MSWin32' && !$winxp) || $^O eq 'NetWare') &&
66                 $Config{cc} =~ /^(cl|gcc)/i);
67
68 # UWIN seems to loop after taint tests, just skip for now
69 $have_setlocale = 0 if ($^O =~ /^uwin/);
70
71 $a = 'abc %';
72
73 my $test_num = 0;
74
75 sub ok {
76     my ($result, $message) = @_;
77     $message = "" unless defined $message;
78
79     print 'not ' unless ($result);
80     print "ok " . ++$test_num;
81     print " $message";
82     print "\n";
83 }
84
85 # First we'll do a lot of taint checking for locales.
86 # This is the easiest to test, actually, as any locale,
87 # even the default locale will taint under 'use locale'.
88
89 sub is_tainted { # hello, camel two.
90     no warnings 'uninitialized' ;
91     my $dummy;
92     local $@;
93     not eval { $dummy = join("", @_), kill 0; 1 }
94 }
95
96 sub check_taint ($;$) {
97     my $message_tail = $_[1] // "";
98     $message_tail = ": $message_tail" if $message_tail;
99     ok is_tainted($_[0]), "verify that is tainted$message_tail";
100 }
101
102 sub check_taint_not ($;$) {
103     my $message_tail = $_[1] // "";
104     $message_tail = ": $message_tail" if $message_tail;
105     ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
106 }
107
108 "\tb\t" =~ /^m?(\s)(.*)\1$/;
109 check_taint_not   $&, "not tainted outside 'use locale'";
110 ;
111
112 use locale;     # engage locale and therefore locale taint.
113
114 check_taint_not   $a;
115
116 check_taint       uc($a);
117 check_taint       "\U$a";
118 check_taint       ucfirst($a);
119 check_taint       "\u$a";
120 check_taint       lc($a);
121 check_taint       fc($a);
122 check_taint       "\L$a";
123 check_taint       "\F$a";
124 check_taint       lcfirst($a);
125 check_taint       "\l$a";
126
127 check_taint_not  sprintf('%e', 123.456);
128 check_taint_not  sprintf('%f', 123.456);
129 check_taint_not  sprintf('%g', 123.456);
130 check_taint_not  sprintf('%d', 123.456);
131 check_taint_not  sprintf('%x', 123.456);
132
133 $_ = $a;        # untaint $_
134
135 $_ = uc($a);    # taint $_
136
137 check_taint      $_;
138
139 /(\w)/; # taint $&, $`, $', $+, $1.
140 check_taint      $&;
141 check_taint      $`;
142 check_taint      $';
143 check_taint      $+;
144 check_taint      $1;
145 check_taint_not  $2;
146
147 /(.)/;  # untaint $&, $`, $', $+, $1.
148 check_taint_not  $&;
149 check_taint_not  $`;
150 check_taint_not  $';
151 check_taint_not  $+;
152 check_taint_not  $1;
153 check_taint_not  $2;
154
155 /(\W)/; # taint $&, $`, $', $+, $1.
156 check_taint      $&;
157 check_taint      $`;
158 check_taint      $';
159 check_taint      $+;
160 check_taint      $1;
161 check_taint_not  $2;
162
163 /(\s)/; # taint $&, $`, $', $+, $1.
164 check_taint      $&;
165 check_taint      $`;
166 check_taint      $';
167 check_taint      $+;
168 check_taint      $1;
169 check_taint_not  $2;
170
171 /(\S)/; # taint $&, $`, $', $+, $1.
172 check_taint      $&;
173 check_taint      $`;
174 check_taint      $';
175 check_taint      $+;
176 check_taint      $1;
177 check_taint_not  $2;
178
179 $_ = $a;        # untaint $_
180
181 check_taint_not  $_;
182
183 /(b)/;          # this must not taint
184 check_taint_not  $&;
185 check_taint_not  $`;
186 check_taint_not  $';
187 check_taint_not  $+;
188 check_taint_not  $1;
189 check_taint_not  $2;
190
191 $_ = $a;        # untaint $_
192
193 check_taint_not  $_;
194
195 $b = uc($a);    # taint $b
196 s/(.+)/$b/;     # this must taint only the $_
197
198 check_taint      $_;
199 check_taint_not  $&;
200 check_taint_not  $`;
201 check_taint_not  $';
202 check_taint_not  $+;
203 check_taint_not  $1;
204 check_taint_not  $2;
205
206 $_ = $a;        # untaint $_
207
208 s/(.+)/b/;      # this must not taint
209 check_taint_not  $_;
210 check_taint_not  $&;
211 check_taint_not  $`;
212 check_taint_not  $';
213 check_taint_not  $+;
214 check_taint_not  $1;
215 check_taint_not  $2;
216
217 $b = $a;        # untaint $b
218
219 ($b = $a) =~ s/\w/$&/;
220 check_taint      $b;    # $b should be tainted.
221 check_taint_not  $a;    # $a should be not.
222
223 $_ = $a;        # untaint $_
224
225 s/(\w)/\l$1/;   # this must taint
226 check_taint      $_;
227 check_taint      $&;
228 check_taint      $`;
229 check_taint      $';
230 check_taint      $+;
231 check_taint      $1;
232 check_taint_not  $2;
233
234 $_ = $a;        # untaint $_
235
236 s/(\w)/\L$1/;   # this must taint
237 check_taint      $_;
238 check_taint      $&;
239 check_taint      $`;
240 check_taint      $';
241 check_taint      $+;
242 check_taint      $1;
243 check_taint_not  $2;
244
245 $_ = $a;        # untaint $_
246
247 s/(\w)/\u$1/;   # this must taint
248 check_taint      $_;
249 check_taint      $&;
250 check_taint      $`;
251 check_taint      $';
252 check_taint      $+;
253 check_taint      $1;
254 check_taint_not  $2;
255
256 $_ = $a;        # untaint $_
257
258 s/(\w)/\U$1/;   # this must taint
259 check_taint      $_;
260 check_taint      $&;
261 check_taint      $`;
262 check_taint      $';
263 check_taint      $+;
264 check_taint      $1;
265 check_taint_not  $2;
266
267 # After all this tainting $a should be cool.
268
269 check_taint_not  $a;
270
271 {   # This is just the previous tests copied here with a different
272     # compile-time pragma.
273
274     use locale ':not_characters'; # engage restricted locale with different
275                                   # tainting rules
276
277     check_taint_not   $a;
278
279     check_taint_not     uc($a);
280     check_taint_not     "\U$a";
281     check_taint_not     ucfirst($a);
282     check_taint_not     "\u$a";
283     check_taint_not     lc($a);
284     check_taint_not     fc($a);
285     check_taint_not     "\L$a";
286     check_taint_not     "\F$a";
287     check_taint_not     lcfirst($a);
288     check_taint_not     "\l$a";
289
290     check_taint_not  sprintf('%e', 123.456);
291     check_taint_not  sprintf('%f', 123.456);
292     check_taint_not  sprintf('%g', 123.456);
293     check_taint_not  sprintf('%d', 123.456);
294     check_taint_not  sprintf('%x', 123.456);
295
296     $_ = $a;    # untaint $_
297
298     $_ = uc($a);        # taint $_
299
300     check_taint_not     $_;
301
302     /(\w)/;     # taint $&, $`, $', $+, $1.
303     check_taint_not     $&;
304     check_taint_not     $`;
305     check_taint_not     $';
306     check_taint_not     $+;
307     check_taint_not     $1;
308     check_taint_not  $2;
309
310     /(.)/;      # untaint $&, $`, $', $+, $1.
311     check_taint_not  $&;
312     check_taint_not  $`;
313     check_taint_not  $';
314     check_taint_not  $+;
315     check_taint_not  $1;
316     check_taint_not  $2;
317
318     /(\W)/;     # taint $&, $`, $', $+, $1.
319     check_taint_not     $&;
320     check_taint_not     $`;
321     check_taint_not     $';
322     check_taint_not     $+;
323     check_taint_not     $1;
324     check_taint_not  $2;
325
326     /(\s)/;     # taint $&, $`, $', $+, $1.
327     check_taint_not     $&;
328     check_taint_not     $`;
329     check_taint_not     $';
330     check_taint_not     $+;
331     check_taint_not     $1;
332     check_taint_not  $2;
333
334     /(\S)/;     # taint $&, $`, $', $+, $1.
335     check_taint_not     $&;
336     check_taint_not     $`;
337     check_taint_not     $';
338     check_taint_not     $+;
339     check_taint_not     $1;
340     check_taint_not  $2;
341
342     $_ = $a;    # untaint $_
343
344     check_taint_not  $_;
345
346     /(b)/;              # this must not taint
347     check_taint_not  $&;
348     check_taint_not  $`;
349     check_taint_not  $';
350     check_taint_not  $+;
351     check_taint_not  $1;
352     check_taint_not  $2;
353
354     $_ = $a;    # untaint $_
355
356     check_taint_not  $_;
357
358     $b = uc($a);        # taint $b
359     s/(.+)/$b/; # this must taint only the $_
360
361     check_taint_not     $_;
362     check_taint_not  $&;
363     check_taint_not  $`;
364     check_taint_not  $';
365     check_taint_not  $+;
366     check_taint_not  $1;
367     check_taint_not  $2;
368
369     $_ = $a;    # untaint $_
370
371     s/(.+)/b/;  # this must not taint
372     check_taint_not  $_;
373     check_taint_not  $&;
374     check_taint_not  $`;
375     check_taint_not  $';
376     check_taint_not  $+;
377     check_taint_not  $1;
378     check_taint_not  $2;
379
380     $b = $a;    # untaint $b
381
382     ($b = $a) =~ s/\w/$&/;
383     check_taint_not     $b;     # $b should be tainted.
384     check_taint_not  $a;        # $a should be not.
385
386     $_ = $a;    # untaint $_
387
388     s/(\w)/\l$1/;       # this must taint
389     check_taint_not     $_;
390     check_taint_not     $&;
391     check_taint_not     $`;
392     check_taint_not     $';
393     check_taint_not     $+;
394     check_taint_not     $1;
395     check_taint_not  $2;
396
397     $_ = $a;    # untaint $_
398
399     s/(\w)/\L$1/;       # this must taint
400     check_taint_not     $_;
401     check_taint_not     $&;
402     check_taint_not     $`;
403     check_taint_not     $';
404     check_taint_not     $+;
405     check_taint_not     $1;
406     check_taint_not  $2;
407
408     $_ = $a;    # untaint $_
409
410     s/(\w)/\u$1/;       # this must taint
411     check_taint_not     $_;
412     check_taint_not     $&;
413     check_taint_not     $`;
414     check_taint_not     $';
415     check_taint_not     $+;
416     check_taint_not     $1;
417     check_taint_not  $2;
418
419     $_ = $a;    # untaint $_
420
421     s/(\w)/\U$1/;       # this must taint
422     check_taint_not     $_;
423     check_taint_not     $&;
424     check_taint_not     $`;
425     check_taint_not     $';
426     check_taint_not     $+;
427     check_taint_not     $1;
428     check_taint_not  $2;
429
430     # After all this tainting $a should be cool.
431
432     check_taint_not  $a;
433 }
434
435 # Here are in scope of 'use locale'
436
437 # I think we've seen quite enough of taint.
438 # Let us do some *real* locale work now,
439 # unless setlocale() is missing (i.e. minitest).
440
441 unless ($have_setlocale) {
442     print "1..$test_num\n";
443     exit;
444 }
445
446 # The test number before our first setlocale()
447 my $final_without_setlocale = $test_num;
448
449 # Find locales.
450
451 debug "# Scanning for locales...\n";
452
453 # Note that it's okay that some languages have their native names
454 # capitalized here even though that's not "right".  They are lowercased
455 # anyway later during the scanning process (and besides, some clueless
456 # vendor might have them capitalized erroneously anyway).
457
458 my $locales = <<EOF;
459 Afrikaans:af:za:1 15
460 Arabic:ar:dz eg sa:6 arabic8
461 Brezhoneg Breton:br:fr:1 15
462 Bulgarski Bulgarian:bg:bg:5
463 Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
464 Hrvatski Croatian:hr:hr:2
465 Cymraeg Welsh:cy:cy:1 14 15
466 Czech:cs:cz:2
467 Dansk Danish:da:dk:1 15
468 Nederlands Dutch:nl:be nl:1 15
469 English American British:en:au ca gb ie nz us uk zw:1 15 cp850
470 Esperanto:eo:eo:3
471 Eesti Estonian:et:ee:4 6 13
472 Suomi Finnish:fi:fi:1 15
473 Flamish::fl:1 15
474 Deutsch German:de:at be ch de lu:1 15
475 Euskaraz Basque:eu:es fr:1 15
476 Galego Galician:gl:es:1 15
477 Ellada Greek:el:gr:7 g8
478 Frysk:fy:nl:1 15
479 Greenlandic:kl:gl:4 6
480 Hebrew:iw:il:8 hebrew8
481 Hungarian:hu:hu:2
482 Indonesian:id:id:1 15
483 Gaeilge Irish:ga:IE:1 14 15
484 Italiano Italian:it:ch it:1 15
485 Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
486 Korean:ko:kr:
487 Latine Latin:la:va:1 15
488 Latvian:lv:lv:4 6 13
489 Lithuanian:lt:lt:4 6 13
490 Macedonian:mk:mk:1 15
491 Maltese:mt:mt:3
492 Moldovan:mo:mo:2
493 Norsk Norwegian:no no\@nynorsk nb nn:no:1 15
494 Occitan:oc:es:1 15
495 Polski Polish:pl:pl:2
496 Rumanian:ro:ro:2
497 Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
498 Serbski Serbian:sr:yu:5
499 Slovak:sk:sk:2
500 Slovene Slovenian:sl:si:2
501 Sqhip Albanian:sq:sq:1 15
502 Svenska Swedish:sv:fi se:1 15
503 Thai:th:th:11 tis620
504 Turkish:tr:tr:9 turkish8
505 Yiddish:yi::1 15
506 EOF
507
508 if ($^O eq 'os390') {
509     # These cause heartburn.  Broken locales?
510     $locales =~ s/Svenska Swedish:sv:fi se:1 15\n//;
511     $locales =~ s/Thai:th:th:11 tis620\n//;
512 }
513
514 sub in_utf8 () { $^H & 0x08 || (${^OPEN} || "") =~ /:utf8/ }
515
516 if (in_utf8) {
517     require "lib/locale/utf8";
518 } else {
519     require "lib/locale/latin1";
520 }
521
522 my @Locale;
523 my $Locale;
524 my @Digit_;
525 my @Alnum_;
526
527 sub trylocale {
528     my $locale = shift;
529     return if grep { $locale eq $_ } @Locale;
530     return unless setlocale(&POSIX::LC_ALL, $locale);
531     my $badutf8;
532     {
533         local $SIG{__WARN__} = sub {
534             $badutf8 = $_[0] =~ /Malformed UTF-8/;
535         };
536         $Locale =~ /UTF-?8/i;
537     }
538
539     if ($badutf8) {
540         ok(0, "Locale name contains malformed utf8");
541         return;
542     }
543     push @Locale, $locale;
544 }
545
546 sub decode_encodings {
547     my @enc;
548
549     foreach (split(/ /, shift)) {
550         if (/^(\d+)$/) {
551             push @enc, "ISO8859-$1";
552             push @enc, "iso8859$1";     # HP
553             if ($1 eq '1') {
554                  push @enc, "roman8";   # HP
555             }
556         } else {
557             push @enc, $_;
558             push @enc, "$_.UTF-8";
559         }
560     }
561     if ($^O eq 'os390') {
562         push @enc, qw(IBM-037 IBM-819 IBM-1047);
563     }
564
565     return @enc;
566 }
567
568 trylocale("C");
569 trylocale("POSIX");
570 foreach (0..15) {
571     trylocale("ISO8859-$_");
572     trylocale("iso8859$_");
573     trylocale("iso8859-$_");
574     trylocale("iso_8859_$_");
575     trylocale("isolatin$_");
576     trylocale("isolatin-$_");
577     trylocale("iso_latin_$_");
578 }
579
580 # Sanitize the environment so that we can run the external 'locale'
581 # program without the taint mode getting grumpy.
582
583 # $ENV{PATH} is special in VMS.
584 delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
585
586 # Other subversive stuff.
587 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
588
589 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
590     while (<LOCALES>) {
591         # It seems that /usr/bin/locale steadfastly outputs 8 bit data, which
592         # ain't great when we're running this testPERL_UNICODE= so that utf8
593         # locales will cause all IO hadles to default to (assume) utf8
594         next unless utf8::valid($_);
595         chomp;
596         trylocale($_);
597     }
598     close(LOCALES);
599 } elsif ($^O eq 'VMS' && defined($ENV{'SYS$I18N_LOCALE'}) && -d 'SYS$I18N_LOCALE') {
600 # The SYS$I18N_LOCALE logical name search list was not present on
601 # VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
602     opendir(LOCALES, "SYS\$I18N_LOCALE:");
603     while ($_ = readdir(LOCALES)) {
604         chomp;
605         trylocale($_);
606     }
607     close(LOCALES);
608 } elsif ($^O eq 'openbsd' && -e '/usr/share/locale') {
609
610    # OpenBSD doesn't have a locale executable, so reading /usr/share/locale
611    # is much easier and faster than the last resort method.
612
613     opendir(LOCALES, '/usr/share/locale');
614     while ($_ = readdir(LOCALES)) {
615         chomp;
616         trylocale($_);
617     }
618     close(LOCALES);
619 } else {
620
621     # This is going to be slow.
622
623     foreach my $locale (split(/\n/, $locales)) {
624         my ($locale_name, $language_codes, $country_codes, $encodings) =
625             split(/:/, $locale);
626         my @enc = decode_encodings($encodings);
627         foreach my $loc (split(/ /, $locale_name)) {
628             trylocale($loc);
629             foreach my $enc (@enc) {
630                 trylocale("$loc.$enc");
631             }
632             $loc = lc $loc;
633             foreach my $enc (@enc) {
634                 trylocale("$loc.$enc");
635             }
636         }
637         foreach my $lang (split(/ /, $language_codes)) {
638             trylocale($lang);
639             foreach my $country (split(/ /, $country_codes)) {
640                 my $lc = "${lang}_${country}";
641                 trylocale($lc);
642                 foreach my $enc (@enc) {
643                     trylocale("$lc.$enc");
644                 }
645                 my $lC = "${lang}_\U${country}";
646                 trylocale($lC);
647                 foreach my $enc (@enc) {
648                     trylocale("$lC.$enc");
649                 }
650             }
651         }
652     }
653 }
654
655 setlocale(&POSIX::LC_ALL, "C");
656
657 if ($^O eq 'darwin') {
658     # Darwin 8/Mac OS X 10.4 and 10.5 have bad Basque locales: perl bug #35895,
659     # Apple bug ID# 4139653. It also has a problem in Byelorussian.
660     (my $v) = $Config{osvers} =~ /^(\d+)/;
661     if ($v >= 8 and $v < 10) {
662         debug "# Skipping eu_ES, be_BY locales -- buggy in Darwin\n";
663         @Locale = grep ! m/^(eu_ES(?:\..*)?|be_BY\.CP1131)$/, @Locale;
664     } elsif ($v < 12) {
665         debug "# Skipping be_BY locales -- buggy in Darwin\n";
666         @Locale = grep ! m/^be_BY\.CP1131$/, @Locale;
667     }
668 }
669
670 @Locale = sort @Locale;
671
672 debug "# Locales =\n";
673 for ( @Locale ) {
674     debug "# $_\n";
675 }
676
677 my %Problem;
678 my %Okay;
679 my %Testing;
680 my @Added_alpha;   # Alphas that aren't in the C locale.
681 my %test_names;
682
683 sub display_characters {
684     # This returns a display string denoting the input parameter @_, each
685     # entry of which is a single character in the range 0-255.  The first part
686     # of the output is a string of the characters in @_ that are ASCII
687     # graphics, and hence unambiguously displayable.  They are given by code
688     # point order.  The second part is the remaining code points, the ordinals
689     # of which are each displayed as 2-digit hex.  Blanks are inserted so as
690     # to keep anything from the first part looking like a 2-digit hex number.
691
692     no locale;
693     my @chars = sort { ord $a <=> ord $b } @_;
694     my $output = "";
695     my $hex = "";
696     my $range_start;
697     my $start_class;
698     push @chars, chr(258);  # This sentinel simplifies the loop termination
699                             # logic
700     foreach my $i (0 .. @chars - 1) {
701         my $char = $chars[$i];
702         my $range_end;
703         my $class;
704
705         # We avoid using [:posix:] classes, as these are being tested in this
706         # file.  Each equivalence class below is for things that can appear in
707         # a range; those that can't be in a range have class -1.  0 for those
708         # which should be output in hex; and >0 for the other ranges
709         if ($char =~ /[A-Z]/) {
710             $class = 2;
711         }
712         elsif ($char =~ /[a-z]/) {
713             $class = 3;
714         }
715         elsif ($char =~ /[0-9]/) {
716             $class = 4;
717         }
718         elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
719             $class = -1;    # Punct never appears in a range
720         }
721         else {
722             $class = 0;     # Output in hex
723         }
724
725         if (! defined $range_start) {
726             if ($class < 0) {
727                 $output .= $char;
728             }
729             else {
730                 $range_start = ord $char;
731                 $start_class = $class;
732             }
733         } # A range ends if not consecutive, or the class-type changes
734         elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
735               || $class != $start_class)
736         {
737
738             # Here, the current character is not in the range.  This means the
739             # previous character must have been.  Output the range up through
740             # that one.
741             my $range_length = $range_end - $range_start + 1;
742             if ($start_class > 0) {
743                 $output .= " " . chr($range_start);
744                 $output .= "-" . chr($range_end) if $range_length > 1;
745             }
746             else {
747                 $hex .= sprintf(" %02X", $range_start);
748                 $hex .= sprintf("-%02X", $range_end) if $range_length > 1;
749             }
750
751             # Handle the new current character, as potentially beginning a new
752             # range
753             undef $range_start;
754             redo;
755         }
756     }
757
758     $output =~ s/^ //;
759     $hex =~ s/^ // if ! length $output;
760     return "$output$hex";
761 }
762
763 sub report_result {
764     my ($Locale, $i, $pass_fail, $message) = @_;
765     $message //= "";
766     $message = "  ($message)" if $message;
767     unless ($pass_fail) {
768         $Problem{$i}{$Locale} = 1;
769         debug "# failed $i ($test_names{$i}) with locale '$Locale'$message\n";
770     } else {
771         push @{$Okay{$i}}, $Locale;
772     }
773 }
774
775 sub report_multi_result {
776     my ($Locale, $i, $results_ref) = @_;
777
778     # $results_ref points to an array, each element of which is a character that was
779     # in error for this test numbered '$i'.  If empty, the test passed
780
781     my $message = "";
782     if (@$results_ref) {
783         $message = join " ", "for", display_characters(@$results_ref);
784     }
785     report_result($Locale, $i, @$results_ref == 0, $message);
786 }
787
788 my $first_locales_test_number = $final_without_setlocale + 1;
789 my $locales_test_number;
790 my $not_necessarily_a_problem_test_number;
791 my $first_casing_test_number;
792 my $final_casing_test_number;
793 my %setlocale_failed;   # List of locales that setlocale() didn't work on
794
795 foreach $Locale (@Locale) {
796     $locales_test_number = $first_locales_test_number - 1;
797     debug "# Locale = $Locale\n";
798
799     unless (setlocale(&POSIX::LC_ALL, $Locale)) {
800         $setlocale_failed{$Locale} = $Locale;
801         next;
802     }
803
804     # We test UTF-8 locales only under ':not_characters'; otherwise they have
805     # documented deficiencies.  Non- UTF-8 locales are tested only under plain
806     # 'use locale', as otherwise we would have to convert everything in them
807     # to Unicode.
808     my $is_utf8_locale = $Locale =~ /UTF-?8/i;
809
810     my %UPPER = ();     # All alpha X for which uc(X) == X and lc(X) != X
811     my %lower = ();     # All alpha X for which lc(X) == X and uc(X) != X
812     my %BoThCaSe = ();  # All alpha X for which uc(X) == lc(X) == X
813
814     if (! $is_utf8_locale) {
815         use locale;
816         @Alnum_ = sort grep /\w/, map { chr } 0..255;
817         debug "# w = ", join("",@Alnum_), "\n";
818         @Digit_ = grep /\d/, map { chr } 0..255;
819
820         # Sieve the uppercase and the lowercase.
821
822         for (@Alnum_) {
823             if (/[^\d_]/) { # skip digits and the _
824                 if (uc($_) eq $_) {
825                     $UPPER{$_} = $_;
826                 }
827                 if (lc($_) eq $_) {
828                     $lower{$_} = $_;
829                 }
830             }
831         }
832     }
833     else {
834         use locale ':not_characters';
835         @Alnum_ = sort grep /\w/, map { chr } 0..255;
836         @Digit_ = grep /\d/, map { chr } 0..255;
837         debug "# w = ", join("",@Alnum_), "\n";
838         for (@Alnum_) {
839             if (/[^\d_]/) { # skip digits and the _
840                 if (uc($_) eq $_) {
841                     $UPPER{$_} = $_;
842                 }
843                 if (lc($_) eq $_) {
844                     $lower{$_} = $_;
845                 }
846             }
847         }
848     }
849     foreach (keys %UPPER) {
850         $BoThCaSe{$_}++ if exists $lower{$_};
851     }
852     foreach (keys %lower) {
853         $BoThCaSe{$_}++ if exists $UPPER{$_};
854     }
855     foreach (keys %BoThCaSe) {
856         delete $UPPER{$_};
857         delete $lower{$_};
858     }
859
860     debug "# UPPER    = ", display_characters(keys %UPPER), "\n";
861     debug "# lower    = ", display_characters(keys %lower), "\n";
862     debug "# BoThCaSe = ", display_characters(keys %BoThCaSe), "\n";
863
864     my @failures;
865     my @fold_failures;
866     foreach my $x (sort keys %UPPER) {
867         my $ok;
868         my $fold_ok;
869         if ($is_utf8_locale) {
870             use locale ':not_characters';
871             $ok = $x =~ /[[:upper:]]/;
872             $fold_ok = $x =~ /[[:lower:]]/i;
873         }
874         else {
875             use locale;
876             $ok = $x =~ /[[:upper:]]/;
877             $fold_ok = $x =~ /[[:lower:]]/i;
878         }
879         push @failures, $x unless $ok;
880         push @fold_failures, $x unless $fold_ok;
881     }
882     $locales_test_number++;
883     $first_casing_test_number = $locales_test_number;
884     $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches all alpha X for which uc(X) == X and lc(X) != X';
885     report_multi_result($Locale, $locales_test_number, \@failures);
886
887     $locales_test_number++;
888
889     $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i matches all alpha X for which uc(X) == X and lc(X) != X';
890     report_multi_result($Locale, $locales_test_number, \@fold_failures);
891
892     undef @failures;
893     undef @fold_failures;
894
895     foreach my $x (sort keys %lower) {
896         my $ok;
897         my $fold_ok;
898         if ($is_utf8_locale) {
899             use locale ':not_characters';
900             $ok = $x =~ /[[:lower:]]/;
901             $fold_ok = $x =~ /[[:upper:]]/i;
902         }
903         else {
904             use locale;
905             $ok = $x =~ /[[:lower:]]/;
906             $fold_ok = $x =~ /[[:upper:]]/i;
907         }
908         push @failures, $x unless $ok;
909         push @fold_failures, $x unless $fold_ok;
910     }
911
912     $locales_test_number++;
913     $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/ matches all alpha X for which lc(X) == X and uc(X) != X';
914     report_multi_result($Locale, $locales_test_number, \@failures);
915
916     $locales_test_number++;
917     $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/i matches all alpha X for which lc(X) == X and uc(X) != X';
918     report_multi_result($Locale, $locales_test_number, \@fold_failures);
919
920     {   # Find the alphabetic characters that are not considered alphabetics
921         # in the default (C) locale.
922
923         no locale;
924
925         @Added_alpha = ();
926         for (keys %UPPER, keys %lower, keys %BoThCaSe) {
927             push(@Added_alpha, $_) if (/\W/);
928         }
929     }
930
931     @Added_alpha = sort @Added_alpha;
932
933     debug "# Added_alpha = ", display_characters(@Added_alpha), "\n";
934
935     # Cross-check the whole 8-bit character set.
936
937     ++$locales_test_number;
938     my @f;
939     $test_names{$locales_test_number} = 'Verify that \w and [:word:] are identical';
940     for (map { chr } 0..255) {
941         if ($is_utf8_locale) {
942             use locale ':not_characters';
943             push @f, $_ unless /[[:word:]]/ == /\w/;
944         }
945         else {
946             push @f, $_ unless /[[:word:]]/ == /\w/;
947         }
948     }
949     report_multi_result($Locale, $locales_test_number, \@f);
950
951     ++$locales_test_number;
952     undef @f;
953     $test_names{$locales_test_number} = 'Verify that \d and [:digit:] are identical';
954     for (map { chr } 0..255) {
955         if ($is_utf8_locale) {
956             use locale ':not_characters';
957             push @f, $_ unless /[[:digit:]]/ == /\d/;
958         }
959         else {
960             push @f, $_ unless /[[:digit:]]/ == /\d/;
961         }
962     }
963     report_multi_result($Locale, $locales_test_number, \@f);
964
965     ++$locales_test_number;
966     undef @f;
967     $test_names{$locales_test_number} = 'Verify that \s and [:space:] are identical';
968     for (map { chr } 0..255) {
969         if ($is_utf8_locale) {
970             use locale ':not_characters';
971             push @f, $_ unless /[[:space:]]/ == /\s/;
972         }
973         else {
974             push @f, $_ unless /[[:space:]]/ == /\s/;
975         }
976     }
977     report_multi_result($Locale, $locales_test_number, \@f);
978
979     ++$locales_test_number;
980     undef @f;
981     $test_names{$locales_test_number} = 'Verify that [:posix:] and [:^posix:] are mutually exclusive';
982     for (map { chr } 0..255) {
983         if ($is_utf8_locale) {
984             use locale ':not_characters';
985             push @f, $_ unless   (/[[:alpha:]]/ xor /[[:^alpha:]]/)   ||
986                     (/[[:alnum:]]/ xor /[[:^alnum:]]/)   ||
987                     (/[[:ascii:]]/ xor /[[:^ascii:]]/)   ||
988                     (/[[:blank:]]/ xor /[[:^blank:]]/)   ||
989                     (/[[:cntrl:]]/ xor /[[:^cntrl:]]/)   ||
990                     (/[[:digit:]]/ xor /[[:^digit:]]/)   ||
991                     (/[[:graph:]]/ xor /[[:^graph:]]/)   ||
992                     (/[[:lower:]]/ xor /[[:^lower:]]/)   ||
993                     (/[[:print:]]/ xor /[[:^print:]]/)   ||
994                     (/[[:space:]]/ xor /[[:^space:]]/)   ||
995                     (/[[:upper:]]/ xor /[[:^upper:]]/)   ||
996                     (/[[:word:]]/  xor /[[:^word:]]/)    ||
997                     (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
998
999                     # effectively is what [:cased:] would be if it existed.
1000                     (/[[:upper:]]/i xor /[[:^upper:]]/i);
1001         }
1002         else {
1003             push @f, $_ unless   (/[[:alpha:]]/ xor /[[:^alpha:]]/)   ||
1004                     (/[[:alnum:]]/ xor /[[:^alnum:]]/)   ||
1005                     (/[[:ascii:]]/ xor /[[:^ascii:]]/)   ||
1006                     (/[[:blank:]]/ xor /[[:^blank:]]/)   ||
1007                     (/[[:cntrl:]]/ xor /[[:^cntrl:]]/)   ||
1008                     (/[[:digit:]]/ xor /[[:^digit:]]/)   ||
1009                     (/[[:graph:]]/ xor /[[:^graph:]]/)   ||
1010                     (/[[:lower:]]/ xor /[[:^lower:]]/)   ||
1011                     (/[[:print:]]/ xor /[[:^print:]]/)   ||
1012                     (/[[:space:]]/ xor /[[:^space:]]/)   ||
1013                     (/[[:upper:]]/ xor /[[:^upper:]]/)   ||
1014                     (/[[:word:]]/  xor /[[:^word:]]/)    ||
1015                     (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1016                     (/[[:upper:]]/i xor /[[:^upper:]]/i);
1017         }
1018     }
1019     report_multi_result($Locale, $locales_test_number, \@f);
1020
1021     # The rules for the relationships are given in:
1022     # http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
1023
1024     ++$locales_test_number;
1025     undef @f;
1026     $test_names{$locales_test_number} = 'Verify that [:lower:] is a subset of [:alpha:]';
1027     for (map { chr } 0..255) {
1028         if ($is_utf8_locale) {
1029             use locale ':not_characters';
1030             push @f, $_  if /[[:lower:]]/ and ! /[[:alpha:]]/;
1031         }
1032         else {
1033             push @f, $_  if /[[:lower:]]/ and ! /[[:alpha:]]/;
1034         }
1035     }
1036     report_multi_result($Locale, $locales_test_number, \@f);
1037
1038     ++$locales_test_number;
1039     undef @f;
1040     $test_names{$locales_test_number} = 'Verify that [:upper:] is a subset of [:alpha:]';
1041     for (map { chr } 0..255) {
1042         if ($is_utf8_locale) {
1043             use locale ':not_characters';
1044             push @f, $_  if /[[:upper:]]/ and ! /[[:alpha:]]/;
1045         }
1046         else {
1047             push @f, $_ if /[[:upper:]]/  and ! /[[:alpha:]]/;
1048         }
1049     }
1050     report_multi_result($Locale, $locales_test_number, \@f);
1051
1052     ++$locales_test_number;
1053     undef @f;
1054     $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i is a subset of [:alpha:]';
1055     for (map { chr } 0..255) {
1056         if ($is_utf8_locale) {
1057             use locale ':not_characters';
1058             push @f, $_ if /[[:lower:]]/i  and ! /[[:alpha:]]/;
1059         }
1060         else {
1061             push @f, $_ if /[[:lower:]]/i  and ! /[[:alpha:]]/;
1062         }
1063     }
1064     report_multi_result($Locale, $locales_test_number, \@f);
1065
1066     ++$locales_test_number;
1067     undef @f;
1068     $test_names{$locales_test_number} = 'Verify that [:alpha:] is a subset of [:alnum:]';
1069     for (map { chr } 0..255) {
1070         if ($is_utf8_locale) {
1071             use locale ':not_characters';
1072             push @f, $_ if /[[:alpha:]]/  and ! /[[:alnum:]]/;
1073         }
1074         else {
1075             push @f, $_ if /[[:alpha:]]/  and ! /[[:alnum:]]/;
1076         }
1077     }
1078     report_multi_result($Locale, $locales_test_number, \@f);
1079
1080     ++$locales_test_number;
1081     undef @f;
1082     $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:alnum:]';
1083     for (map { chr } 0..255) {
1084         if ($is_utf8_locale) {
1085             use locale ':not_characters';
1086             push @f, $_ if /[[:digit:]]/  and ! /[[:alnum:]]/;
1087         }
1088         else {
1089             push @f, $_ if /[[:digit:]]/  and ! /[[:alnum:]]/;
1090         }
1091     }
1092     report_multi_result($Locale, $locales_test_number, \@f);
1093
1094     ++$locales_test_number;
1095     undef @f;
1096     $test_names{$locales_test_number} = 'Verify that [:digit:] matches either 10 or 20 code points';
1097     report_result($Locale, $locales_test_number, @Digit_ == 10 || @Digit_ ==20);
1098
1099     ++$locales_test_number;
1100     undef @f;
1101     $test_names{$locales_test_number} = 'Verify that [:digit:] (if is 10 code points) is a subset of [:xdigit:]';
1102     if (@Digit_ == 10) {
1103         for (map { chr } 0..255) {
1104             if ($is_utf8_locale) {
1105                 use locale ':not_characters';
1106                 push @f, $_ if /[[:digit:]]/  and ! /[[:xdigit:]]/;
1107             }
1108             else {
1109                 push @f, $_ if /[[:digit:]]/  and ! /[[:xdigit:]]/;
1110             }
1111         }
1112     }
1113     report_multi_result($Locale, $locales_test_number, \@f);
1114
1115     ++$locales_test_number;
1116     undef @f;
1117     $test_names{$locales_test_number} = 'Verify that [:alnum:] is a subset of [:graph:]';
1118     for (map { chr } 0..255) {
1119         if ($is_utf8_locale) {
1120             use locale ':not_characters';
1121             push @f, $_ if /[[:alnum:]]/  and ! /[[:graph:]]/;
1122         }
1123         else {
1124             push @f, $_ if /[[:alnum:]]/  and ! /[[:graph:]]/;
1125         }
1126     }
1127     report_multi_result($Locale, $locales_test_number, \@f);
1128
1129     # Note that xdigit doesn't have to be a subset of alnum
1130
1131     ++$locales_test_number;
1132     undef @f;
1133     $test_names{$locales_test_number} = 'Verify that [:xdigit:] is a subset of [:graph:]';
1134     for (map { chr } 0..255) {
1135         if ($is_utf8_locale) {
1136             use locale ':not_characters';
1137             push @f, $_ if /[[:xdigit:]]/  and ! /[[:graph:]]/;
1138         }
1139         else {
1140             push @f, $_ if /[[:xdigit:]]/  and ! /[[:graph:]]/;
1141         }
1142     }
1143     report_multi_result($Locale, $locales_test_number, \@f);
1144
1145     ++$locales_test_number;
1146     undef @f;
1147     $test_names{$locales_test_number} = 'Verify that [:punct:] is a subset of [:graph:]';
1148     for (map { chr } 0..255) {
1149         if ($is_utf8_locale) {
1150             use locale ':not_characters';
1151             push @f, $_ if /[[:punct:]]/  and ! /[[:graph:]]/;
1152         }
1153         else {
1154             push @f, $_ if /[[:punct:]]/  and ! /[[:graph:]]/;
1155         }
1156     }
1157     report_multi_result($Locale, $locales_test_number, \@f);
1158
1159     ++$locales_test_number;
1160     undef @f;
1161     $test_names{$locales_test_number} = 'Verify that [:blank:] is a subset of [:space:]';
1162     for (map { chr } 0..255) {
1163         if ($is_utf8_locale) {
1164             use locale ':not_characters';
1165             push @f, $_ if /[[:blank:]]/  and ! /[[:space:]]/;
1166         }
1167         else {
1168             push @f, $_ if /[[:blank:]]/  and ! /[[:space:]]/;
1169         }
1170     }
1171     report_multi_result($Locale, $locales_test_number, \@f);
1172
1173     ++$locales_test_number;
1174     undef @f;
1175     $test_names{$locales_test_number} = 'Verify that [:graph:] is a subset of [:print:]';
1176     for (map { chr } 0..255) {
1177         if ($is_utf8_locale) {
1178             use locale ':not_characters';
1179             push @f, $_ if /[[:graph:]]/  and ! /[[:print:]]/;
1180         }
1181         else {
1182             push @f, $_ if /[[:graph:]]/  and ! /[[:print:]]/;
1183         }
1184     }
1185     report_multi_result($Locale, $locales_test_number, \@f);
1186
1187     ++$locales_test_number;
1188     undef @f;
1189     $test_names{$locales_test_number} = 'Verify that isn\'t both [:cntrl:] and [:print:]';
1190     for (map { chr } 0..255) {
1191         if ($is_utf8_locale) {
1192             use locale ':not_characters';
1193             push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1194         }
1195         else {
1196             push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1197         }
1198     }
1199     report_multi_result($Locale, $locales_test_number, \@f);
1200
1201     ++$locales_test_number;
1202     undef @f;
1203     $test_names{$locales_test_number} = 'Verify that isn\'t both [:alnum:] and [:punct:]';
1204     for (map { chr } 0..255) {
1205         if ($is_utf8_locale) {
1206             use locale ':not_characters';
1207             push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1208         }
1209         else {
1210             push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1211         }
1212     }
1213     report_multi_result($Locale, $locales_test_number, \@f);
1214
1215     ++$locales_test_number;
1216     undef @f;
1217     $test_names{$locales_test_number} = 'Verify that isn\'t both [:xdigit:] and [:punct:]';
1218     for (map { chr } 0..255) {
1219         if ($is_utf8_locale) {
1220             use locale ':not_characters';
1221             push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1222         }
1223         else {
1224             push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1225         }
1226     }
1227     report_multi_result($Locale, $locales_test_number, \@f);
1228
1229     ++$locales_test_number;
1230     undef @f;
1231     $test_names{$locales_test_number} = 'Verify that isn\'t both [:graph:] and [:space:]';
1232     for (map { chr } 0..255) {
1233         if ($is_utf8_locale) {
1234             use locale ':not_characters';
1235             push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1236         }
1237         else {
1238             push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1239         }
1240     }
1241     report_multi_result($Locale, $locales_test_number, \@f);
1242
1243     $final_casing_test_number = $locales_test_number;
1244
1245     # Test for read-only scalars' locale vs non-locale comparisons.
1246
1247     {
1248         no locale;
1249         my $ok;
1250         $a = "qwerty";
1251         if ($is_utf8_locale) {
1252             use locale ':not_characters';
1253             $ok = ($a cmp "qwerty") == 0;
1254         }
1255         else {
1256             use locale;
1257             $ok = ($a cmp "qwerty") == 0;
1258         }
1259         report_result($Locale, ++$locales_test_number, $ok);
1260         $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
1261     }
1262
1263     {
1264         my ($from, $to, $lesser, $greater,
1265             @test, %test, $test, $yes, $no, $sign);
1266
1267         ++$locales_test_number;
1268         $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
1269         $not_necessarily_a_problem_test_number = $locales_test_number;
1270         for (0..9) {
1271             # Select a slice.
1272             $from = int(($_*@Alnum_)/10);
1273             $to = $from + int(@Alnum_/10);
1274             $to = $#Alnum_ if ($to > $#Alnum_);
1275             $lesser  = join('', @Alnum_[$from..$to]);
1276             # Select a slice one character on.
1277             $from++; $to++;
1278             $to = $#Alnum_ if ($to > $#Alnum_);
1279             $greater = join('', @Alnum_[$from..$to]);
1280             if ($is_utf8_locale) {
1281                 use locale ':not_characters';
1282                 ($yes, $no, $sign) = ($lesser lt $greater
1283                                     ? ("    ", "not ", 1)
1284                                     : ("not ", "    ", -1));
1285             }
1286             else {
1287                 use locale;
1288                 ($yes, $no, $sign) = ($lesser lt $greater
1289                                     ? ("    ", "not ", 1)
1290                                     : ("not ", "    ", -1));
1291             }
1292             # all these tests should FAIL (return 0).  Exact lt or gt cannot
1293             # be tested because in some locales, say, eacute and E may test
1294             # equal.
1295             @test =
1296                 (
1297                     $no.'    ($lesser  le $greater)',  # 1
1298                     'not      ($lesser  ne $greater)', # 2
1299                     '         ($lesser  eq $greater)', # 3
1300                     $yes.'    ($lesser  ge $greater)', # 4
1301                     $yes.'    ($lesser  ge $greater)', # 5
1302                     $yes.'    ($greater le $lesser )', # 7
1303                     'not      ($greater ne $lesser )', # 8
1304                     '         ($greater eq $lesser )', # 9
1305                     $no.'     ($greater ge $lesser )', # 10
1306                     'not (($lesser cmp $greater) == -($sign))' # 11
1307                     );
1308             @test{@test} = 0 x @test;
1309             $test = 0;
1310             for my $ti (@test) {
1311                 if ($is_utf8_locale) {
1312                     use locale ':not_characters';
1313                     $test{$ti} = eval $ti;
1314                 }
1315                 else {
1316                     # Already in 'use locale';
1317                     $test{$ti} = eval $ti;
1318                 }
1319                 $test ||= $test{$ti}
1320             }
1321             report_result($Locale, $locales_test_number, $test == 0);
1322             if ($test) {
1323                 debug "# lesser  = '$lesser'\n";
1324                 debug "# greater = '$greater'\n";
1325                 debug "# lesser cmp greater = ",
1326                         $lesser cmp $greater, "\n";
1327                 debug "# greater cmp lesser = ",
1328                         $greater cmp $lesser, "\n";
1329                 debug "# (greater) from = $from, to = $to\n";
1330                 for my $ti (@test) {
1331                     debugf("# %-40s %-4s", $ti,
1332                             $test{$ti} ? 'FAIL' : 'ok');
1333                     if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
1334                         debugf("(%s == %4d)", $1, eval $1);
1335                     }
1336                     debug "\n#";
1337                 }
1338
1339                 last;
1340             }
1341         }
1342     }
1343
1344     my $ok1;
1345     my $ok2;
1346     my $ok3;
1347     my $ok4;
1348     my $ok5;
1349     my $ok6;
1350     my $ok7;
1351     my $ok8;
1352     my $ok9;
1353     my $ok10;
1354     my $ok11;
1355     my $ok12;
1356     my $ok13;
1357     my $ok14;
1358     my $ok15;
1359     my $ok16;
1360
1361     my $c;
1362     my $d;
1363     my $e;
1364     my $f;
1365     my $g;
1366
1367     if (! $is_utf8_locale) {
1368         use locale;
1369
1370         my ($x, $y) = (1.23, 1.23);
1371
1372         $a = "$x";
1373         printf ''; # printf used to reset locale to "C"
1374         $b = "$y";
1375         $ok1 = $a eq $b;
1376
1377         $c = "$x";
1378         my $z = sprintf ''; # sprintf used to reset locale to "C"
1379         $d = "$y";
1380         $ok2 = $c eq $d;
1381         {
1382
1383             use warnings;
1384             my $w = 0;
1385             local $SIG{__WARN__} =
1386                 sub {
1387                     print "# @_\n";
1388                     $w++;
1389                 };
1390
1391             # The == (among other ops) used to warn for locales
1392             # that had something else than "." as the radix character.
1393
1394             $ok3 = $c == 1.23;
1395             $ok4 = $c == $x;
1396             $ok5 = $c == $d;
1397             {
1398                 no locale;
1399
1400                 $e = "$x";
1401
1402                 $ok6 = $e == 1.23;
1403                 $ok7 = $e == $x;
1404                 $ok8 = $e == $c;
1405             }
1406
1407             $f = "1.23";
1408             $g = 2.34;
1409
1410             $ok9 = $f == 1.23;
1411             $ok10 = $f == $x;
1412             $ok11 = $f == $c;
1413             $ok12 = abs(($f + $g) - 3.57) < 0.01;
1414             $ok13 = $w == 0;
1415             $ok14 = $ok15 = $ok16 = 1;  # Skip for non-utf8 locales
1416         }
1417     }
1418     else {
1419         use locale ':not_characters';
1420
1421         my ($x, $y) = (1.23, 1.23);
1422         $a = "$x";
1423         printf ''; # printf used to reset locale to "C"
1424         $b = "$y";
1425         $ok1 = $a eq $b;
1426
1427         $c = "$x";
1428         my $z = sprintf ''; # sprintf used to reset locale to "C"
1429         $d = "$y";
1430         $ok2 = $c eq $d;
1431         {
1432             use warnings;
1433             my $w = 0;
1434             local $SIG{__WARN__} =
1435                 sub {
1436                     print "# @_\n";
1437                     $w++;
1438                 };
1439             $ok3 = $c == 1.23;
1440             $ok4 = $c == $x;
1441             $ok5 = $c == $d;
1442             {
1443                 no locale;
1444                 $e = "$x";
1445
1446                 $ok6 = $e == 1.23;
1447                 $ok7 = $e == $x;
1448                 $ok8 = $e == $c;
1449             }
1450
1451             $f = "1.23";
1452             $g = 2.34;
1453
1454             $ok9 = $f == 1.23;
1455             $ok10 = $f == $x;
1456             $ok11 = $f == $c;
1457             $ok12 = abs(($f + $g) - 3.57) < 0.01;
1458             $ok13 = $w == 0;
1459
1460             # Look for non-ASCII error messages, and verify that the first
1461             # such is in UTF-8 (the others almost certainly will be like the
1462             # first).
1463             $ok14 = 1;
1464             foreach my $err (keys %!) {
1465                 use Errno;
1466                 $! = eval "&Errno::$err";   # Convert to strerror() output
1467                 my $strerror = "$!";
1468                 if ("$strerror" =~ /\P{ASCII}/) {
1469                     my $utf8_strerror = $strerror;
1470                     utf8::upgrade($utf8_strerror);
1471
1472                     # If $! was already in UTF-8, the upgrade was a no-op;
1473                     # otherwise they will be different byte strings.
1474                     use bytes;
1475                     $ok14 = $utf8_strerror eq $strerror;
1476                     last;
1477                 }
1478             }
1479
1480             # Similarly, we verify that a non-ASCII radix is in UTF-8.  This
1481             # also catches if there is a disparity between sprintf and
1482             # stringification.
1483
1484             my $string_g = "$g";
1485
1486             my $utf8_string_g = "$g";
1487             utf8::upgrade($utf8_string_g);
1488
1489             my $utf8_sprintf_g = sprintf("%g", $g);
1490             utf8::upgrade($utf8_sprintf_g);
1491             use bytes;
1492             $ok15 = $utf8_string_g eq $string_g;
1493             $ok16 = $utf8_sprintf_g eq $string_g;
1494         }
1495     }
1496
1497     report_result($Locale, ++$locales_test_number, $ok1);
1498     $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
1499     my $first_a_test = $locales_test_number;
1500
1501     debug "# $first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
1502
1503     report_result($Locale, ++$locales_test_number, $ok2);
1504     $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
1505
1506     my $first_c_test = $locales_test_number;
1507
1508     report_result($Locale, ++$locales_test_number, $ok3);
1509     $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
1510
1511     report_result($Locale, ++$locales_test_number, $ok4);
1512     $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
1513
1514     report_result($Locale, ++$locales_test_number, $ok5);
1515     $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
1516
1517     debug "# $first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
1518
1519     report_result($Locale, ++$locales_test_number, $ok6);
1520     $test_names{$locales_test_number} = 'Verify that can assign stringified under inner no-locale block';
1521     my $first_e_test = $locales_test_number;
1522
1523     report_result($Locale, ++$locales_test_number, $ok7);
1524     $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
1525
1526     report_result($Locale, ++$locales_test_number, $ok8);
1527     $test_names{$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
1528
1529     debug "# $first_e_test..$locales_test_number: \$e = $e, no locale\n";
1530
1531     report_result($Locale, ++$locales_test_number, $ok9);
1532     $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
1533     my $first_f_test = $locales_test_number;
1534
1535     report_result($Locale, ++$locales_test_number, $ok10);
1536     $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
1537
1538     report_result($Locale, ++$locales_test_number, $ok11);
1539     $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';
1540
1541     report_result($Locale, ++$locales_test_number, $ok12);
1542     $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';
1543
1544     report_result($Locale, ++$locales_test_number, $ok13);
1545     $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
1546
1547     report_result($Locale, ++$locales_test_number, $ok14);
1548     $test_names{$locales_test_number} = 'Verify that non-ASCII UTF-8 error messages are in UTF-8';
1549
1550     report_result($Locale, ++$locales_test_number, $ok15);
1551     $test_names{$locales_test_number} = 'Verify that a number with a UTF-8 radix has a UTF-8 stringification';
1552
1553     report_result($Locale, ++$locales_test_number, $ok16);
1554     $test_names{$locales_test_number} = 'Verify that a sprintf of a number with a UTF-8 radix yields UTF-8';
1555
1556     debug "# $first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
1557
1558     # Does taking lc separately differ from taking
1559     # the lc "in-line"?  (This was the bug 19990704.002, change #3568.)
1560     # The bug was in the caching of the 'o'-magic.
1561     if (! $is_utf8_locale) {
1562         use locale;
1563
1564         sub lcA {
1565             my $lc0 = lc $_[0];
1566             my $lc1 = lc $_[1];
1567             return $lc0 cmp $lc1;
1568         }
1569
1570         sub lcB {
1571             return lc($_[0]) cmp lc($_[1]);
1572         }
1573
1574         my $x = "ab";
1575         my $y = "aa";
1576         my $z = "AB";
1577
1578         report_result($Locale, ++$locales_test_number,
1579                     lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
1580                     lcA($x, $z) == 0 && lcB($x, $z) == 0);
1581     }
1582     else {
1583         use locale ':not_characters';
1584
1585         sub lcC {
1586             my $lc0 = lc $_[0];
1587             my $lc1 = lc $_[1];
1588             return $lc0 cmp $lc1;
1589         }
1590
1591         sub lcD {
1592             return lc($_[0]) cmp lc($_[1]);
1593         }
1594
1595         my $x = "ab";
1596         my $y = "aa";
1597         my $z = "AB";
1598
1599         report_result($Locale, ++$locales_test_number,
1600                     lcC($x, $y) == 1 && lcD($x, $y) == 1 ||
1601                     lcC($x, $z) == 0 && lcD($x, $z) == 0);
1602     }
1603     $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
1604
1605     # Does lc of an UPPER (if different from the UPPER) match
1606     # case-insensitively the UPPER, and does the UPPER match
1607     # case-insensitively the lc of the UPPER.  And vice versa.
1608     {
1609         use locale;
1610         no utf8;
1611         my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
1612
1613         my @f = ();
1614         ++$locales_test_number;
1615         $test_names{$locales_test_number} = 'Verify case insensitive matching works';
1616         foreach my $x (sort keys %UPPER) {
1617             if (! $is_utf8_locale) {
1618                 my $y = lc $x;
1619                 next unless uc $y eq $x;
1620                 print "# UPPER $x lc $y ",
1621                         $x =~ /$y/i ? 1 : 0, " ",
1622                         $y =~ /$x/i ? 1 : 0, "\n" if 0;
1623                 #
1624                 # If $x and $y contain regular expression characters
1625                 # AND THEY lowercase (/i) to regular expression characters,
1626                 # regcomp() will be mightily confused.  No, the \Q doesn't
1627                 # help here (maybe regex engine internal lowercasing
1628                 # is done after the \Q?)  An example of this happening is
1629                 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
1630                 # the chr(173) (the "[") is the lowercase of the chr(235).
1631                 #
1632                 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
1633                 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
1634                 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
1635                 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
1636                 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
1637                 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
1638                 #
1639                 # Similar things can happen even under (bastardised)
1640                 # non-EBCDIC locales: in many European countries before the
1641                 # advent of ISO 8859-x nationally customised versions of
1642                 # ISO 646 were devised, reusing certain punctuation
1643                 # characters for modified characters needed by the
1644                 # country/language.  For example, the "|" might have
1645                 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
1646                 #
1647                 if ($x =~ $re || $y =~ $re) {
1648                     print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1649                     next;
1650                 }
1651                 # With utf8 both will fail since the locale concept
1652                 # of upper/lower does not work well in Unicode.
1653                 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
1654
1655                 # fc is not a locale concept, so Perl uses lc for it.
1656                 push @f, $x unless lc $x eq fc $x;
1657             }
1658             else {
1659                 use locale ':not_characters';
1660                 my $y = lc $x;
1661                 next unless uc $y eq $x;
1662                 print "# UPPER $x lc $y ",
1663                         $x =~ /$y/i ? 1 : 0, " ",
1664                         $y =~ /$x/i ? 1 : 0, "\n" if 0;
1665
1666                 # Here, we can fully test things, unlike plain 'use locale',
1667                 # because this form does work well with Unicode
1668                 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1669
1670                 # The places where Unicode's lc is different from fc are
1671                 # skipped here by virtue of the 'next unless uc...' line above
1672                 push @f, $x unless lc $x eq fc $x;
1673             }
1674         }
1675
1676         foreach my $x (sort keys %lower) {
1677             if (! $is_utf8_locale) {
1678                 my $y = uc $x;
1679                 next unless lc $y eq $x;
1680                 print "# lower $x uc $y ",
1681                     $x =~ /$y/i ? 1 : 0, " ",
1682                     $y =~ /$x/i ? 1 : 0, "\n" if 0;
1683                 if ($x =~ $re || $y =~ $re) { # See above.
1684                     print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1685                     next;
1686                 }
1687                 # With utf8 both will fail since the locale concept
1688                 # of upper/lower does not work well in Unicode.
1689                 push @f, $x unless $x =~ /$y/i == $y =~ /$x/i;
1690
1691                 push @f, $x unless lc $x eq fc $x;
1692             }
1693             else {
1694                 use locale ':not_characters';
1695                 my $y = uc $x;
1696                 next unless lc $y eq $x;
1697                 print "# lower $x uc $y ",
1698                         $x =~ /$y/i ? 1 : 0, " ",
1699                         $y =~ /$x/i ? 1 : 0, "\n" if 0;
1700                 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1701
1702                 push @f, $x unless lc $x eq fc $x;
1703             }
1704         }
1705         report_multi_result($Locale, $locales_test_number, \@f);
1706     }
1707
1708     # [perl #109318]
1709     {
1710         my @f = ();
1711         ++$locales_test_number;
1712         $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
1713
1714         my $radix = POSIX::localeconv()->{decimal_point};
1715         my @nums = (
1716              "3.14e+9",  "3${radix}14e+9",  "3.14e-9",  "3${radix}14e-9",
1717             "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
1718         );
1719
1720         if (! $is_utf8_locale) {
1721             use locale;
1722             for my $num (@nums) {
1723                 push @f, $num
1724                     unless sprintf("%g", $num) =~ /3.+14/;
1725             }
1726         }
1727         else {
1728             use locale ':not_characters';
1729             for my $num (@nums) {
1730                 push @f, $num
1731                     unless sprintf("%g", $num) =~ /3.+14/;
1732             }
1733         }
1734
1735         report_result($Locale, $locales_test_number, @f == 0);
1736         if (@f) {
1737             print "# failed $locales_test_number locale '$Locale' numbers @f\n"
1738         }
1739     }
1740 }
1741
1742 my $final_locales_test_number = $locales_test_number;
1743
1744 # Recount the errors.
1745
1746 foreach ($first_locales_test_number..$final_locales_test_number) {
1747     if (%setlocale_failed) {
1748         print "not ";
1749     }
1750     elsif ($Problem{$_} || !defined $Okay{$_} || !@{$Okay{$_}}) {
1751         if (defined $not_necessarily_a_problem_test_number
1752             && $_ == $not_necessarily_a_problem_test_number)
1753         {
1754             print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
1755             print "# It usually indicates a problem in the environment,\n";
1756             print "# not in Perl itself.\n";
1757         }
1758         if ($Okay{$_} && ($_ >= $first_casing_test_number
1759                           && $_ <= $final_casing_test_number))
1760         {
1761             # Round to nearest .1%
1762             my $percent_fail = (int(.5 + (1000 * scalar(keys $Problem{$_})
1763                                           / scalar(@Locale))))
1764                                / 10;
1765             if (! $debug && $percent_fail < $acceptable_fold_failure_percentage)
1766             {
1767                 $test_names{$_} .= 'TODO';
1768                 print "# ", 100 - $percent_fail, "% of locales pass the following test, so it is likely that the failures\n";
1769                 print "# are errors in the locale definitions.  The test is marked TODO, as the\n";
1770                 print "# problem is not likely to be Perl's\n";
1771             }
1772         }
1773         print "#\n";
1774         if ($debug) {
1775             print "# The code points that had this failure are given above.  Look for lines\n";
1776             print "# that match 'failed $_'\n";
1777         }
1778         else {
1779             print "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
1780             print "# Then look at that output for lines that match 'failed $_'\n";
1781         }
1782         print "not ";
1783     }
1784     print "ok $_";
1785     if (defined $test_names{$_}) {
1786         # If TODO is in the test name, make it thus
1787         my $todo = $test_names{$_} =~ s/TODO\s*//;
1788         print " $test_names{$_}";
1789         print " # TODO" if $todo;
1790     }
1791     print "\n";
1792 }
1793
1794 $test_num = $final_locales_test_number;
1795
1796 {   # perl #115808
1797     use warnings;
1798     my $warned = 0;
1799     local $SIG{__WARN__} = sub {
1800         $warned = $_[0] =~ /uninitialized/;
1801     };
1802     my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy");
1803     ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized");
1804 }
1805
1806 # Test that tainting and case changing works on utf8 strings.  These tests are
1807 # placed last to avoid disturbing the hard-coded test numbers that existed at
1808 # the time these were added above this in this file.
1809 # This also tests that locale overrides unicode_strings in the same scope for
1810 # non-utf8 strings.
1811 setlocale(&POSIX::LC_ALL, "C");
1812 {
1813     use locale;
1814     use feature 'unicode_strings';
1815
1816     foreach my $function ("uc", "ucfirst", "lc", "lcfirst", "fc") {
1817         my @list;   # List of code points to test for $function
1818
1819         # Used to calculate the changed case for ASCII characters by using the
1820         # ord, instead of using one of the functions under test.
1821         my $ascii_case_change_delta;
1822         my $above_latin1_case_change_delta; # Same for the specific ords > 255
1823                                             # that we use
1824
1825         # We test an ASCII character, which should change case and be tainted;
1826         # a Latin1 character, which shouldn't change case under this C locale,
1827         #   and is tainted.
1828         # an above-Latin1 character that when the case is changed would cross
1829         #   the 255/256 boundary, so doesn't change case and isn't tainted
1830         # (the \x{149} is one of these, but changes into 2 characters, the
1831         #   first one of which doesn't cross the boundary.
1832         # the final one in each list is an above-Latin1 character whose case
1833         #   does change, and shouldn't be tainted.  The code below uses its
1834         #   position in its list as a marker to indicate that it, unlike the
1835         #   other code points above ASCII, has a successful case change
1836         if ($function =~ /^u/) {
1837             @list = ("", "a", "\xe0", "\xff", "\x{fb00}", "\x{149}", "\x{101}");
1838             $ascii_case_change_delta = -32;
1839             $above_latin1_case_change_delta = -1;
1840         }
1841         else {
1842             @list = ("", "A", "\xC0", "\x{17F}", "\x{100}");
1843             $ascii_case_change_delta = +32;
1844             $above_latin1_case_change_delta = +1;
1845         }
1846         foreach my $is_utf8_locale (0 .. 1) {
1847             foreach my $j (0 .. $#list) {
1848                 my $char = $list[$j];
1849
1850                 for my $encoded_in_utf8 (0 .. 1) {
1851                     my $should_be;
1852                     my $changed;
1853                     if (! $is_utf8_locale) {
1854                         $should_be = ($j == $#list)
1855                             ? chr(ord($char) + $above_latin1_case_change_delta)
1856                             : (length $char == 0 || ord($char) > 127)
1857                             ? $char
1858                             : chr(ord($char) + $ascii_case_change_delta);
1859
1860                         # This monstrosity is in order to avoid using an eval,
1861                         # which might perturb the results
1862                         $changed = ($function eq "uc")
1863                                     ? uc($char)
1864                                     : ($function eq "ucfirst")
1865                                       ? ucfirst($char)
1866                                       : ($function eq "lc")
1867                                         ? lc($char)
1868                                         : ($function eq "lcfirst")
1869                                           ? lcfirst($char)
1870                                           : ($function eq "fc")
1871                                             ? fc($char)
1872                                             : die("Unexpected function \"$function\"");
1873                     }
1874                     else {
1875                         {
1876                             no locale;
1877
1878                             # For utf8-locales the case changing functions
1879                             # should work just like they do outside of locale.
1880                             # Can use eval here because not testing it when
1881                             # not in locale.
1882                             $should_be = eval "$function('$char')";
1883                             die "Unexpected eval error $@ from 'eval \"$function('$char')\"'" if  $@;
1884
1885                         }
1886                         use locale ':not_characters';
1887                         $changed = ($function eq "uc")
1888                                     ? uc($char)
1889                                     : ($function eq "ucfirst")
1890                                       ? ucfirst($char)
1891                                       : ($function eq "lc")
1892                                         ? lc($char)
1893                                         : ($function eq "lcfirst")
1894                                           ? lcfirst($char)
1895                                           : ($function eq "fc")
1896                                             ? fc($char)
1897                                             : die("Unexpected function \"$function\"");
1898                     }
1899                     ok($changed eq $should_be,
1900                         "$function(\"$char\") in C locale "
1901                         . (($is_utf8_locale)
1902                             ? "(use locale ':not_characters'"
1903                             : "(use locale")
1904                         . (($encoded_in_utf8)
1905                             ? "; encoded in utf8)"
1906                             : "; not encoded in utf8)")
1907                         . " should be \"$should_be\", got \"$changed\"");
1908
1909                     # Tainting shouldn't happen for utf8 locales, empty
1910                     # strings, or those characters above 255.
1911                     (! $is_utf8_locale && length($char) > 0 && ord($char) < 256)
1912                     ? check_taint($changed)
1913                     : check_taint_not($changed);
1914
1915                     # Use UTF-8 next time through the loop
1916                     utf8::upgrade($char);
1917                 }
1918             }
1919         }
1920     }
1921 }
1922
1923 # Give final advice.
1924
1925 my $didwarn = 0;
1926
1927 foreach ($first_locales_test_number..$final_locales_test_number) {
1928     if ($Problem{$_}) {
1929         my @f = sort keys %{ $Problem{$_} };
1930         my $f = join(" ", @f);
1931         $f =~ s/(.{50,60}) /$1\n#\t/g;
1932         print
1933             "#\n",
1934             "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
1935             "#\t", $f, "\n#\n",
1936             "# on your system may have errors because the locale test $_\n",
1937             "# \"$test_names{$_}\"\n",
1938             "# failed in ", (@f == 1 ? "that locale" : "those locales"),
1939             ".\n";
1940         print <<EOW;
1941 #
1942 # If your users are not using these locales you are safe for the moment,
1943 # but please report this failure first to perlbug\@perl.com using the
1944 # perlbug script (as described in the INSTALL file) so that the exact
1945 # details of the failures can be sorted out first and then your operating
1946 # system supplier can be alerted about these anomalies.
1947 #
1948 EOW
1949         $didwarn = 1;
1950     }
1951 }
1952
1953 # Tell which locales were okay and which were not.
1954
1955 if ($didwarn) {
1956     my (@s, @F);
1957
1958     foreach my $l (@Locale) {
1959         my $p = 0;
1960         if ($setlocale_failed{$l}) {
1961             $p++;
1962         }
1963         else {
1964             foreach my $t
1965                         ($first_locales_test_number..$final_locales_test_number)
1966             {
1967                 $p++ if $Problem{$t}{$l};
1968             }
1969         }
1970         push @s, $l if $p == 0;
1971         push @F, $l unless $p == 0;
1972     }
1973
1974     if (@s) {
1975         my $s = join(" ", @s);
1976         $s =~ s/(.{50,60}) /$1\n#\t/g;
1977
1978         warn
1979             "# The following locales\n#\n",
1980             "#\t", $s, "\n#\n",
1981             "# tested okay.\n#\n",
1982     } else {
1983         warn "# None of your locales were fully okay.\n";
1984     }
1985
1986     if (@F) {
1987         my $F = join(" ", @F);
1988         $F =~ s/(.{50,60}) /$1\n#\t/g;
1989
1990         warn
1991           "# The following locales\n#\n",
1992           "#\t", $F, "\n#\n",
1993           "# had problems.\n#\n",
1994           "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
1995     } else {
1996         warn "# None of your locales were broken.\n";
1997     }
1998 }
1999
2000 print "1..$test_num\n";
2001
2002 # eof