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