3 # This tests plain 'use locale' and adorned 'use locale ":not_characters"'
4 # Because these pragmas are compile time, and I (khw) am trying to test
5 # without using 'eval' as much as possible, which might cloud the issue, the
6 # crucial parts of the code are duplicated in a block for each pragma.
8 # To make a TODO test, add the string 'TODO' to its %test_names value
10 binmode STDOUT, ':utf8';
11 binmode STDERR, ':utf8';
17 require Config; import Config;
18 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
22 require './loc_tools.pl';
29 # =1 adds debugging output; =2 increases the verbosity somewhat
30 my $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
32 # Certain tests have been shown to be problematical for a few locales. Don't
33 # fail them unless at least this percentage of the tested locales fail.
34 # Some Windows machines are defective in every locale but the C, calling \t
35 # printable; superscripts to be digits, etc. See
36 # http://markmail.org/message/5jwam4xsx4amsdnv. Also on AIX machines, many
37 # locales call a no-break space a graphic.
38 # (There aren't 1000 locales currently in existence, so 99.9 works)
39 my $acceptable_failure_percentage = ($^O =~ / ^ ( MSWin32 | AIX ) $ /ix)
43 # The list of test numbers of the problematic tests.
44 my %problematical_tests;
49 my $dumper = Dumpvalue->new(
56 my($mess) = join "", @_;
58 print $dumper->stringify($mess,1), "\n";
62 return unless $debug > 1;
75 my ($result, $message) = @_;
76 $message = "" unless defined $message;
78 print 'not ' unless ($result);
79 print "ok " . ++$test_num;
84 # First we'll do a lot of taint checking for locales.
85 # This is the easiest to test, actually, as any locale,
86 # even the default locale will taint under 'use locale'.
88 sub is_tainted { # hello, camel two.
89 no warnings 'uninitialized' ;
92 not eval { $dummy = join("", @_), kill 0; 1 }
95 sub check_taint ($;$) {
96 my $message_tail = $_[1] // "";
97 $message_tail = ": $message_tail" if $message_tail;
98 ok is_tainted($_[0]), "verify that is tainted$message_tail";
101 sub check_taint_not ($;$) {
102 my $message_tail = $_[1] // "";
103 $message_tail = ": $message_tail" if $message_tail;
104 ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
107 "\tb\t" =~ /^m?(\s)(.*)\1$/;
108 check_taint_not $&, "not tainted outside 'use locale'";
111 use locale; # engage locale and therefore locale taint.
113 check_taint_not $a, "\t\$a";
117 check_taint ucfirst($a);
123 check_taint lcfirst($a);
126 check_taint_not sprintf('%e', 123.456);
127 check_taint_not sprintf('%f', 123.456);
128 check_taint_not sprintf('%g', 123.456);
129 check_taint_not sprintf('%d', 123.456);
130 check_taint_not sprintf('%x', 123.456);
132 $_ = $a; # untaint $_
134 $_ = uc($a); # taint $_
136 check_taint $_, "\t\$_";
138 /(\w)/; # taint $&, $`, $', $+, $1.
139 check_taint $&, "\t/(\\w)/ \$&";
140 check_taint $`, "\t\$`";
141 check_taint $', "\t\$'";
142 check_taint $+, "\t\$+";
143 check_taint $1, "\t\$1";
144 check_taint_not $2, "\t\$2";
146 /(.)/; # untaint $&, $`, $', $+, $1.
147 check_taint_not $&, "\t/(.)/ \$&";
148 check_taint_not $`, "\t\$`";
149 check_taint_not $', "\t\$'";
150 check_taint_not $+, "\t\$+";
151 check_taint_not $1, "\t\$1";
152 check_taint_not $2, "\t\$2";
154 /(\W)/; # taint $&, $`, $', $+, $1.
155 check_taint $&, "\t/(\\W)/ \$&";
156 check_taint $`, "\t\$`";
157 check_taint $', "\t\$'";
158 check_taint $+, "\t\$+";
159 check_taint $1, "\t\$1";
160 check_taint_not $2, "\t\$2";
162 /(.)/; # untaint $&, $`, $', $+, $1.
163 check_taint_not $&, "\t/(.)/ \$&";
164 check_taint_not $`, "\t\$`";
165 check_taint_not $', "\t\$'";
166 check_taint_not $+, "\t\$+";
167 check_taint_not $1, "\t\$1";
168 check_taint_not $2, "\t\$2";
170 /(\s)/; # taint $&, $`, $', $+, $1.
171 check_taint $&, "\t/(\\s)/ \$&";
172 check_taint $`, "\t\$`";
173 check_taint $', "\t\$'";
174 check_taint $+, "\t\$+";
175 check_taint $1, "\t\$1";
176 check_taint_not $2, "\t\$2";
178 /(.)/; # untaint $&, $`, $', $+, $1.
179 check_taint_not $&, "\t/(.)/ \$&";
181 /(\S)/; # taint $&, $`, $', $+, $1.
182 check_taint $&, "\t/(\\S)/ \$&";
183 check_taint $`, "\t\$`";
184 check_taint $', "\t\$'";
185 check_taint $+, "\t\$+";
186 check_taint $1, "\t\$1";
187 check_taint_not $2, "\t\$2";
189 /(.)/; # untaint $&, $`, $', $+, $1.
190 check_taint_not $&, "\t/(.)/ \$&";
192 "a" =~ /(a)|(\w)/; # taint $&, $`, $', $+, $1.
193 check_taint $&, "\t/(a)|(\\w)/ \$&";
194 check_taint $`, "\t\$`";
195 check_taint $', "\t\$'";
196 check_taint $+, "\t\$+";
197 check_taint $1, "\t\$1";
198 ok($1 eq 'a', ("\t" x 4) . "\$1 is 'a'");
199 ok(! defined $2, ("\t" x 4) . "\$2 is undefined");
200 check_taint_not $2, "\t\$2";
201 check_taint_not $3, "\t\$3";
203 /(.)/; # untaint $&, $`, $', $+, $1.
204 check_taint_not $&, "\t/(.)/ \$&";
206 "\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i; # no tainting because no locale dependence
207 check_taint_not $&, "\t/(\\N{CYRILLIC CAPITAL LETTER A})/i \$&";
208 check_taint_not $`, "\t\$`";
209 check_taint_not $', "\t\$'";
210 check_taint_not $+, "\t\$+";
211 check_taint_not $1, "\t\$1";
212 ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\$1 is 'small cyrillic a'");
213 check_taint_not $2, "\t\$2";
215 /(.)/; # untaint $&, $`, $', $+, $1.
216 check_taint_not $&, "\t/./ \$&";
218 /(.)/; # untaint $&, $`, $', $+, $1.
219 check_taint_not $&, "\t/(.)/ \$&";
221 "a:" =~ /(.)\b(.)/; # taint $&, $`, $', $+, $1.
222 check_taint $&, "\t/(.)\\b(.)/ \$&";
223 check_taint $`, "\t\$`";
224 check_taint $', "\t\$'";
225 check_taint $+, "\t\$+";
226 check_taint $1, "\t\$1";
227 check_taint $2, "\t\$2";
228 check_taint_not $3, "\t\$3";
230 /(.)/; # untaint $&, $`, $', $+, $1.
231 check_taint_not $&, "\t/./ \$&";
233 "aa" =~ /(.)\B(.)/; # taint $&, $`, $', $+, $1.
234 check_taint $&, "\t/(.)\\B(.)/ \$&";
235 check_taint $`, "\t\$`";
236 check_taint $', "\t\$'";
237 check_taint $+, "\t\$+";
238 check_taint $1, "\t\$1";
239 check_taint $2, "\t\$2";
240 check_taint_not $3, "\t\$3";
242 /(.)/; # untaint $&, $`, $', $+, $1.
243 check_taint_not $&, "\t/./ \$&";
245 "aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
246 check_taint_not $&, "\t/(.).(\\1)/ \$&";
247 check_taint_not $`, "\t\$`";
248 check_taint_not $', "\t\$'";
249 check_taint_not $+, "\t\$+";
250 check_taint_not $1, "\t\$1";
251 check_taint_not $2, "\t\$2";
252 check_taint_not $3, "\t\$3";
254 /(.)/; # untaint $&, $`, $', $+, $1.
255 check_taint_not $&, "\t/./ \$&";
257 $_ = $a; # untaint $_
259 check_taint_not $_, "\t\$_";
261 /(b)/; # this must not taint
262 check_taint_not $&, "\t/(b)/ \$&";
263 check_taint_not $`, "\t\$`";
264 check_taint_not $', "\t\$'";
265 check_taint_not $+, "\t\$+";
266 check_taint_not $1, "\t\$1";
267 check_taint_not $2, "\t\$2";
269 $_ = $a; # untaint $_
271 check_taint_not $_, "\t\$_";
273 $b = uc($a); # taint $b
274 s/(.+)/$b/; # this must taint only the $_
276 check_taint $_, "\t\$_";
277 check_taint_not $&, "\t\$&";
278 check_taint_not $`, "\t\$`";
279 check_taint_not $', "\t\$'";
280 check_taint_not $+, "\t\$+";
281 check_taint_not $1, "\t\$1";
282 check_taint_not $2, "\t\$2";
284 $_ = $a; # untaint $_
286 s/(.+)/b/; # this must not taint
287 check_taint_not $_, "\t\$_";
288 check_taint_not $&, "\t\$&";
289 check_taint_not $`, "\t\$`";
290 check_taint_not $', "\t\$'";
291 check_taint_not $+, "\t\$+";
292 check_taint_not $1, "\t\$1";
293 check_taint_not $2, "\t\$2";
295 $b = $a; # untaint $b
297 ($b = $a) =~ s/\w/$&/;
298 check_taint $b, "\t\$b"; # $b should be tainted.
299 check_taint_not $a, "\t\$a"; # $a should be not.
301 $_ = $a; # untaint $_
303 s/(\w)/\l$1/; # this must taint
304 check_taint $_, "\t\$_";
305 check_taint $&, "\t\$&";
306 check_taint $`, "\t\$`";
307 check_taint $', "\t\$'";
308 check_taint $+, "\t\$+";
309 check_taint $1, "\t\$1";
310 check_taint_not $2, "\t\$2";
312 $_ = $a; # untaint $_
314 s/(\w)/\L$1/; # this must taint
315 check_taint $_, "\t\$_";
316 check_taint $&, "\t\$&";
317 check_taint $`, "\t\$`";
318 check_taint $', "\t\$'";
319 check_taint $+, "\t\$+";
320 check_taint $1, "\t\$1";
321 check_taint_not $2, "\t\$2";
323 $_ = $a; # untaint $_
325 s/(\w)/\u$1/; # this must taint
326 check_taint $_, "\t\$_";
327 check_taint $&, "\t\$&";
328 check_taint $`, "\t\$`";
329 check_taint $', "\t\$'";
330 check_taint $+, "\t\$+";
331 check_taint $1, "\t\$1";
332 check_taint_not $2, "\t\$2";
334 $_ = $a; # untaint $_
336 s/(\w)/\U$1/; # this must taint
337 check_taint $_, "\t\$_";
338 check_taint $&, "\t\$&";
339 check_taint $`, "\t\$`";
340 check_taint $', "\t\$'";
341 check_taint $+, "\t\$+";
342 check_taint $1, "\t\$1";
343 check_taint_not $2, "\t\$2";
345 # After all this tainting $a should be cool.
347 check_taint_not $a, "\t\$a";
350 check_taint_not $1, '"a" =~ /([a-z])/';
351 "foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
352 check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
354 # BE SURE TO COPY ANYTHING YOU ADD to the block below
356 { # This is just the previous tests copied here with a different
357 # compile-time pragma.
359 use locale ':not_characters'; # engage restricted locale with different
364 check_taint_not uc($a);
365 check_taint_not "\U$a";
366 check_taint_not ucfirst($a);
367 check_taint_not "\u$a";
368 check_taint_not lc($a);
369 check_taint_not fc($a);
370 check_taint_not "\L$a";
371 check_taint_not "\F$a";
372 check_taint_not lcfirst($a);
373 check_taint_not "\l$a";
375 check_taint_not sprintf('%e', 123.456);
376 check_taint_not sprintf('%f', 123.456);
377 check_taint_not sprintf('%g', 123.456);
378 check_taint_not sprintf('%d', 123.456);
379 check_taint_not sprintf('%x', 123.456);
381 $_ = $a; # untaint $_
383 $_ = uc($a); # taint $_
387 /(\w)/; # taint $&, $`, $', $+, $1.
395 /(.)/; # untaint $&, $`, $', $+, $1.
403 /(\W)/; # taint $&, $`, $', $+, $1.
411 /(\s)/; # taint $&, $`, $', $+, $1.
419 /(\S)/; # taint $&, $`, $', $+, $1.
427 $_ = $a; # untaint $_
431 /(b)/; # this must not taint
439 $_ = $a; # untaint $_
443 $b = uc($a); # taint $b
444 s/(.+)/$b/; # this must taint only the $_
454 $_ = $a; # untaint $_
456 s/(.+)/b/; # this must not taint
465 $b = $a; # untaint $b
467 ($b = $a) =~ s/\w/$&/;
468 check_taint_not $b; # $b should be tainted.
469 check_taint_not $a; # $a should be not.
471 $_ = $a; # untaint $_
473 s/(\w)/\l$1/; # this must taint
482 $_ = $a; # untaint $_
484 s/(\w)/\L$1/; # this must taint
493 $_ = $a; # untaint $_
495 s/(\w)/\u$1/; # this must taint
504 $_ = $a; # untaint $_
506 s/(\w)/\U$1/; # this must taint
515 # After all this tainting $a should be cool.
520 check_taint_not $1, '"a" =~ /([a-z])/';
521 "foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
522 check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
525 # Here are in scope of 'use locale'
527 # I think we've seen quite enough of taint.
528 # Let us do some *real* locale work now,
529 # unless setlocale() is missing (i.e. minitest).
531 # The test number before our first setlocale()
532 my $final_without_setlocale = $test_num;
536 debug "# Scanning for locales...\n";
538 require POSIX; import POSIX ':locale_h';
540 my @Locale = find_locales([ &POSIX::LC_CTYPE, &POSIX::LC_ALL ]);
542 debug "# Locales =\n";
548 print "1..$test_num\n";
553 setlocale(&POSIX::LC_ALL, "C");
560 my @Added_alpha; # Alphas that aren't in the C locale.
564 # This returns a display string denoting the input parameter @_, each
565 # entry of which is a single character in the range 0-255. The first part
566 # of the output is a string of the characters in @_ that are ASCII
567 # graphics, and hence unambiguously displayable. They are given by code
568 # point order. The second part is the remaining code points, the ordinals
569 # of which are each displayed as 2-digit hex. Blanks are inserted so as
570 # to keep anything from the first part looking like a 2-digit hex number.
573 my @chars = sort { ord $a <=> ord $b } @_;
577 push @chars, chr(258); # This sentinel simplifies the loop termination
579 foreach my $i (0 .. @chars - 1) {
580 my $char = $chars[$i];
584 # We avoid using [:posix:] classes, as these are being tested in this
585 # file. Each equivalence class below is for things that can appear in
586 # a range; those that can't be in a range have class -1. 0 for those
587 # which should be output in hex; and >0 for the other ranges
588 if ($char =~ /[A-Z]/) {
591 elsif ($char =~ /[a-z]/) {
594 elsif ($char =~ /[0-9]/) {
597 # Uncomment to get literal punctuation displayed instead of hex
598 #elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
599 # $class = -1; # Punct never appears in a range
602 $class = 0; # Output in hex
605 if (! defined $range_start) {
607 $output .= " " . $char;
610 $range_start = ord $char;
611 $start_class = $class;
613 } # A range ends if not consecutive, or the class-type changes
614 elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
615 || $class != $start_class)
618 # Here, the current character is not in the range. This means the
619 # previous character must have been. Output the range up through
621 my $range_length = $range_end - $range_start + 1;
622 if ($start_class > 0) {
623 $output .= " " . chr($range_start);
624 $output .= "-" . chr($range_end) if $range_length > 1;
627 $output .= sprintf(" %02X", $range_start);
628 $output .= sprintf("-%02X", $range_end) if $range_length > 1;
631 # Handle the new current character, as potentially beginning a new
643 my ($Locale, $i, $pass_fail, $message) = @_;
645 $message = " ($message)" if $message;
646 unless ($pass_fail) {
647 $Problem{$i}{$Locale} = 1;
648 debug "# failed $i ($test_names{$i}) with locale '$Locale'$message\n";
650 push @{$Okay{$i}}, $Locale;
654 sub report_multi_result {
655 my ($Locale, $i, $results_ref) = @_;
657 # $results_ref points to an array, each element of which is a character that was
658 # in error for this test numbered '$i'. If empty, the test passed
662 $message = join " ", "for", disp_chars(@$results_ref);
664 report_result($Locale, $i, @$results_ref == 0, $message);
667 my $first_locales_test_number = $final_without_setlocale + 1;
668 my $locales_test_number;
669 my $not_necessarily_a_problem_test_number;
670 my $first_casing_test_number;
671 my %setlocale_failed; # List of locales that setlocale() didn't work on
673 foreach my $Locale (@Locale) {
674 $locales_test_number = $first_locales_test_number - 1;
676 debug "# Locale = $Locale\n";
678 unless (setlocale(&POSIX::LC_ALL, $Locale)) {
679 $setlocale_failed{$Locale} = $Locale;
683 # We test UTF-8 locales only under ':not_characters'; It is easier to
684 # test them in other test files than here. Non- UTF-8 locales are tested
685 # only under plain 'use locale', as otherwise we would have to convert
686 # everything in them to Unicode.
688 my %UPPER = (); # All alpha X for which uc(X) == X and lc(X) != X
689 my %lower = (); # All alpha X for which lc(X) == X and uc(X) != X
690 my %BoThCaSe = (); # All alpha X for which uc(X) == lc(X) == X
692 my $is_utf8_locale = is_locale_utf8($Locale);
694 debug "# is utf8 locale? = $is_utf8_locale\n";
696 my $radix = localeconv()->{decimal_point};
697 if ($radix !~ / ^ [[:ascii:]] + $/x) {
699 $radix = disp_chars(split "", $radix);
701 debug "# radix = $radix\n";
703 if (! $is_utf8_locale) {
705 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
706 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
707 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
708 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
709 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
710 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
711 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
712 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
713 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
714 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
715 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
716 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
717 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
718 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
719 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
721 # Sieve the uppercase and the lowercase.
723 for (@{$posixes{'word'}}) {
724 if (/[^\d_]/) { # skip digits and the _
735 use locale ':not_characters';
736 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
737 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
738 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
739 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
740 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
741 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
742 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
743 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
744 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
745 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
746 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
747 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
748 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
749 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
750 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
751 for (@{$posixes{'word'}}) {
752 if (/[^\d_]/) { # skip digits and the _
763 # Ordered, where possible, in groups of "this is a subset of the next
765 debug "# :upper: = ", disp_chars(@{$posixes{'upper'}}), "\n";
766 debug "# :lower: = ", disp_chars(@{$posixes{'lower'}}), "\n";
767 debug "# :cased: = ", disp_chars(@{$posixes{'cased'}}), "\n";
768 debug "# :alpha: = ", disp_chars(@{$posixes{'alpha'}}), "\n";
769 debug "# :alnum: = ", disp_chars(@{$posixes{'alnum'}}), "\n";
770 debug "# w = ", disp_chars(@{$posixes{'word'}}), "\n";
771 debug "# :graph: = ", disp_chars(@{$posixes{'graph'}}), "\n";
772 debug "# :print: = ", disp_chars(@{$posixes{'print'}}), "\n";
773 debug "# d = ", disp_chars(@{$posixes{'digit'}}), "\n";
774 debug "# :xdigit: = ", disp_chars(@{$posixes{'xdigit'}}), "\n";
775 debug "# :blank: = ", disp_chars(@{$posixes{'blank'}}), "\n";
776 debug "# s = ", disp_chars(@{$posixes{'space'}}), "\n";
777 debug "# :punct: = ", disp_chars(@{$posixes{'punct'}}), "\n";
778 debug "# :cntrl: = ", disp_chars(@{$posixes{'cntrl'}}), "\n";
779 debug "# :ascii: = ", disp_chars(@{$posixes{'ascii'}}), "\n";
781 foreach (keys %UPPER) {
783 $BoThCaSe{$_}++ if exists $lower{$_};
785 foreach (keys %lower) {
786 $BoThCaSe{$_}++ if exists $UPPER{$_};
788 foreach (keys %BoThCaSe) {
794 foreach my $ord ( 0 .. 255 ) {
795 $Unassigned{chr $ord} = 1;
797 foreach my $class (keys %posixes) {
798 foreach my $char (@{$posixes{$class}}) {
799 delete $Unassigned{$char};
803 debug "# UPPER = ", disp_chars(sort { ord $a <=> ord $b } keys %UPPER), "\n";
804 debug "# lower = ", disp_chars(sort { ord $a <=> ord $b } keys %lower), "\n";
805 debug "# BoThCaSe = ", disp_chars(sort { ord $a <=> ord $b } keys %BoThCaSe), "\n";
806 debug "# Unassigned = ", disp_chars(sort { ord $a <=> ord $b } keys %Unassigned), "\n";
810 foreach my $x (sort { ord $a <=> ord $b } keys %UPPER) {
813 if ($is_utf8_locale) {
814 use locale ':not_characters';
815 $ok = $x =~ /[[:upper:]]/;
816 $fold_ok = $x =~ /[[:lower:]]/i;
820 $ok = $x =~ /[[:upper:]]/;
821 $fold_ok = $x =~ /[[:lower:]]/i;
823 push @failures, $x unless $ok;
824 push @fold_failures, $x unless $fold_ok;
826 $locales_test_number++;
827 $first_casing_test_number = $locales_test_number;
828 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches all alpha X for which uc(X) == X and lc(X) != X';
829 report_multi_result($Locale, $locales_test_number, \@failures);
831 $locales_test_number++;
833 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i matches all alpha X for which uc(X) == X and lc(X) != X';
834 report_multi_result($Locale, $locales_test_number, \@fold_failures);
837 undef @fold_failures;
839 foreach my $x (sort { ord $a <=> ord $b } keys %lower) {
842 if ($is_utf8_locale) {
843 use locale ':not_characters';
844 $ok = $x =~ /[[:lower:]]/;
845 $fold_ok = $x =~ /[[:upper:]]/i;
849 $ok = $x =~ /[[:lower:]]/;
850 $fold_ok = $x =~ /[[:upper:]]/i;
852 push @failures, $x unless $ok;
853 push @fold_failures, $x unless $fold_ok;
856 $locales_test_number++;
857 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/ matches all alpha X for which lc(X) == X and uc(X) != X';
858 report_multi_result($Locale, $locales_test_number, \@failures);
860 $locales_test_number++;
861 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/i matches all alpha X for which lc(X) == X and uc(X) != X';
862 report_multi_result($Locale, $locales_test_number, \@fold_failures);
864 { # Find the alphabetic characters that are not considered alphabetics
865 # in the default (C) locale.
870 for (keys %UPPER, keys %lower, keys %BoThCaSe) {
871 push(@Added_alpha, $_) if (/\W/);
875 @Added_alpha = sort { ord $a <=> ord $b } @Added_alpha;
877 debug "# Added_alpha = ", disp_chars(@Added_alpha), "\n";
879 # Cross-check the whole 8-bit character set.
881 ++$locales_test_number;
883 $test_names{$locales_test_number} = 'Verify that \w and [:word:] are identical';
884 for (map { chr } 0..255) {
885 if ($is_utf8_locale) {
886 use locale ':not_characters';
887 push @f, $_ unless /[[:word:]]/ == /\w/;
890 push @f, $_ unless /[[:word:]]/ == /\w/;
893 report_multi_result($Locale, $locales_test_number, \@f);
895 ++$locales_test_number;
897 $test_names{$locales_test_number} = 'Verify that \d and [:digit:] are identical';
898 for (map { chr } 0..255) {
899 if ($is_utf8_locale) {
900 use locale ':not_characters';
901 push @f, $_ unless /[[:digit:]]/ == /\d/;
904 push @f, $_ unless /[[:digit:]]/ == /\d/;
907 report_multi_result($Locale, $locales_test_number, \@f);
909 ++$locales_test_number;
911 $test_names{$locales_test_number} = 'Verify that \s and [:space:] are identical';
912 for (map { chr } 0..255) {
913 if ($is_utf8_locale) {
914 use locale ':not_characters';
915 push @f, $_ unless /[[:space:]]/ == /\s/;
918 push @f, $_ unless /[[:space:]]/ == /\s/;
921 report_multi_result($Locale, $locales_test_number, \@f);
923 ++$locales_test_number;
925 $test_names{$locales_test_number} = 'Verify that [:posix:] and [:^posix:] are mutually exclusive';
926 for (map { chr } 0..255) {
927 if ($is_utf8_locale) {
928 use locale ':not_characters';
929 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
930 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
931 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
932 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
933 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
934 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
935 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
936 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
937 (/[[:print:]]/ xor /[[:^print:]]/) ||
938 (/[[:space:]]/ xor /[[:^space:]]/) ||
939 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
940 (/[[:word:]]/ xor /[[:^word:]]/) ||
941 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
943 # effectively is what [:cased:] would be if it existed.
944 (/[[:upper:]]/i xor /[[:^upper:]]/i);
947 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
948 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
949 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
950 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
951 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
952 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
953 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
954 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
955 (/[[:print:]]/ xor /[[:^print:]]/) ||
956 (/[[:space:]]/ xor /[[:^space:]]/) ||
957 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
958 (/[[:word:]]/ xor /[[:^word:]]/) ||
959 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
960 (/[[:upper:]]/i xor /[[:^upper:]]/i);
963 report_multi_result($Locale, $locales_test_number, \@f);
965 # The rules for the relationships are given in:
966 # http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
969 ++$locales_test_number;
971 $test_names{$locales_test_number} = 'Verify that [:lower:] contains at least a-z';
973 if ($is_utf8_locale) {
974 use locale ':not_characters';
975 push @f, $_ unless /[[:lower:]]/;
978 push @f, $_ unless /[[:lower:]]/;
981 report_multi_result($Locale, $locales_test_number, \@f);
983 ++$locales_test_number;
985 $test_names{$locales_test_number} = 'Verify that [:lower:] is a subset of [:alpha:]';
986 for (map { chr } 0..255) {
987 if ($is_utf8_locale) {
988 use locale ':not_characters';
989 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
992 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
995 report_multi_result($Locale, $locales_test_number, \@f);
997 ++$locales_test_number;
999 $test_names{$locales_test_number} = 'Verify that [:upper:] contains at least A-Z';
1001 if ($is_utf8_locale) {
1002 use locale ':not_characters';
1003 push @f, $_ unless /[[:upper:]]/;
1006 push @f, $_ unless /[[:upper:]]/;
1009 report_multi_result($Locale, $locales_test_number, \@f);
1011 ++$locales_test_number;
1013 $test_names{$locales_test_number} = 'Verify that [:upper:] is a subset of [:alpha:]';
1014 for (map { chr } 0..255) {
1015 if ($is_utf8_locale) {
1016 use locale ':not_characters';
1017 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1020 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1023 report_multi_result($Locale, $locales_test_number, \@f);
1025 ++$locales_test_number;
1027 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i is a subset of [:alpha:]';
1028 for (map { chr } 0..255) {
1029 if ($is_utf8_locale) {
1030 use locale ':not_characters';
1031 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1034 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1037 report_multi_result($Locale, $locales_test_number, \@f);
1039 ++$locales_test_number;
1041 $test_names{$locales_test_number} = 'Verify that [:alpha:] is a subset of [:alnum:]';
1042 for (map { chr } 0..255) {
1043 if ($is_utf8_locale) {
1044 use locale ':not_characters';
1045 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1048 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1051 report_multi_result($Locale, $locales_test_number, \@f);
1053 ++$locales_test_number;
1055 $test_names{$locales_test_number} = 'Verify that [:digit:] contains at least 0-9';
1057 if ($is_utf8_locale) {
1058 use locale ':not_characters';
1059 push @f, $_ unless /[[:digit:]]/;
1062 push @f, $_ unless /[[:digit:]]/;
1065 report_multi_result($Locale, $locales_test_number, \@f);
1067 ++$locales_test_number;
1069 $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:alnum:]';
1070 for (map { chr } 0..255) {
1071 if ($is_utf8_locale) {
1072 use locale ':not_characters';
1073 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1076 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1079 report_multi_result($Locale, $locales_test_number, \@f);
1081 ++$locales_test_number;
1083 $test_names{$locales_test_number} = 'Verify that [:digit:] matches either 10 or 20 code points';
1084 report_result($Locale, $locales_test_number, @{$posixes{'digit'}} == 10 || @{$posixes{'digit'}} == 20);
1086 ++$locales_test_number;
1088 $test_names{$locales_test_number} = 'Verify that if there is a second set of digits in [:digit:], they are consecutive';
1089 if (@{$posixes{'digit'}} == 20) {
1091 for (map { chr } 0..255) {
1092 next unless /[[:digit:]]/;
1094 if (defined $previous_ord) {
1095 if ($is_utf8_locale) {
1096 use locale ':not_characters';
1097 push @f, $_ if ord $_ != $previous_ord + 1;
1100 push @f, $_ if ord $_ != $previous_ord + 1;
1103 $previous_ord = ord $_;
1106 report_multi_result($Locale, $locales_test_number, \@f);
1108 ++$locales_test_number;
1110 my @xdigit_digits; # :digit: & :xdigit:
1111 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains one or two blocks of 10 consecutive [:digit:] chars';
1112 for (map { chr } 0..255) {
1113 if ($is_utf8_locale) {
1114 use locale ':not_characters';
1115 # For utf8 locales, we actually use a stricter test: that :digit:
1116 # is a subset of :xdigit:, as we know that only 0-9 should match
1117 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1120 push @xdigit_digits, $_ if /[[:digit:]]/ and /[[:xdigit:]]/;
1123 if (! $is_utf8_locale) {
1125 # For non-utf8 locales, @xdigit_digits is a list of the characters
1126 # that are both :xdigit: and :digit:. Because :digit: is stored in
1127 # increasing code point order (unless the tests above failed),
1128 # @xdigit_digits is as well. There should be exactly 10 or
1130 if (@xdigit_digits != 10 && @xdigit_digits != 20) {
1131 @f = @xdigit_digits;
1135 # Look for contiguity in the series, adding any wrong ones to @f
1136 my @temp = @xdigit_digits;
1138 push @f, $temp[1] if ($temp[0] != $temp[1] - 1)
1140 # Skip this test for the 0th character of
1141 # the second block of 10, as it won't be
1142 # contiguous with the previous block
1143 && (! defined $xdigit_digits[10]
1144 || $temp[1] != $xdigit_digits[10]);
1150 report_multi_result($Locale, $locales_test_number, \@f);
1152 ++$locales_test_number;
1154 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains at least A-F, a-f';
1155 for ('A' .. 'F', 'a' .. 'f') {
1156 if ($is_utf8_locale) {
1157 use locale ':not_characters';
1158 push @f, $_ unless /[[:xdigit:]]/;
1161 push @f, $_ unless /[[:xdigit:]]/;
1164 report_multi_result($Locale, $locales_test_number, \@f);
1166 ++$locales_test_number;
1168 $test_names{$locales_test_number} = 'Verify that any additional members of [:xdigit:], are in groups of 6 consecutive code points';
1171 for my $chr (map { chr } 0..255) {
1172 next unless $chr =~ /[[:xdigit:]]/;
1173 if ($is_utf8_locale) {
1174 next if $chr =~ /[[:digit:]]/;
1177 next if grep { $chr eq $_ } @xdigit_digits;
1179 next if $chr =~ /[A-Fa-f]/;
1180 if (defined $previous_ord) {
1181 if ($is_utf8_locale) {
1182 use locale ':not_characters';
1183 push @f, $chr if ord $chr != $previous_ord + 1;
1186 push @f, $chr if ord $chr != $previous_ord + 1;
1191 undef $previous_ord;
1194 $previous_ord = ord $chr;
1197 report_multi_result($Locale, $locales_test_number, \@f);
1199 ++$locales_test_number;
1201 $test_names{$locales_test_number} = 'Verify that [:xdigit:] is a subset of [:graph:]';
1202 for (map { chr } 0..255) {
1203 if ($is_utf8_locale) {
1204 use locale ':not_characters';
1205 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1208 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1211 report_multi_result($Locale, $locales_test_number, \@f);
1213 # Note that xdigit doesn't have to be a subset of alnum
1215 ++$locales_test_number;
1217 $test_names{$locales_test_number} = 'Verify that [:punct:] is a subset of [:graph:]';
1218 for (map { chr } 0..255) {
1219 if ($is_utf8_locale) {
1220 use locale ':not_characters';
1221 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1224 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1227 report_multi_result($Locale, $locales_test_number, \@f);
1229 ++$locales_test_number;
1231 $test_names{$locales_test_number} = 'Verify that the space character is not in [:graph:]';
1232 if ($is_utf8_locale) {
1233 use locale ':not_characters';
1234 push @f, " " if " " =~ /[[:graph:]]/;
1237 push @f, " " if " " =~ /[[:graph:]]/;
1239 report_multi_result($Locale, $locales_test_number, \@f);
1241 ++$locales_test_number;
1243 $test_names{$locales_test_number} = 'Verify that [:space:] contains at least [\f\n\r\t\cK ]';
1244 for (' ', "\f", "\n", "\r", "\t", "\cK") {
1245 if ($is_utf8_locale) {
1246 use locale ':not_characters';
1247 push @f, $_ unless /[[:space:]]/;
1250 push @f, $_ unless /[[:space:]]/;
1253 report_multi_result($Locale, $locales_test_number, \@f);
1255 ++$locales_test_number;
1257 $test_names{$locales_test_number} = 'Verify that [:blank:] contains at least [\t ]';
1259 if ($is_utf8_locale) {
1260 use locale ':not_characters';
1261 push @f, $_ unless /[[:blank:]]/;
1264 push @f, $_ unless /[[:blank:]]/;
1267 report_multi_result($Locale, $locales_test_number, \@f);
1269 ++$locales_test_number;
1271 $test_names{$locales_test_number} = 'Verify that [:blank:] is a subset of [:space:]';
1272 for (map { chr } 0..255) {
1273 if ($is_utf8_locale) {
1274 use locale ':not_characters';
1275 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1278 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1281 report_multi_result($Locale, $locales_test_number, \@f);
1283 ++$locales_test_number;
1285 $test_names{$locales_test_number} = 'Verify that [:graph:] is a subset of [:print:]';
1286 for (map { chr } 0..255) {
1287 if ($is_utf8_locale) {
1288 use locale ':not_characters';
1289 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1292 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1295 report_multi_result($Locale, $locales_test_number, \@f);
1297 ++$locales_test_number;
1299 $test_names{$locales_test_number} = 'Verify that the space character is in [:print:]';
1300 if ($is_utf8_locale) {
1301 use locale ':not_characters';
1302 push @f, " " if " " !~ /[[:print:]]/;
1305 push @f, " " if " " !~ /[[:print:]]/;
1307 report_multi_result($Locale, $locales_test_number, \@f);
1309 ++$locales_test_number;
1311 $test_names{$locales_test_number} = 'Verify that isn\'t both [:cntrl:] and [:print:]';
1312 for (map { chr } 0..255) {
1313 if ($is_utf8_locale) {
1314 use locale ':not_characters';
1315 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1318 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1321 report_multi_result($Locale, $locales_test_number, \@f);
1323 ++$locales_test_number;
1325 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alpha:] and [:digit:]';
1326 for (map { chr } 0..255) {
1327 if ($is_utf8_locale) {
1328 use locale ':not_characters';
1329 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1332 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1335 report_multi_result($Locale, $locales_test_number, \@f);
1337 ++$locales_test_number;
1339 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alnum:] and [:punct:]';
1340 for (map { chr } 0..255) {
1341 if ($is_utf8_locale) {
1342 use locale ':not_characters';
1343 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1346 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1349 report_multi_result($Locale, $locales_test_number, \@f);
1351 ++$locales_test_number;
1353 $test_names{$locales_test_number} = 'Verify that isn\'t both [:xdigit:] and [:punct:]';
1354 for (map { chr } 0..255) {
1355 if ($is_utf8_locale) {
1356 use locale ':not_characters';
1357 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1360 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1363 report_multi_result($Locale, $locales_test_number, \@f);
1365 ++$locales_test_number;
1367 $test_names{$locales_test_number} = 'Verify that isn\'t both [:graph:] and [:space:]';
1368 for (map { chr } 0..255) {
1369 if ($is_utf8_locale) {
1370 use locale ':not_characters';
1371 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1374 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1377 report_multi_result($Locale, $locales_test_number, \@f);
1379 foreach ($first_casing_test_number..$locales_test_number) {
1380 $problematical_tests{$_} = 1;
1384 # Test for read-only scalars' locale vs non-locale comparisons.
1390 if ($is_utf8_locale) {
1391 use locale ':not_characters';
1392 $ok = ($a cmp "qwerty") == 0;
1396 $ok = ($a cmp "qwerty") == 0;
1398 report_result($Locale, ++$locales_test_number, $ok);
1399 $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
1403 my ($from, $to, $lesser, $greater,
1404 @test, %test, $test, $yes, $no, $sign);
1406 ++$locales_test_number;
1407 $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
1408 $not_necessarily_a_problem_test_number = $locales_test_number;
1411 $from = int(($_*@{$posixes{'word'}})/10);
1412 $to = $from + int(@{$posixes{'word'}}/10);
1413 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1414 $lesser = join('', @{$posixes{'word'}}[$from..$to]);
1415 # Select a slice one character on.
1417 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1418 $greater = join('', @{$posixes{'word'}}[$from..$to]);
1419 if ($is_utf8_locale) {
1420 use locale ':not_characters';
1421 ($yes, $no, $sign) = ($lesser lt $greater
1423 : ("not ", " ", -1));
1427 ($yes, $no, $sign) = ($lesser lt $greater
1429 : ("not ", " ", -1));
1431 # all these tests should FAIL (return 0). Exact lt or gt cannot
1432 # be tested because in some locales, say, eacute and E may test
1436 $no.' ($lesser le $greater)', # 1
1437 'not ($lesser ne $greater)', # 2
1438 ' ($lesser eq $greater)', # 3
1439 $yes.' ($lesser ge $greater)', # 4
1440 $yes.' ($lesser ge $greater)', # 5
1441 $yes.' ($greater le $lesser )', # 7
1442 'not ($greater ne $lesser )', # 8
1443 ' ($greater eq $lesser )', # 9
1444 $no.' ($greater ge $lesser )', # 10
1445 'not (($lesser cmp $greater) == -($sign))' # 11
1447 @test{@test} = 0 x @test;
1449 for my $ti (@test) {
1450 if ($is_utf8_locale) {
1451 use locale ':not_characters';
1452 $test{$ti} = eval $ti;
1455 # Already in 'use locale';
1456 $test{$ti} = eval $ti;
1458 $test ||= $test{$ti}
1460 report_result($Locale, $locales_test_number, $test == 0);
1462 debug "# lesser = '$lesser'\n";
1463 debug "# greater = '$greater'\n";
1464 debug "# lesser cmp greater = ",
1465 $lesser cmp $greater, "\n";
1466 debug "# greater cmp lesser = ",
1467 $greater cmp $lesser, "\n";
1468 debug "# (greater) from = $from, to = $to\n";
1469 for my $ti (@test) {
1470 debugf("# %-40s %-4s", $ti,
1471 $test{$ti} ? 'FAIL' : 'ok');
1472 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
1473 debugf("(%s == %4d)", $1, eval $1);
1511 if (! $is_utf8_locale) {
1514 my ($x, $y) = (1.23, 1.23);
1517 printf ''; # printf used to reset locale to "C"
1522 my $z = sprintf ''; # sprintf used to reset locale to "C"
1529 local $SIG{__WARN__} =
1535 # The == (among other ops) used to warn for locales
1536 # that had something else than "." as the radix character.
1560 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1562 $ok14 = $ok15 = $ok16 = 1; # Skip for non-utf8 locales
1566 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1568 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1571 use locale ':not_characters';
1573 my ($x, $y) = (1.23, 1.23);
1575 printf ''; # printf used to reset locale to "C"
1580 my $z = sprintf ''; # sprintf used to reset locale to "C"
1586 local $SIG{__WARN__} =
1612 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1615 # Look for non-ASCII error messages, and verify that the first
1616 # such is NOT in UTF-8 (the others almost certainly will be like
1617 # the first) See [perl #119499].
1619 foreach my $err (keys %!) {
1621 $! = eval "&Errno::$err"; # Convert to strerror() output
1622 my $strerror = "$!";
1623 if ("$strerror" =~ /\P{ASCII}/) {
1624 $ok14 = ! utf8::is_utf8($strerror);
1629 # Similarly, we verify that a non-ASCII radix is in UTF-8. This
1630 # also catches if there is a disparity between sprintf and
1633 my $string_g = "$g";
1634 my $sprintf_g = sprintf("%g", $g);
1636 $ok15 = $string_g =~ / ^ \p{ASCII}+ $ /x || utf8::is_utf8($string_g);
1637 $ok16 = $sprintf_g eq $string_g;
1641 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1643 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1646 report_result($Locale, ++$locales_test_number, $ok1);
1647 $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
1648 my $first_a_test = $locales_test_number;
1650 debug "# $first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
1652 report_result($Locale, ++$locales_test_number, $ok2);
1653 $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
1655 my $first_c_test = $locales_test_number;
1657 report_result($Locale, ++$locales_test_number, $ok3);
1658 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
1659 $problematical_tests{$locales_test_number} = 1;
1661 report_result($Locale, ++$locales_test_number, $ok4);
1662 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
1663 $problematical_tests{$locales_test_number} = 1;
1665 report_result($Locale, ++$locales_test_number, $ok5);
1666 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
1667 $problematical_tests{$locales_test_number} = 1;
1669 debug "# $first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
1671 report_result($Locale, ++$locales_test_number, $ok6);
1672 $test_names{$locales_test_number} = 'Verify that can assign stringified under inner no-locale block';
1673 my $first_e_test = $locales_test_number;
1675 report_result($Locale, ++$locales_test_number, $ok7);
1676 $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
1678 report_result($Locale, ++$locales_test_number, $ok8);
1679 $test_names{$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
1680 $problematical_tests{$locales_test_number} = 1;
1682 debug "# $first_e_test..$locales_test_number: \$e = $e, no locale\n";
1684 report_result($Locale, ++$locales_test_number, $ok9);
1685 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
1686 $problematical_tests{$locales_test_number} = 1;
1687 my $first_f_test = $locales_test_number;
1689 report_result($Locale, ++$locales_test_number, $ok10);
1690 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
1691 $problematical_tests{$locales_test_number} = 1;
1693 report_result($Locale, ++$locales_test_number, $ok11);
1694 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar and an intervening sprintf';
1695 $problematical_tests{$locales_test_number} = 1;
1697 report_result($Locale, ++$locales_test_number, $ok12);
1698 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix can participate in an addition and function call as numeric';
1699 $problematical_tests{$locales_test_number} = 1;
1701 report_result($Locale, ++$locales_test_number, $ok13);
1702 $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
1703 $problematical_tests{$locales_test_number} = 1;
1705 report_result($Locale, ++$locales_test_number, $ok14);
1706 $test_names{$locales_test_number} = 'Verify that non-ASCII UTF-8 error messages are NOT in UTF-8';
1708 report_result($Locale, ++$locales_test_number, $ok15);
1709 $test_names{$locales_test_number} = 'Verify that a number with a UTF-8 radix has a UTF-8 stringification';
1711 report_result($Locale, ++$locales_test_number, $ok16);
1712 $test_names{$locales_test_number} = 'Verify that a sprintf of a number with a UTF-8 radix yields UTF-8';
1714 report_result($Locale, ++$locales_test_number, $ok17);
1715 $test_names{$locales_test_number} = 'Verify that a sprintf of a number outside locale scope uses a dot radix';
1717 report_result($Locale, ++$locales_test_number, $ok18);
1718 $test_names{$locales_test_number} = 'Verify that a sprintf of a number back within locale scope uses locale radix';
1720 debug "# $first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
1722 # Does taking lc separately differ from taking
1723 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
1724 # The bug was in the caching of the 'o'-magic.
1725 if (! $is_utf8_locale) {
1731 return $lc0 cmp $lc1;
1735 return lc($_[0]) cmp lc($_[1]);
1742 report_result($Locale, ++$locales_test_number,
1743 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
1744 lcA($x, $z) == 0 && lcB($x, $z) == 0);
1747 use locale ':not_characters';
1752 return $lc0 cmp $lc1;
1756 return lc($_[0]) cmp lc($_[1]);
1763 report_result($Locale, ++$locales_test_number,
1764 lcC($x, $y) == 1 && lcD($x, $y) == 1 ||
1765 lcC($x, $z) == 0 && lcD($x, $z) == 0);
1767 $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
1769 # Does lc of an UPPER (if different from the UPPER) match
1770 # case-insensitively the UPPER, and does the UPPER match
1771 # case-insensitively the lc of the UPPER. And vice versa.
1775 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
1778 ++$locales_test_number;
1779 $test_names{$locales_test_number} = 'Verify case insensitive matching works';
1780 foreach my $x (sort { ord $a <=> ord $b } keys %UPPER) {
1781 if (! $is_utf8_locale) {
1783 next unless uc $y eq $x;
1784 debug_more( "# UPPER=", disp_chars(($x)),
1785 "; lc=", disp_chars(($y)), "; ",
1786 "; fc=", disp_chars((fc $x)), "; ",
1787 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
1788 $x =~ /$y/i ? 1 : 0,
1790 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
1791 $y =~ /$x/i ? 1 : 0,
1794 # If $x and $y contain regular expression characters
1795 # AND THEY lowercase (/i) to regular expression characters,
1796 # regcomp() will be mightily confused. No, the \Q doesn't
1797 # help here (maybe regex engine internal lowercasing
1798 # is done after the \Q?) An example of this happening is
1799 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
1800 # the chr(173) (the "[") is the lowercase of the chr(235).
1802 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
1803 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
1804 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
1805 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
1806 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
1807 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
1809 # Similar things can happen even under (bastardised)
1810 # non-EBCDIC locales: in many European countries before the
1811 # advent of ISO 8859-x nationally customised versions of
1812 # ISO 646 were devised, reusing certain punctuation
1813 # characters for modified characters needed by the
1814 # country/language. For example, the "|" might have
1815 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
1817 if ($x =~ $re || $y =~ $re) {
1818 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1821 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1823 # fc is not a locale concept, so Perl uses lc for it.
1824 push @f, $x unless lc $x eq fc $x;
1827 use locale ':not_characters';
1829 next unless uc $y eq $x;
1830 debug_more( "# UPPER=", disp_chars(($x)),
1831 "; lc=", disp_chars(($y)), "; ",
1832 "; fc=", disp_chars((fc $x)), "; ",
1833 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
1834 $x =~ /$y/i ? 1 : 0,
1836 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
1837 $y =~ /$x/i ? 1 : 0,
1840 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1842 # The places where Unicode's lc is different from fc are
1843 # skipped here by virtue of the 'next unless uc...' line above
1844 push @f, $x unless lc $x eq fc $x;
1848 foreach my $x (sort { ord $a <=> ord $b } keys %lower) {
1849 if (! $is_utf8_locale) {
1851 next unless lc $y eq $x;
1852 debug_more( "# lower=", disp_chars(($x)),
1853 "; uc=", disp_chars(($y)), "; ",
1854 "; fc=", disp_chars((fc $x)), "; ",
1855 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
1856 $x =~ /$y/i ? 1 : 0,
1858 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
1859 $y =~ /$x/i ? 1 : 0,
1861 if ($x =~ $re || $y =~ $re) { # See above.
1862 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1865 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1867 push @f, $x unless lc $x eq fc $x;
1870 use locale ':not_characters';
1872 next unless lc $y eq $x;
1873 debug_more( "# lower=", disp_chars(($x)),
1874 "; uc=", disp_chars(($y)), "; ",
1875 "; fc=", disp_chars((fc $x)), "; ",
1876 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
1877 $x =~ /$y/i ? 1 : 0,
1879 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
1880 $y =~ /$x/i ? 1 : 0,
1882 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1884 push @f, $x unless lc $x eq fc $x;
1887 report_multi_result($Locale, $locales_test_number, \@f);
1888 $problematical_tests{$locales_test_number} = 1;
1894 ++$locales_test_number;
1895 $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
1896 $problematical_tests{$locales_test_number} = 1;
1898 my $radix = POSIX::localeconv()->{decimal_point};
1900 "3.14e+9", "3${radix}14e+9", "3.14e-9", "3${radix}14e-9",
1901 "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
1904 if (! $is_utf8_locale) {
1906 for my $num (@nums) {
1908 unless sprintf("%g", $num) =~ /3.+14/;
1912 use locale ':not_characters';
1913 for my $num (@nums) {
1915 unless sprintf("%g", $num) =~ /3.+14/;
1919 report_result($Locale, $locales_test_number, @f == 0);
1921 print "# failed $locales_test_number locale '$Locale' numbers @f\n"
1926 my $final_locales_test_number = $locales_test_number;
1928 # Recount the errors.
1930 foreach $test_num ($first_locales_test_number..$final_locales_test_number) {
1931 if (%setlocale_failed) {
1934 elsif ($Problem{$test_num} || !defined $Okay{$test_num} || !@{$Okay{$test_num}}) {
1935 if (defined $not_necessarily_a_problem_test_number
1936 && $test_num == $not_necessarily_a_problem_test_number)
1938 print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
1939 print "# It usually indicates a problem in the environment,\n";
1940 print "# not in Perl itself.\n";
1942 if ($Okay{$test_num} && grep { $_ == $test_num } keys %problematical_tests) {
1943 no warnings 'experimental::autoderef';
1944 # Round to nearest .1%
1945 my $percent_fail = (int(.5 + (1000 * scalar(keys $Problem{$test_num})
1946 / scalar(@Locale))))
1948 if (! $debug && $percent_fail < $acceptable_failure_percentage)
1950 $test_names{$test_num} .= 'TODO';
1951 print "# ", 100 - $percent_fail, "% of locales pass the following test, so it is likely that the failures\n";
1952 print "# are errors in the locale definitions. The test is marked TODO, as the\n";
1953 print "# problem is not likely to be Perl's\n";
1958 print "# The code points that had this failure are given above. Look for lines\n";
1959 print "# that match 'failed $test_num'\n";
1962 print "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
1963 print "# Then look at that output for lines that match 'failed $test_num'\n";
1967 print "ok $test_num";
1968 if (defined $test_names{$test_num}) {
1969 # If TODO is in the test name, make it thus
1970 my $todo = $test_names{$test_num} =~ s/TODO\s*//;
1971 print " $test_names{$test_num}";
1972 print " # TODO" if $todo;
1977 $test_num = $final_locales_test_number;
1979 unless ( $^O =~ m!^(dragonfly|openbsd|bitrig|mirbsd)$! ) {
1983 local $SIG{__WARN__} = sub {
1984 $warned = $_[0] =~ /uninitialized/;
1986 my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy");
1987 ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized");
1990 # Test that tainting and case changing works on utf8 strings. These tests are
1991 # placed last to avoid disturbing the hard-coded test numbers that existed at
1992 # the time these were added above this in this file.
1993 # This also tests that locale overrides unicode_strings in the same scope for
1995 setlocale(&POSIX::LC_ALL, "C");
1998 use feature 'unicode_strings';
2000 foreach my $function ("uc", "ucfirst", "lc", "lcfirst", "fc") {
2001 my @list; # List of code points to test for $function
2003 # Used to calculate the changed case for ASCII characters by using the
2004 # ord, instead of using one of the functions under test.
2005 my $ascii_case_change_delta;
2006 my $above_latin1_case_change_delta; # Same for the specific ords > 255
2009 # We test an ASCII character, which should change case;
2010 # a Latin1 character, which shouldn't change case under this C locale,
2011 # an above-Latin1 character that when the case is changed would cross
2012 # the 255/256 boundary, so doesn't change case
2013 # (the \x{149} is one of these, but changes into 2 characters, the
2014 # first one of which doesn't cross the boundary.
2015 # the final one in each list is an above-Latin1 character whose case
2016 # does change. The code below uses its position in its list as a
2017 # marker to indicate that it, unlike the other code points above
2018 # ASCII, has a successful case change
2020 # All casing operations under locale (but not :not_characters) should
2022 if ($function =~ /^u/) {
2023 @list = ("", "a", "\xe0", "\xff", "\x{fb00}", "\x{149}", "\x{101}");
2024 $ascii_case_change_delta = -32;
2025 $above_latin1_case_change_delta = -1;
2028 @list = ("", "A", "\xC0", "\x{17F}", "\x{100}");
2029 $ascii_case_change_delta = +32;
2030 $above_latin1_case_change_delta = +1;
2032 foreach my $is_utf8_locale (0 .. 1) {
2033 foreach my $j (0 .. $#list) {
2034 my $char = $list[$j];
2036 for my $encoded_in_utf8 (0 .. 1) {
2039 if (! $is_utf8_locale) {
2040 $should_be = ($j == $#list)
2041 ? chr(ord($char) + $above_latin1_case_change_delta)
2042 : (length $char == 0 || ord($char) > 127)
2044 : chr(ord($char) + $ascii_case_change_delta);
2046 # This monstrosity is in order to avoid using an eval,
2047 # which might perturb the results
2048 $changed = ($function eq "uc")
2050 : ($function eq "ucfirst")
2052 : ($function eq "lc")
2054 : ($function eq "lcfirst")
2056 : ($function eq "fc")
2058 : die("Unexpected function \"$function\"");
2064 # For utf8-locales the case changing functions
2065 # should work just like they do outside of locale.
2066 # Can use eval here because not testing it when
2068 $should_be = eval "$function('$char')";
2069 die "Unexpected eval error $@ from 'eval \"$function('$char')\"'" if $@;
2072 use locale ':not_characters';
2073 $changed = ($function eq "uc")
2075 : ($function eq "ucfirst")
2077 : ($function eq "lc")
2079 : ($function eq "lcfirst")
2081 : ($function eq "fc")
2083 : die("Unexpected function \"$function\"");
2085 ok($changed eq $should_be,
2086 "$function(\"$char\") in C locale "
2087 . (($is_utf8_locale)
2088 ? "(use locale ':not_characters'"
2090 . (($encoded_in_utf8)
2091 ? "; encoded in utf8)"
2092 : "; not encoded in utf8)")
2093 . " should be \"$should_be\", got \"$changed\"");
2095 # Tainting shouldn't happen for use locale :not_character
2098 ? check_taint($changed)
2099 : check_taint_not($changed);
2101 # Use UTF-8 next time through the loop
2102 utf8::upgrade($char);
2109 # Give final advice.
2113 foreach ($first_locales_test_number..$final_locales_test_number) {
2115 my @f = sort keys %{ $Problem{$_} };
2116 my $f = join(" ", @f);
2117 $f =~ s/(.{50,60}) /$1\n#\t/g;
2120 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
2122 "# on your system may have errors because the locale test $_\n",
2123 "# \"$test_names{$_}\"\n",
2124 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
2128 # If your users are not using these locales you are safe for the moment,
2129 # but please report this failure first to perlbug\@perl.com using the
2130 # perlbug script (as described in the INSTALL file) so that the exact
2131 # details of the failures can be sorted out first and then your operating
2132 # system supplier can be alerted about these anomalies.
2139 # Tell which locales were okay and which were not.
2144 foreach my $l (@Locale) {
2146 if ($setlocale_failed{$l}) {
2151 ($first_locales_test_number..$final_locales_test_number)
2153 $p++ if $Problem{$t}{$l};
2156 push @s, $l if $p == 0;
2157 push @F, $l unless $p == 0;
2161 my $s = join(" ", @s);
2162 $s =~ s/(.{50,60}) /$1\n#\t/g;
2165 "# The following locales\n#\n",
2167 "# tested okay.\n#\n",
2169 print "# None of your locales were fully okay.\n";
2173 my $F = join(" ", @F);
2174 $F =~ s/(.{50,60}) /$1\n#\t/g;
2178 $details = "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2180 elsif ($debug == 1) {
2181 $details = "# For even more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=2.\n";
2185 "# The following locales\n#\n",
2187 "# had problems.\n#\n",
2190 print "# None of your locales were broken.\n";
2194 print "1..$test_num\n";