}
require "./test.pl";
-plan(tests => 31);
+plan(tests => 66);
use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
$Is_OS390 = $^O eq 'os390';
ok( $testfd = open("TEST", O_RDONLY, 0), 'O_RDONLY with open' );
-read($testfd, $buffer, 9) if $testfd > 2;
-is( $buffer, "#!./perl\n", ' with read' );
+read($testfd, $buffer, 4) if $testfd > 2;
+is( $buffer, "#!./", ' with read' );
-write(1,"ok 3\nnot ok 3\n", 5);
+TODO:
+{
+ local $TODO = "read to array element not working";
+
+ read($testfd, $buffer[1], 5) if $testfd > 2;
+ is( $buffer[1], "perl\n", ' read to array element' );
+}
+
+write(1,"ok 4\nnot ok 4\n", 5);
next_test();
SKIP: {
CORE::open($reader = \*READER, "<&=".$fds[0]);
CORE::open($writer = \*WRITER, ">&=".$fds[1]);
- print $writer "ok 5\n";
+ print $writer "ok 6\n";
close $writer;
print <$reader>;
close $reader;
$sigset->delset(1);
ok(! $sigset->ismember(1), 'POSIX::SigSet->delset' );
ok( $sigset->ismember(3), 'POSIX::SigSet->ismember' );
-
+
SKIP: {
skip("no kill() support on Mac OS", 4) if $Is_MacOS;
+ my $sigint_called = 0;
+
my $mask = new POSIX::SigSet &SIGINT;
my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
sigaction(&SIGHUP, $action);
$SIG{'INT'} = 'SigINT';
kill 'HUP', $$;
sleep 1;
- print "ok 11 - signal masks successful\n";
+
+ printf "%s 11 - masked SIGINT received %s\n",
+ $sigint_called ? "ok" : "not ok",
+ $^O eq 'darwin' ? "# TODO Darwin seems to loose blocked signals"
+ : '';
+
+ print "ok 12 - signal masks successful\n";
sub SigHUP {
- print "ok 8 - sigaction SIGHUP\n";
+ print "ok 9 - sigaction SIGHUP\n";
kill 'INT', $$;
sleep 2;
- print "ok 9 - sig mask delayed SIGINT\n";
+ print "ok 10 - sig mask delayed SIGINT\n";
}
sub SigINT {
- print "ok 10 - masked SIGINT received\n";
+ $sigint_called++;
}
# The order of the above tests is very important, so
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 > $fds[1], '_POSIX_OPEN_MAX' );
+ ok( &_POSIX_OPEN_MAX >= 16, "The minimum allowed values according to susv2" );
+
}
my $pat;
# 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 18 # %H:%M, on %D\n", localtime());
+print POSIX::strftime("ok 21 # %H:%M, on %D\n", localtime());
next_test();
# If that worked, validate the mini_mktime() routine's normalisation of
sub try_strftime {
my $expect = shift;
my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_);
- is($got, $expect, 'validating mini_mktime() and strftime()');
+ is($got, $expect, "validating mini_mktime() and strftime(): $expect");
}
$lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
&POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
+SKIP: {
+ # XXX wait for smokers to see which OSs else to skip
+ skip("No mktime and/or tm_gmtoff", 5)
+ if !$Config{d_mktime} || !$Config{d_tm_tm_gmtoff} || !$Config{d_tm_tm_zone};
+ local $ENV{TZ} = "Europe/Berlin";
+
+ # May fail for ancient FreeBSD versions.
+ # %z is not included in POSIX, but valid on Linux and FreeBSD.
+ foreach $def ([1000,'Sun Sep 9 03:46:40 2001 +0200 CEST'],
+ [900, 'Thu Jul 9 18:00:00 1998 +0200 CEST'],
+ [800, 'Tue May 9 08:13:20 1995 +0200 CEST'],
+ [700, 'Sat Mar 7 21:26:40 1992 +0100 CET'],
+ [600, 'Thu Jan 5 11:40:00 1989 +0100 CET'],
+ ) {
+ my($t, $expected) = @$def;
+ my @tm = localtime($t*1000000);
+ is(strftime("%c %z %Z",@tm), $expected, "validating zone setting: $expected");
+ }
+}
+
{
for my $test (0, 1) {
$! = 0;
my $foo = $!;
my $errno = POSIX::errno();
- local $TODO;
- $TODO = 'POSIX::errno() munged by autoloading on VMS'
- if $Is_VMS && $test == 0;
-
# Force numeric context.
is( $errno + 0, $foo + 0, 'autoloading and errno() mix' );
}
}
-$| = 0;
-# The following line assumes buffered output, which may be not true:
-print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 ||
+SKIP: {
+ skip("no kill() support on Mac OS", 1) if $Is_MacOS;
+ is (eval "kill 0", 0, "check we have CORE::kill")
+ or print "\$\@ is " . _qq($@) . "\n";
+}
+
+# Check that we can import the POSIX kill routine
+POSIX->import ('kill');
+my $result = eval "kill 0";
+is ($result, undef, "we should now have POSIX::kill");
+# Check usage.
+like ($@, qr/^Usage: POSIX::kill\(pid, sig\)/, "check its usage message");
+
+# Check unimplemented.
+$result = eval {POSIX::offsetof};
+is ($result, undef, "offsetof should fail");
+like ($@, qr/^Unimplemented: POSIX::offsetof\(\) is C-specific/,
+ "check its unimplemented message");
+
+# Check reimplemented.
+$result = eval {POSIX::fgets};
+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' );
+
+# 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') {
+ print "# TODO - hit VOS bug posix-885 - _exit flushes output buffers.\n";
+} else {
+ $| = 0;
+ # The following line assumes buffered output, which may be not true:
+ print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 ||
$Is_VMS ||
(defined $ENV{PERLIO} &&
$ENV{PERLIO} eq 'unix' &&
$Config::Config{useperlio}));
-_exit(0);
+ _exit(0);
+}