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