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