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