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