my $is_ebcdic = ord("A") == 193;
+no warnings 'locale'; # We test even weird locales; and do some scary things
+ # in ok locales
+
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
chdir 't' if -d 't';
@INC = '../lib';
unshift @INC, '.';
- require Config; import Config;
- if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
+ require './loc_tools.pl';
+ unless (locales_enabled('LC_CTYPE')) {
print "1..0\n";
exit;
}
- require './loc_tools.pl';
$| = 1;
+ require Config; import Config;
}
use strict;
-use feature 'fc';
+use feature 'fc', 'postderef';
# =1 adds debugging output; =2 increases the verbosity somewhat
my $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
sub debug {
return unless $debug;
my($mess) = join "", '# ', @_;
- chop $mess;
+ chomp $mess;
print STDERR $dumper->stringify($mess,1), "\n";
}
print "ok " . ++$test_num;
print " $message";
print "\n";
+ return ($result) ? 1 : 0;
}
# First we'll do a lot of taint checking for locales.
ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
}
+foreach my $category (qw(ALL COLLATE CTYPE MESSAGES MONETARY NUMERIC TIME)) {
+ my $short_result = locales_enabled($category);
+ ok ($short_result == 0 || $short_result == 1,
+ "Verify locales_enabled('$category') returns 0 or 1");
+ debug("locales_enabled('$category') returned '$short_result'");
+ my $long_result = locales_enabled("LC_$category");
+ if (! ok ($long_result == $short_result,
+ " and locales_enabled('LC_$category') returns "
+ . "the same value")
+ ) {
+ debug("locales_enabled('LC_$category') returned $long_result");
+ }
+}
+
"\tb\t" =~ /^m?(\s)(.*)\1$/;
check_taint_not $&, "not tainted outside 'use locale'";
;
require POSIX; import POSIX ':locale_h';
-no warnings 'locale'; # We test even weird locales;
-
my @Locale = find_locales([ &POSIX::LC_CTYPE, &POSIX::LC_NUMERIC, &POSIX::LC_ALL ]);
debug "Locales =\n";
}
else {
$result .= " " unless $prev_was_punct;
- $result .= charnames::viacode(ord $char);
+ my $name = charnames::viacode(ord $char);
+ $result .= (defined $name) ? $name : ':unknown:';
$prev_was_punct = 0;
}
}
# first). This is only done if the current locale has LC_MESSAGES
$ok14 = 1;
$ok14_5 = 1;
- if (setlocale(&POSIX::LC_MESSAGES, $Locale)) {
+ if ( locales_enabled('LC_MESSAGES')
+ && setlocale(&POSIX::LC_MESSAGES, $Locale))
+ {
foreach my $err (keys %!) {
use Errno;
$! = eval "&Errno::$err"; # Convert to strerror() output
}
$ok21 = 1;
- foreach my $err (keys %!) {
- no locale;
- use Errno;
- $! = eval "&Errno::$err"; # Convert to strerror() output
- my $strerror = "$!";
- if ("$strerror" =~ /\P{ASCII}/) {
- $ok21 = 0;
- last;
+ if (locales_enabled('LC_MESSAGES')) {
+ foreach my $err (keys %!) {
+ no locale;
+ use Errno;
+ $! = eval "&Errno::$err"; # Convert to strerror() output
+ my $strerror = "$!";
+ if ("$strerror" =~ /\P{ASCII}/) {
+ $ok21 = 0;
+ last;
+ }
}
}
if (($Okay{$test_num} || $Known_bad_locale{$test_num})
&& grep { $_ == $test_num } keys %problematical_tests)
{
- no warnings 'experimental::autoderef';
+ no warnings 'experimental::postderef';
# Don't count the known-bad failures when calculating the
# percentage that fail.
my $known_failures = (exists $Known_bad_locale{$test_num})
- ? scalar(keys $Known_bad_locale{$test_num})
+ ? scalar(keys $Known_bad_locale{$test_num}->%*)
: 0;
- my $adjusted_failures = scalar(keys $Problem{$test_num})
+ my $adjusted_failures = scalar(keys $Problem{$test_num}->%*)
- $known_failures;
# Specially handle failures where only known-bad locales fail.
if ($adjusted_failures <= 0) {
print "not ok $test_num $test_names{$test_num} # TODO fails only on ",
"known bad locales: ",
- join " ", keys $Known_bad_locale{$test_num}, "\n";
+ join " ", keys $Known_bad_locale{$test_num}->%*, "\n";
next TEST_NUM;
}
}
if ($debug) {
print "# $percent_fail% of locales (",
- scalar(keys $Problem{$test_num}),
+ scalar(keys $Problem{$test_num}->%*),
" of ",
scalar(@Locale),
") fail the above test (TODO cut-off is ",