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