summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/ext
diff options
context:
space:
mode:
authorMartin Pelikan <pelikan@cvs.openbsd.org>2014-07-14 07:22:08 +0000
committerMartin Pelikan <pelikan@cvs.openbsd.org>2014-07-14 07:22:08 +0000
commitafda1f50262607e949ebcbea1e8a310d6a0abc60 (patch)
tree6de8a7995f27d87e338f98f757eae51d2780d388 /gnu/usr.bin/perl/ext
parentaf5b891568cb5c7890063a6cdd63db156fb9c876 (diff)
international currency locale rules as per POSIX.1-2008
required for libc++ ok guenther afresh1
Diffstat (limited to 'gnu/usr.bin/perl/ext')
-rw-r--r--gnu/usr.bin/perl/ext/POSIX/POSIX.xs6
-rw-r--r--gnu/usr.bin/perl/ext/POSIX/lib/POSIX.pod55
-rw-r--r--gnu/usr.bin/perl/ext/POSIX/t/posix.t233
3 files changed, 239 insertions, 55 deletions
diff --git a/gnu/usr.bin/perl/ext/POSIX/POSIX.xs b/gnu/usr.bin/perl/ext/POSIX/POSIX.xs
index 745cc90c14e..fa1ff5df53c 100644
--- a/gnu/usr.bin/perl/ext/POSIX/POSIX.xs
+++ b/gnu/usr.bin/perl/ext/POSIX/POSIX.xs
@@ -505,6 +505,12 @@ const struct lconv_offset lconv_integers[] = {
{"n_sep_by_space", offsetof(struct lconv, n_sep_by_space)},
{"p_sign_posn", offsetof(struct lconv, p_sign_posn)},
{"n_sign_posn", offsetof(struct lconv, n_sign_posn)},
+ {"int_p_cs_precedes", offsetof(struct lconv, int_p_cs_precedes)},
+ {"int_p_sep_by_space", offsetof(struct lconv, int_p_sep_by_space)},
+ {"int_n_cs_precedes", offsetof(struct lconv, int_n_cs_precedes)},
+ {"int_n_sep_by_space", offsetof(struct lconv, int_n_sep_by_space)},
+ {"int_p_sign_posn", offsetof(struct lconv, int_p_sign_posn)},
+ {"int_n_sign_posn", offsetof(struct lconv, int_n_sign_posn)},
{NULL, 0}
};
diff --git a/gnu/usr.bin/perl/ext/POSIX/lib/POSIX.pod b/gnu/usr.bin/perl/ext/POSIX/lib/POSIX.pod
index f935ae05743..5271a213ae3 100644
--- a/gnu/usr.bin/perl/ext/POSIX/lib/POSIX.pod
+++ b/gnu/usr.bin/perl/ext/POSIX/lib/POSIX.pod
@@ -412,7 +412,7 @@ Retrieves the value of a configurable limit on a file or directory. This
uses file descriptors such as those obtained by calling C<POSIX::open>.
The following will determine the maximum length of the longest allowable
-pathname on the filesystem which holds C</var/foo>.
+pathname on the filesystem which holds F</var/foo>.
$fd = POSIX::open( "/var/foo", &POSIX::O_RDONLY );
$path_max = POSIX::fpathconf( $fd, &POSIX::_PC_PATH_MAX );
@@ -730,27 +730,38 @@ containing the current locale formatting values.
Here is how to query the database for the B<de> (Deutsch or German) locale.
- $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" );
- print "Locale = $loc\n";
- $lconv = POSIX::localeconv();
- print "decimal_point = ", $lconv->{decimal_point}, "\n";
- print "thousands_sep = ", $lconv->{thousands_sep}, "\n";
- print "grouping = ", $lconv->{grouping}, "\n";
- print "int_curr_symbol = ", $lconv->{int_curr_symbol}, "\n";
- print "currency_symbol = ", $lconv->{currency_symbol}, "\n";
- print "mon_decimal_point = ", $lconv->{mon_decimal_point}, "\n";
- print "mon_thousands_sep = ", $lconv->{mon_thousands_sep}, "\n";
- print "mon_grouping = ", $lconv->{mon_grouping}, "\n";
- print "positive_sign = ", $lconv->{positive_sign}, "\n";
- print "negative_sign = ", $lconv->{negative_sign}, "\n";
- print "int_frac_digits = ", $lconv->{int_frac_digits}, "\n";
- print "frac_digits = ", $lconv->{frac_digits}, "\n";
- print "p_cs_precedes = ", $lconv->{p_cs_precedes}, "\n";
- print "p_sep_by_space = ", $lconv->{p_sep_by_space}, "\n";
- print "n_cs_precedes = ", $lconv->{n_cs_precedes}, "\n";
- print "n_sep_by_space = ", $lconv->{n_sep_by_space}, "\n";
- print "p_sign_posn = ", $lconv->{p_sign_posn}, "\n";
- print "n_sign_posn = ", $lconv->{n_sign_posn}, "\n";
+ my $loc = POSIX::setlocale( &POSIX::LC_ALL, "de" );
+ print "Locale: \"$loc\"\n";
+ my $lconv = POSIX::localeconv();
+ foreach my $property (qw(
+ decimal_point
+ thousands_sep
+ grouping
+ int_curr_symbol
+ currency_symbol
+ mon_decimal_point
+ mon_thousands_sep
+ mon_grouping
+ positive_sign
+ negative_sign
+ int_frac_digits
+ frac_digits
+ p_cs_precedes
+ p_sep_by_space
+ n_cs_precedes
+ n_sep_by_space
+ p_sign_posn
+ n_sign_posn
+ int_p_cs_precedes
+ int_p_sep_by_space
+ int_n_cs_precedes
+ int_n_sep_by_space
+ int_p_sign_posn
+ int_n_sign_posn
+ ))
+ {
+ printf qq(%s: "%s",\n), $property, $lconv->{$property};
+ }
=item localtime
diff --git a/gnu/usr.bin/perl/ext/POSIX/t/posix.t b/gnu/usr.bin/perl/ext/POSIX/t/posix.t
index 8f31ada848e..d7064470028 100644
--- a/gnu/usr.bin/perl/ext/POSIX/t/posix.t
+++ b/gnu/usr.bin/perl/ext/POSIX/t/posix.t
@@ -1,8 +1,6 @@
#!./perl
BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
require Config; import Config;
if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
print "1..0\n";
@@ -10,28 +8,52 @@ BEGIN {
}
}
-require "./test.pl";
-plan(tests => 39);
-
+use Test::More tests => 109;
use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
- errno);
+ errno localeconv dup dup2 lseek access);
use strict 'subs';
+sub next_test {
+ my $builder = Test::More->builder;
+ $builder->current_test($builder->current_test() + 1);
+}
+
$| = 1;
$Is_W32 = $^O eq 'MSWin32';
$Is_Dos = $^O eq 'dos';
-$Is_MPE = $^O eq 'mpeix';
$Is_MacOS = $^O eq 'MacOS';
$Is_VMS = $^O eq 'VMS';
$Is_OS2 = $^O eq 'os2';
$Is_UWin = $^O eq 'uwin';
$Is_OS390 = $^O eq 'os390';
-ok( $testfd = open("TEST", O_RDONLY, 0), 'O_RDONLY with open' );
+my $vms_unix_rpt = 0;
+my $vms_efs = 0;
+my $unix_mode = 1;
+
+if ($Is_VMS) {
+ $unix_mode = 0;
+ if (eval 'require VMS::Feature') {
+ $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
+ $vms_efs = VMS::Feature::current("efs_charset");
+ } else {
+ my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
+ my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
+ $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
+ $vms_efs = $efs_charset =~ /^[ET1]/i;
+ }
+
+ # Traditional VMS mode only if VMS is not in UNIX compatible mode.
+ $unix_mode = ($vms_efs && $vms_unix_rpt);
+
+}
+
+my $testfd = open("Makefile.PL", O_RDONLY, 0);
+like($testfd, qr/\A\d+\z/, 'O_RDONLY with open');
read($testfd, $buffer, 4) if $testfd > 2;
-is( $buffer, "#!./", ' with read' );
+is( $buffer, "# Ex", ' with read' );
TODO:
{
@@ -41,22 +63,22 @@ TODO:
is( $buffer[1], "perl\n", ' read to array element' );
}
-write(1,"ok 4\nnot ok 4\n", 5);
-next_test();
+my $test = next_test();
+write(1,"ok $test\nnot ok $test\n", 5);
SKIP: {
skip("no pipe() support on DOS", 2) if $Is_Dos;
@fds = POSIX::pipe();
- ok( $fds[0] > $testfd, 'POSIX::pipe' );
+ cmp_ok($fds[0], '>', $testfd, 'POSIX::pipe');
CORE::open($reader = \*READER, "<&=".$fds[0]);
CORE::open($writer = \*WRITER, ">&=".$fds[1]);
- print $writer "ok 6\n";
+ my $test = next_test();
+ print $writer "ok $test\n";
close $writer;
print <$reader>;
close $reader;
- next_test();
}
SKIP: {
@@ -76,13 +98,28 @@ SKIP: {
my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
sigaction(&SIGHUP, $action);
$SIG{'INT'} = 'SigINT';
- kill 'HUP', $$;
+
+ # At least OpenBSD/i386 3.3 is okay, as is NetBSD 1.5.
+ # But not NetBSD 1.6 & 1.6.1: the test makes perl crash.
+ # So the kill() must not be done with this config in order to
+ # finish the test.
+ # For others (darwin & freebsd), let the test fail without crashing.
+ # the test passes at least from freebsd 8.1
+ my $todo = $^O eq 'netbsd' && $Config{osvers}=~/^1\.6/;
+ my $why_todo = "# TODO $^O $Config{osvers} seems to lose blocked signals";
+ if (!$todo) {
+ kill 'HUP', $$;
+ } else {
+ print "not ok 9 - sigaction SIGHUP ",$why_todo,"\n";
+ print "not ok 10 - sig mask delayed SIGINT ",$why_todo,"\n";
+ }
sleep 1;
- printf "%s 11 - masked SIGINT received %s\n",
- $sigint_called ? "ok" : "not ok",
- $^O eq 'darwin' ? "# TODO Darwin seems to loose blocked signals"
- : '';
+ $todo = 1 if ($^O eq 'freebsd' && $Config{osvers} < 8)
+ || ($^O eq 'darwin' && $Config{osvers} < '6.6');
+ printf "%s 11 - masked SIGINT received %s\n",
+ $sigint_called ? "ok" : "not ok",
+ $todo ? $why_todo : '';
print "ok 12 - signal masks successful\n";
@@ -104,35 +141,33 @@ SKIP: {
}
SKIP: {
- skip("_POSIX_OPEN_MAX is inaccurate on MPE", 1) if $Is_MPE;
skip("_POSIX_OPEN_MAX undefined ($fds[1])", 1) unless &_POSIX_OPEN_MAX;
- ok( &_POSIX_OPEN_MAX >= 16, "The minimum allowed values according to susv2" );
+ cmp_ok(&_POSIX_OPEN_MAX, '>=', 16,
+ "The minimum allowed values according to susv2" );
}
my $pat;
-if ($Is_MacOS) {
- $pat = qr/:t:$/;
-}
-elsif ( $Is_VMS ) {
- $pat = qr/\.T]/i;
+if ( $unix_mode ) {
+ $pat = qr#[\\/]POSIX$#i;
}
else {
- $pat = qr#[\\/]t$#i;
+ $pat = qr/\.POSIX]/i;
}
like( getcwd(), qr/$pat/, 'getcwd' );
# Check string conversion functions.
SKIP: {
- skip("strtod() not present", 1) unless $Config{d_strtod};
+ skip("strtod() not present", 2) unless $Config{d_strtod};
$lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
# we're just checking that strtod works, not how accurate it is
($n, $x) = &POSIX::strtod('3.14159_OR_SO');
- ok((abs("3.14159" - $n) < 1e-6) && ($x == 6), 'strtod works');
+ cmp_ok(abs("3.14159" - $n), '<', 1e-6, 'strtod works');
+ is($x, 6, 'strtod works');
&POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
}
@@ -154,14 +189,14 @@ SKIP: {
}
# Pick up whether we're really able to dynamically load everything.
-ok( &POSIX::acos(1.0) == 0.0, 'dynamic loading' );
+cmp_ok(&POSIX::acos(1.0), '==', 0.0, 'dynamic loading');
# This can coredump if struct tm has a timezone field and we
# didn't detect it. If this fails, try adding
# -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
# See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl
-print POSIX::strftime("ok 21 # %H:%M, on %D\n", localtime());
-next_test();
+$test = next_test();
+print POSIX::strftime("ok $test # %H:%M, on %m/%d/%y\n", localtime());
# If that worked, validate the mini_mktime() routine's normalisation of
# input fields to strftime().
@@ -173,7 +208,14 @@ sub try_strftime {
$lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
try_strftime("Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96);
-try_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
+SKIP: {
+ skip("VC++ 8 and Vista's CRTs regard 60 seconds as an invalid parameter", 1)
+ if ($Is_W32 and (($Config{cc} eq 'cl' and
+ $Config{ccversion} =~ /^(\d+)/ and $1 >= 14) or
+ (Win32::GetOSVersion())[1] >= 6));
+
+ try_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
+}
try_strftime("Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96);
try_strftime("Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99);
try_strftime("Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
@@ -181,6 +223,21 @@ try_strftime("Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
try_strftime("Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
try_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
+
+{ # rt 72232
+
+ # Std C/POSIX allows day/month to be negative and requires that
+ # wday/yday be adjusted as needed
+ # previously mini_mktime() would allow yday to dominate if mday and
+ # month were both non-positive
+ # check that yday doesn't dominate
+ try_strftime("Thu Dec 30 00:00:00 1999 364", 0,0,0, -1,0,100);
+ try_strftime("Thu Dec 30 00:00:00 1999 364", 0,0,0, -1,0,100,-1,10);
+ # it would also allow a positive wday to override the calculated value
+ # check that wday is recalculated too
+ try_strftime("Thu Dec 30 00:00:00 1999 364", 0,0,0, -1,0,100,0,10);
+}
+
&POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
{
@@ -223,6 +280,116 @@ is ($result, undef, "fgets should fail");
like ($@, qr/^Use method IO::Handle::gets\(\) instead/,
"check its redef message");
+# Simplistic tests for the isXXX() functions (bug #16799)
+ok( POSIX::isalnum('1'), 'isalnum' );
+ok(!POSIX::isalnum('*'), 'isalnum' );
+ok( POSIX::isalpha('f'), 'isalpha' );
+ok(!POSIX::isalpha('7'), 'isalpha' );
+ok( POSIX::iscntrl("\cA"),'iscntrl' );
+ok(!POSIX::iscntrl("A"), 'iscntrl' );
+ok( POSIX::isdigit('1'), 'isdigit' );
+ok(!POSIX::isdigit('z'), 'isdigit' );
+ok( POSIX::isgraph('@'), 'isgraph' );
+ok(!POSIX::isgraph(' '), 'isgraph' );
+ok( POSIX::islower('l'), 'islower' );
+ok(!POSIX::islower('L'), 'islower' );
+ok( POSIX::isupper('U'), 'isupper' );
+ok(!POSIX::isupper('u'), 'isupper' );
+ok( POSIX::isprint('$'), 'isprint' );
+ok(!POSIX::isprint("\n"), 'isprint' );
+ok( POSIX::ispunct('%'), 'ispunct' );
+ok(!POSIX::ispunct('u'), 'ispunct' );
+ok( POSIX::isspace("\t"), 'isspace' );
+ok(!POSIX::isspace('_'), 'isspace' );
+ok( POSIX::isxdigit('f'), 'isxdigit' );
+ok(!POSIX::isxdigit('g'), 'isxdigit' );
+# metaphysical question : what should be returned for an empty string ?
+# anyway this shouldn't segfault (bug #24554)
+ok( POSIX::isalnum(''), 'isalnum empty string' );
+ok( POSIX::isalnum(undef),'isalnum undef' );
+# those functions should stringify their arguments
+ok(!POSIX::isalpha([]), 'isalpha []' );
+ok( POSIX::isprint([]), 'isprint []' );
+
+eval { use strict; POSIX->import("S_ISBLK"); my $x = S_ISBLK };
+unlike( $@, qr/Can't use string .* as a symbol ref/, "Can import autoloaded constants" );
+
+SKIP: {
+ skip("localeconv() not present", 20) unless $Config{d_locconv};
+ my $conv = localeconv;
+ is(ref $conv, 'HASH', 'localconv returns a hash reference');
+
+ foreach (qw(decimal_point thousands_sep grouping int_curr_symbol
+ currency_symbol mon_decimal_point mon_thousands_sep
+ mon_grouping positive_sign negative_sign)) {
+ SKIP: {
+ skip("localeconv has no result for $_", 1)
+ unless exists $conv->{$_};
+ unlike(delete $conv->{$_}, qr/\A\z/,
+ "localeconv returned a non-empty string for $_");
+ }
+ }
+
+ foreach (qw(int_frac_digits frac_digits p_cs_precedes p_sep_by_space
+ n_cs_precedes n_sep_by_space p_sign_posn n_sign_posn
+ int_p_cs_precedes int_p_sep_by_space int_n_cs_precedes
+ int_n_sep_by_space int_p_sign_posn int_n_sign_posn)) {
+ SKIP: {
+ skip("localeconv has no result for $_", 1)
+ unless exists $conv->{$_};
+ like(delete $conv->{$_}, qr/\A-?\d+\z/,
+ "localeconv returned an integer for $_");
+ }
+ }
+ is_deeply([%$conv], [], 'no unexpected keys returned by localeconv');
+}
+
+my $fd1 = open("Makefile.PL", O_RDONLY, 0);
+like($fd1, qr/\A\d+\z/, 'O_RDONLY with open');
+cmp_ok($fd1, '>', $testfd);
+my $fd2 = dup($fd1);
+like($fd2, qr/\A\d+\z/, 'dup');
+cmp_ok($fd2, '>', $fd1);
+is(POSIX::close($fd1), '0 but true', 'close');
+is(POSIX::close($testfd), '0 but true', 'close');
+$! = 0;
+undef $buffer;
+is(read($fd1, $buffer, 4), undef, 'read on closed file handle fails');
+cmp_ok($!, '==', POSIX::EBADF);
+undef $buffer;
+read($fd2, $buffer, 4) if $fd2 > 2;
+is($buffer, "# Ex", 'read');
+# The descriptor $testfd was using is now free, and is lower than that which
+# $fd1 was using. Hence if dup2() behaves as dup(), we'll know :-)
+{
+ $testfd = dup2($fd2, $fd1);
+ is($testfd, $fd1, 'dup2');
+ undef $buffer;
+ read($testfd, $buffer, 4) if $testfd > 2;
+ is($buffer, 'pect', 'read');
+ is(lseek($testfd, 0, 0), 0, 'lseek back');
+ # The two should share file position:
+ undef $buffer;
+ read($fd2, $buffer, 4) if $fd2 > 2;
+ is($buffer, "# Ex", 'read');
+}
+
+# The FreeBSD man page warns:
+# The access() system call is a potential security hole due to race
+# conditions and should never be used.
+is(access('Makefile.PL', POSIX::F_OK), '0 but true', 'access');
+is(access('Makefile.PL', POSIX::R_OK), '0 but true', 'access');
+$! = 0;
+is(access('no such file', POSIX::F_OK), undef, 'access on missing file');
+cmp_ok($!, '==', POSIX::ENOENT);
+is(access('Makefile.PL/nonsense', POSIX::F_OK), undef,
+ 'access on not-a-directory');
+SKIP: {
+ skip("$^O is insufficiently POSIX", 1)
+ if $Is_W32 || $Is_VMS;
+ cmp_ok($!, '==', POSIX::ENOTDIR);
+}
+
# Check that output is not flushed by _exit. This test should be last
# in the file, and is not counted in the total number of tests.
if ($^O eq 'vos') {