diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-10-27 22:25:41 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-10-27 22:25:41 +0000 |
commit | d85c2f57f17d991a6ca78d3e1c9f3308a2bbb271 (patch) | |
tree | 8c9a359433cbb3488b0a848e99bd869c76295dfd /gnu/usr.bin/perl/t/io | |
parent | 74cfb115ac810480c0000dc742b20383c1578bac (diff) |
Resolve conflicts, remove old files, merge local changes
Diffstat (limited to 'gnu/usr.bin/perl/t/io')
-rw-r--r-- | gnu/usr.bin/perl/t/io/argv.t | 147 | ||||
-rw-r--r-- | gnu/usr.bin/perl/t/io/dup.t | 57 | ||||
-rw-r--r-- | gnu/usr.bin/perl/t/io/fs.t | 431 | ||||
-rw-r--r-- | gnu/usr.bin/perl/t/io/inplace.t | 12 | ||||
-rw-r--r-- | gnu/usr.bin/perl/t/io/open.t | 392 | ||||
-rw-r--r-- | gnu/usr.bin/perl/t/io/pipe.t | 264 | ||||
-rw-r--r-- | gnu/usr.bin/perl/t/io/tell.t | 9 |
7 files changed, 736 insertions, 576 deletions
diff --git a/gnu/usr.bin/perl/t/io/argv.t b/gnu/usr.bin/perl/t/io/argv.t index 2b8f23b426e..f2f3245b10f 100644 --- a/gnu/usr.bin/perl/t/io/argv.t +++ b/gnu/usr.bin/perl/t/io/argv.t @@ -5,123 +5,128 @@ BEGIN { @INC = '../lib'; } -print "1..21\n"; +require "./test.pl"; + +plan(tests => 22); use File::Spec; my $devnull = File::Spec->devnull; -open(try, '>Io_argv1.tmp') || (die "Can't open temp file: $!"); -print try "a line\n"; -close try; +open(TRY, '>Io_argv1.tmp') || (die "Can't open temp file: $!"); +print TRY "a line\n"; +close TRY or die "Could not close: $!"; -if ($^O eq 'MSWin32') { - $x = `.\\perl -e "while (<>) {print \$.,\$_;}" Io_argv1.tmp Io_argv1.tmp`; -} -else { - $x = `./perl -e 'while (<>) {print \$.,\$_;}' Io_argv1.tmp Io_argv1.tmp`; -} -if ($x eq "1a line\n2a line\n") {print "ok 1\n";} else {print "not ok 1\n";} +$x = runperl( + prog => 'while (<>) { print $., $_; }', + args => [ 'Io_argv1.tmp', 'Io_argv1.tmp' ], +); +is($x, "1a line\n2a line\n", '<> from two files'); -if ($^O eq 'MSWin32') { - $x = `.\\perl -le "print 'foo'" | .\\perl -e "while (<>) {print \$_;}" Io_argv1.tmp -`; -} -else { - $x = `echo foo|./perl -e 'while (<>) {print $_;}' Io_argv1.tmp -`; -} -if ($x eq "a line\nfoo\n") {print "ok 2\n";} else {print "not ok 2\n";} - -if ($^O eq 'MSWin32') { - $x = `.\\perl -le "print 'foo'" |.\\perl -e "while (<>) {print \$_;}"`; -} -else { - $x = `echo foo|./perl -e 'while (<>) {print $_;}'`; +{ + $x = runperl( + prog => 'while (<>) { print $_; }', + stdin => "foo\n", + args => [ 'Io_argv1.tmp', '-' ], + ); + is($x, "a line\nfoo\n", ' from a file and STDIN'); + + $x = runperl( + prog => 'while (<>) { print $_; }', + stdin => "foo\n", + ); + is($x, "foo\n", ' from just STDIN'); } -if ($x eq "foo\n") {print "ok 3\n";} else {print "not ok 3 :$x:\n";} @ARGV = ('Io_argv1.tmp', 'Io_argv1.tmp', $devnull, 'Io_argv1.tmp'); while (<>) { $y .= $. . $_; if (eof()) { - if ($. == 3) {print "ok 4\n";} else {print "not ok 4\n";} + is($., 3, '$. counts <>'); } } -if ($y eq "1a line\n2a line\n3a line\n") - {print "ok 5\n";} -else - {print "not ok 5\n";} +is($y, "1a line\n2a line\n3a line\n", '<> from @ARGV'); + -open(try, '>Io_argv1.tmp') or die "Can't open temp file: $!"; -close try; -open(try, '>Io_argv2.tmp') or die "Can't open temp file: $!"; -close try; +open(TRY, '>Io_argv1.tmp') or die "Can't open temp file: $!"; +close TRY or die "Could not close: $!"; +open(TRY, '>Io_argv2.tmp') or die "Can't open temp file: $!"; +close TRY or die "Could not close: $!"; @ARGV = ('Io_argv1.tmp', 'Io_argv2.tmp'); -$^I = '.bak'; +$^I = '_bak'; # not .bak which confuses VMS $/ = undef; my $i = 6; while (<>) { s/^/ok $i\n/; ++$i; print; + next_test(); } -open(try, '<Io_argv1.tmp') or die "Can't open temp file: $!"; -print while <try>; -open(try, '<Io_argv2.tmp') or die "Can't open temp file: $!"; -print while <try>; -close try; +open(TRY, '<Io_argv1.tmp') or die "Can't open temp file: $!"; +print while <TRY>; +open(TRY, '<Io_argv2.tmp') or die "Can't open temp file: $!"; +print while <TRY>; +close TRY or die "Could not close: $!"; undef $^I; -eof try or print 'not '; -print "ok 8\n"; +ok( eof TRY ); -eof NEVEROPENED or print 'not '; -print "ok 9\n"; +ok( eof NEVEROPENED, 'eof() true on unopened filehandle' ); open STDIN, 'Io_argv1.tmp' or die $!; @ARGV = (); -!eof() or print 'not '; -print "ok 10\n"; +ok( !eof(), 'STDIN has something' ); -<> eq "ok 6\n" or print 'not '; -print "ok 11\n"; +is( <>, "ok 6\n" ); open STDIN, $devnull or die $!; @ARGV = (); -eof() or print 'not '; -print "ok 12\n"; +ok( eof(), 'eof() true with empty @ARGV' ); @ARGV = ('Io_argv1.tmp'); -!eof() or print 'not '; -print "ok 13\n"; +ok( !eof() ); @ARGV = ($devnull, $devnull); -!eof() or print 'not '; -print "ok 14\n"; +ok( !eof() ); close ARGV or die $!; -eof() or print 'not '; -print "ok 15\n"; +ok( eof(), 'eof() true after closing ARGV' ); { local $/; - open F, 'Io_argv1.tmp' or die; + open F, 'Io_argv1.tmp' or die "Could not open Io_argv1.tmp: $!"; <F>; # set $. = 1 - print "not " if defined(<F>); # should hit eof - print "ok 16\n"; + is( <F>, undef ); + open F, $devnull or die; - print "not " unless defined(<F>); - print "ok 17\n"; - print "not " if defined(<F>); - print "ok 18\n"; - print "not " if defined(<F>); - print "ok 19\n"; + ok( defined(<F>) ); + + is( <F>, undef ); + is( <F>, undef ); + open F, $devnull or die; # restart cycle again - print "not " unless defined(<F>); - print "ok 20\n"; - print "not " if defined(<F>); - print "ok 21\n"; - close F; + ok( defined(<F>) ); + is( <F>, undef ); + close F or die "Could not close: $!"; +} + +# This used to dump core +fresh_perl_is( <<'**PROG**', "foobar", {}, "ARGV aliasing and eof()" ); +open OUT, ">Io_argv3.tmp" or die "Can't open temp file: $!"; +print OUT "foo"; +close OUT; +open IN, "Io_argv3.tmp" or die "Can't open temp file: $!"; +*ARGV = *IN; +while (<>) { + print; + print "bar" if eof(); } +close IN; +unlink "Io_argv3.tmp"; +**PROG** -END { unlink 'Io_argv1.tmp', 'Io_argv1.tmp.bak', 'Io_argv2.tmp', 'Io_argv2.tmp.bak' } +END { + unlink 'Io_argv1.tmp', 'Io_argv1.tmp_bak', + 'Io_argv2.tmp', 'Io_argv2.tmp_bak', 'Io_argv3.tmp'; +} diff --git a/gnu/usr.bin/perl/t/io/dup.t b/gnu/usr.bin/perl/t/io/dup.t index af13d4d8f7e..6e7d1218485 100644 --- a/gnu/usr.bin/perl/t/io/dup.t +++ b/gnu/usr.bin/perl/t/io/dup.t @@ -1,15 +1,18 @@ #!./perl -# $RCSfile: dup.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:27 $ - -print "1..6\n"; +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} +my $test = 1; +print "1..8\n"; print "ok 1\n"; -open(dupout,">&STDOUT"); -open(duperr,">&STDERR"); +open(DUPOUT,">&STDOUT"); +open(DUPERR,">&STDERR"); -open(STDOUT,">Io.dup") || die "Can't open stdout"; +open(STDOUT,">Io.dup") || die "Can't open stdout"; open(STDERR,">&STDOUT") || die "Can't open stderr"; select(STDERR); $| = 1; @@ -17,24 +20,42 @@ select(STDOUT); $| = 1; print STDOUT "ok 2\n"; print STDERR "ok 3\n"; -if ($^O eq 'MSWin32') { - print `echo ok 4`; - print `echo ok 5 1>&2`; # does this work? + +# Since some systems don't have echo, we use Perl. +$echo = qq{$^X -le "print q(ok %d)"}; + +$cmd = sprintf $echo, 4; +print `$cmd`; + +$cmd = sprintf "$echo 1>&2", 5; +$cmd = sprintf $echo, 5 if $^O eq 'MacOS'; # don't know if we can do this ... +print `$cmd`; + +# KNOWN BUG system() does not honor STDOUT redirections on VMS. +if( $^O eq 'VMS' ) { + print "not ok $_ # TODO system() not honoring STDOUT redirect on VMS\n" + for 6..7; } else { - system 'echo ok 4'; - system 'echo ok 5 1>&2'; + system sprintf $echo, 6; + if ($^O eq 'MacOS') { + system sprintf $echo, 7; + } + else { + system sprintf "$echo 1>&2", 7; + } } -close(STDOUT); -close(STDERR); +close(STDOUT) or die "Could not close: $!"; +close(STDERR) or die "Could not close: $!"; -open(STDOUT,">&dupout"); -open(STDERR,">&duperr"); +open(STDOUT,">&DUPOUT") or die "Could not open: $!"; +open(STDERR,">&DUPERR") or die "Could not open: $!"; -if ($^O eq 'MSWin32') { print `type Io.dup` } -else { system 'cat Io.dup' } +if (($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'VMS')) { print `type Io.dup` } +elsif ($^O eq 'MacOS') { system 'catenate Io.dup' } +else { system 'cat Io.dup' } unlink 'Io.dup'; -print STDOUT "ok 6\n"; +print STDOUT "ok 8\n"; diff --git a/gnu/usr.bin/perl/t/io/fs.t b/gnu/usr.bin/perl/t/io/fs.t index 8170b33ecce..7535e4ebfd6 100644 --- a/gnu/usr.bin/perl/t/io/fs.t +++ b/gnu/usr.bin/perl/t/io/fs.t @@ -1,210 +1,353 @@ #!./perl -# $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $ - BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + require "./test.pl"; } use Config; +use File::Spec::Functions; + +my $Is_MacOS = ($^O eq 'MacOS'); +my $Is_VMSish = ($^O eq 'VMS'); + +if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { + $wd = `cd`; +} elsif ($^O eq 'VMS') { + $wd = `show default`; +} else { + $wd = `pwd`; +} +chomp($wd); -$Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'dos' or - $^O eq 'os2' or $^O eq 'mint'); +my $has_link = $Config{d_link}; +my $accurate_timestamps = + !($^O eq 'MSWin32' || $^O eq 'NetWare' || + $^O eq 'dos' || $^O eq 'os2' || + $^O eq 'mint' || $^O eq 'cygwin' || + $^O eq 'amigaos' || $wd =~ m#$Config{afsroot}/# || + $Is_MacOS + ); if (defined &Win32::IsWinNT && Win32::IsWinNT()) { - $Is_Dosish = '' if Win32::FsType() eq 'NTFS'; + if (Win32::FsType() eq 'NTFS') { + $has_link = 1; + $accurate_timestamps = 1; + } } -print "1..29\n"; +my $needs_fh_reopen = + $^O eq 'dos' + # Not needed on HPFS, but needed on HPFS386 ?! + || $^O eq 'os2'; + +$needs_fh_reopen = 1 if (defined &Win32::IsWin95 && Win32::IsWin95()); + +my $skip_mode_checks = + $^O eq 'cygwin' && $ENV{CYGWIN} !~ /ntsec/; + +plan tests => 32; + + +if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { + `rmdir /s /q tmp 2>nul`; + `mkdir tmp`; +} +elsif ($^O eq 'VMS') { + `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`; + `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`; + `create/directory [.tmp]`; +} +elsif ($Is_MacOS) { + rmdir "tmp"; mkdir "tmp"; +} +else { + `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; +} -$wd = (($^O eq 'MSWin32') ? `cd` : `pwd`); -chop($wd); +chdir catdir(curdir(), 'tmp'); -if ($^O eq 'MSWin32') { `rmdir /s /q tmp 2>nul`; `mkdir tmp`; } -else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; } -chdir './tmp'; `/bin/rm -rf a b c x` if -x '/bin/rm'; umask(022); -if ($^O eq 'MSWin32') { print "ok 1 # skipped: bogus umask()\n"; } -elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";} +SKIP: { + skip "bogus umask", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'epoc') || $Is_MacOS; + + is((umask(0)&0777), 022, 'umask'), +} + open(fh,'>x') || die "Can't create x"; close(fh); open(fh,'>a') || die "Can't create a"; close(fh); -if ($Is_Dosish) {print "ok 2 # skipped: no link\n";} -elsif (eval {link('a','b')}) {print "ok 2\n";} -else {print "not ok 2\n";} +my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks); -if ($Is_Dosish) {print "ok 3 # skipped: no link\n";} -elsif (eval {link('b','c')}) {print "ok 3\n";} -else {print "not ok 3\n";} +SKIP: { + skip("no link", 4) unless $has_link; -($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('c'); + ok(link('a','b'), "link a b"); + ok(link('b','c'), "link b c"); -if ($Config{dont_use_nlink} || $Is_Dosish) - {print "ok 4 # skipped: no link\n";} -elsif ($nlink == 3) - {print "ok 4\n";} -else {print "not ok 4\n";} + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('c'); -if ($^O eq 'amigaos' || $Is_Dosish) - {print "ok 5 # skipped: no link\n";} -elsif (($mode & 0777) == 0666) - {print "ok 5\n";} -else {print "not ok 5\n";} + SKIP: { + skip "no nlink", 1 if $Config{dont_use_nlink}; -$newmode = $^O eq 'MSWin32' ? 0444 : 0777; -if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";} + is($nlink, 3, "link count of triply-linked file"); + } -($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('c'); -if ($Is_Dosish) {print "ok 7 # skipped: no link\n";} -elsif (($mode & 0777) == $newmode) {print "ok 7\n";} -else {print "not ok 7\n";} + SKIP: { + skip "hard links not that hard in $^O", 1 if $^O eq 'amigaos'; + skip "no mode checks", 1 if $skip_mode_checks; + +# if ($^O eq 'cygwin') { # new files on cygwin get rwx instead of rw- +# is($mode & 0777, 0777, "mode of triply-linked file"); +# } else { + is($mode & 0777, 0666, "mode of triply-linked file"); +# } + } +} + +$newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777; -$newmode = 0700; -if ($^O eq 'MSWin32') { +is(chmod($newmode,'a'), 1, "chmod succeeding"); + +SKIP: { + skip("no link", 7) unless $has_link; + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('c'); + + SKIP: { + skip "no mode checks", 1 if $skip_mode_checks; + + is($mode & 0777, $newmode, "chmod going through"); + } + + $newmode = 0700; chmod 0444, 'x'; $newmode = 0666; + + is(chmod($newmode,'c','x'), 2, "chmod two files"); + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('c'); + + SKIP: { + skip "no mode checks", 1 if $skip_mode_checks; + + is($mode & 0777, $newmode, "chmod going through to c"); + } + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('x'); + + SKIP: { + skip "no mode checks", 1 if $skip_mode_checks; + + is($mode & 0777, $newmode, "chmod going through to x"); + } + + is(unlink('b','x'), 2, "unlink two files"); + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('b'); + + is($ino, undef, "ino of removed file b should be undef"); + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('x'); + + is($ino, undef, "ino of removed file x should be undef"); } -if ($Is_Dosish) {print "ok 8 # skipped: no link\n";} -elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";} -else {print "not ok 8\n";} +is(rename('a','b'), 1, "rename a b"); ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('c'); -if ($Is_Dosish) {print "ok 9 # skipped: no link\n";} -elsif (($mode & 0777) == $newmode) {print "ok 9\n";} -else {print "not ok 9\n";} + $blksize,$blocks) = stat('a'); -($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('x'); -if ($Is_Dosish) {print "ok 10 # skipped: no link\n";} -elsif (($mode & 0777) == $newmode) {print "ok 10\n";} -else {print "not ok 10\n";} - -if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; } -elsif ((unlink 'b','x') == 2) {print "ok 11\n";} -else {print "not ok 11\n";} -($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('b'); -if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";} -($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('x'); -if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";} +is($ino, undef, "ino of renamed file a should be undef"); -if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";} -($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, - $blksize,$blocks) = stat('a'); -if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";} -$delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem +$delta = $accurate_timestamps ? 1 : 2; # Granularity of time on the filesystem chmod 0777, 'b'; $foo = (utime 500000000,500000000 + $delta,'b'); -if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";} + +is($foo, 1, "utime"); + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks) = stat('b'); -if ($^O eq 'MSWin32') { print "ok 17 # skipped: bogus (stat)[1]\n"; } -elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";} -if ($wd =~ m#/afs/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32') - {print "ok 18 # skipped: granularity of the filetime\n";} -elsif ($atime == 500000000 && $mtime == 500000000 + $delta) - {print "ok 18\n";} -elsif ($^O =~ /\blinux\b/i) { - # Maybe stat() cannot get the correct atime, as happens via NFS on linux? - $foo = (utime 400000000,500000000 + 2*$delta,'b'); - my ($new_atime, $new_mtime) = (stat('b'))[8,9]; - if ($new_atime == $atime && $new_mtime - $mtime == $delta) - {print "ok 18 # accounted for possible NFS/glibc2.2 bug on linux\n";} - else - {print "not ok 18 $atime/$new_atime $mtime/$new_mtime\n";} -} else - {print "not ok 18 $atime $mtime\n";} - -if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";} + +SKIP: { + skip "bogus inode num", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare'); + + ok($ino, 'non-zero inode num'); +} + +SKIP: { + skip "filesystem atime/mtime granularity too low", 2 + unless $accurate_timestamps; + + print "# atime - $atime mtime - $mtime delta - $delta\n"; + if($atime == 500000000 && $mtime == 500000000 + $delta) { + pass('atime'); + pass('mtime'); + } + else { + if ($^O =~ /\blinux\b/i) { + print "# Maybe stat() cannot get the correct atime, ". + "as happens via NFS on linux?\n"; + $foo = (utime 400000000,500000000 + 2*$delta,'b'); + my ($new_atime, $new_mtime) = (stat('b'))[8,9]; + print "# newatime - $new_atime nemtime - $new_mtime\n"; + if ($new_atime == $atime && $new_mtime - $mtime == $delta) { + pass("atime - accounted for possible NFS/glibc2.2 bug on linux"); + pass("mtime - accounted for possible NFS/glibc2.2 bug on linux"); + } + else { + fail("atime - $atime/$new_atime $mtime/$new_mtime"); + fail("mtime - $atime/$new_atime $mtime/$new_mtime"); + } + } + elsif ($^O eq 'VMS') { + # why is this 1 second off? + is( $atime, 500000001, 'atime' ); + is( $mtime, 500000000 + $delta, 'mtime' ); + } + elsif ($^O eq 'beos') { + SKIP: { skip "atime not updated", 1; } + is($mtime, 500000001, 'mtime'); + } + else { + fail("atime"); + fail("mtime"); + } + } +} + +is(unlink('b'), 1, "unlink b"); + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks) = stat('b'); -if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";} +is($ino, undef, "ino of unlinked file b should be undef"); unlink 'c'; chdir $wd || die "Can't cd back to $wd"; -unlink 'c'; -if ($^O ne 'MSWin32' and `ls -l perl 2>/dev/null` =~ /^l.*->/) { - # we have symbolic links +# Yet another way to look for links (perhaps those that cannot be +# created by perl?). Hopefully there is an ls utility in your +# %PATH%. N.B. that $^O is 'cygwin' on Cygwin. + +SKIP: { + skip "Win32/Netware specific test", 2 + unless ($^O eq 'MSWin32') || ($^O eq 'NetWare'); + skip "No symbolic links found to test with", 2 + unless `ls -l perl 2>nul` =~ /^l.*->/; + system("cp TEST TEST$$"); # we have to copy because e.g. GNU grep gets huffy if we have # a symlink forest to another disk (it complains about too many # levels of symbolic links, even if we have only two) - if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";} + is(symlink("TEST$$","c"), 1, "symlink"); $foo = `grep perl c 2>&1`; - if ($foo) {print "ok 22\n";} else {print "not ok 22\n";} + ok($foo, "found perl in c"); unlink 'c'; unlink("TEST$$"); } -else { - print "ok 21\nok 22\n"; -} -# truncate (may not be implemented everywhere) unlink "Iofs.tmp"; -`echo helloworld > Iofs.tmp`; -eval { truncate "Iofs.tmp", 5; }; -if ($@ =~ /not implemented/) { - print "# truncate not implemented -- skipping tests 23 through 26\n"; - for (23 .. 26) { - print "ok $_\n"; - } -} -else { - if (-s "Iofs.tmp" == 5) {print "ok 23\n"} else {print "not ok 23\n"} - truncate "Iofs.tmp", 0; - if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"} - open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp"; - binmode FH; - { select FH; $| = 1; select STDOUT } - { - use strict; +open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!"; +print IOFSCOM 'helloworld'; +close(IOFSCOM); + +# TODO: pp_truncate needs to be taught about F_CHSIZE and F_FREESP, +# as per UNIX FAQ. + +SKIP: { +# Check truncating a closed file. + eval { truncate "Iofs.tmp", 5; }; + + skip("no truncate - $@", 6) if $@; + + is(-s "Iofs.tmp", 5, "truncation to five bytes"); + + truncate "Iofs.tmp", 0; + + ok(-z "Iofs.tmp", "truncation to zero bytes"); + +#these steps are necessary to check if file is really truncated +#On Win95, FH is updated, but file properties aren't + open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp"; print FH "x\n" x 200; - truncate(FH, 200) or die "Can't truncate FH: $!"; - } - if ($^O eq 'dos' - # Not needed on HPFS, but needed on HPFS386 ?! - or $^O eq 'os2') - { - close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; - } - if (-s "Iofs.tmp" == 200) {print "ok 25\n"} else {print "not ok 25\n"} - truncate FH, 0; - if ($^O eq 'dos' - # Not needed on HPFS, but needed on HPFS386 ?! - or $^O eq 'os2') - { - close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; - } - if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"} - close FH; + close FH; + +# Check truncating an open file. + open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending"; + + binmode FH; + select FH; + $| = 1; + select STDOUT; + + { + use strict; + print FH "x\n" x 200; + ok(truncate(FH, 200), "fh resize to 200"); + } + + if ($needs_fh_reopen) { + close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; + } + + if ($^O eq 'vos') { + skip ("# TODO - hit VOS bug posix-973 - cannot resize an open file below the current file pos.", 3); + } + + is(-s "Iofs.tmp", 200, "fh resize to 200 working (filename check)"); + + ok(truncate(FH, 0), "fh resize to zero"); + + if ($needs_fh_reopen) { + close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; + } + + ok(-z "Iofs.tmp", "fh resize to zero working (filename check)"); + + close FH; } # check if rename() can be used to just change case of filename -chdir './tmp'; -open(fh,'>x') || die "Can't create x"; -close(fh); -rename('x', 'X'); -print 'not ' unless -e 'X'; -print "ok 27\n"; -unlink 'X'; -chdir $wd || die "Can't cd back to $wd"; +SKIP: { + skip "Works in Cygwin only if check_case is set to relaxed", 1 + if $^O eq 'cygwin'; + + chdir './tmp'; + open(fh,'>x') || die "Can't create x"; + close(fh); + rename('x', 'X'); + + # this works on win32 only, because fs isn't casesensitive + ok(-e 'X', "rename working"); + + 1 while unlink 'X'; + chdir $wd || die "Can't cd back to $wd"; +} # check if rename() works on directories -rename 'tmp', 'tmp1' or print "not "; -print "ok 28\n"; --d 'tmp1' or print "not "; -print "ok 29\n"; +if ($^O eq 'VMS') { + # must have delete access to rename a directory + `set file tmp.dir/protection=o:d`; + ok(rename('tmp.dir', 'tmp1.dir'), "rename on directories") || + print "# errno: $!\n"; +} else { + ok(rename('tmp', 'tmp1'), "rename on directories"); +} + +ok(-d 'tmp1', "rename on directories working"); -END { rmdir 'tmp1'; unlink "Iofs.tmp"; } +# need to remove 'tmp' if rename() in test 28 failed! +END { rmdir 'tmp1'; rmdir 'tmp'; unlink "Iofs.tmp"; } diff --git a/gnu/usr.bin/perl/t/io/inplace.t b/gnu/usr.bin/perl/t/io/inplace.t index ff410a7b5fc..a97add566c0 100644 --- a/gnu/usr.bin/perl/t/io/inplace.t +++ b/gnu/usr.bin/perl/t/io/inplace.t @@ -13,6 +13,18 @@ if ($^O eq 'MSWin32') { `.\\perl -le "print 'foo'" > .b`; `.\\perl -le "print 'foo'" > .c`; } +elsif ($^O eq 'NetWare') { + $CAT = 'perl -e "print<>"'; + `perl -le "print 'foo'" > .a`; + `perl -le "print 'foo'" > .b`; + `perl -le "print 'foo'" > .c`; +} +elsif ($^O eq 'MacOS') { + $CAT = "$^X -e \"print<>\""; + `$^X -le "print 'foo'" > .a`; + `$^X -le "print 'foo'" > .b`; + `$^X -le "print 'foo'" > .c`; +} elsif ($^O eq 'VMS') { $CAT = 'MCR []perl. -e "print<>"'; `MCR []perl. -le "print 'foo'" > ./.a`; diff --git a/gnu/usr.bin/perl/t/io/open.t b/gnu/usr.bin/perl/t/io/open.t index 0e2d57cd757..cf1d39dc0d8 100644 --- a/gnu/usr.bin/perl/t/io/open.t +++ b/gnu/usr.bin/perl/t/io/open.t @@ -3,289 +3,241 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; -} + require './test.pl'; +} -# $RCSfile$ $| = 1; use warnings; +use Config; $Is_VMS = $^O eq 'VMS'; -$Is_Dos = $^O eq 'dos'; +$Is_MacOS = $^O eq 'MacOS'; -print "1..66\n"; +plan tests => 94; -my $test = 1; +my $Perl = which_perl(); -sub ok { print "ok $test\n"; $test++ } +{ + unlink("afile") if -f "afile"; -# my $file tests + $! = 0; # the -f above will set $! if 'afile' doesn't exist. + ok( open(my $f,"+>afile"), 'open(my $f, "+>...")' ); -# 1..9 -{ - unlink("afile") if -f "afile"; - print "$!\nnot " unless open(my $f,"+>afile"); - ok; binmode $f; - print "not " unless -f "afile"; - ok; - print "not " unless print $f "SomeData\n"; - ok; - print "not " unless tell($f) == 9; - ok; - print "not " unless seek($f,0,0); - ok; + ok( -f "afile", ' its a file'); + ok( (print $f "SomeData\n"), ' we can print to it'); + is( tell($f), 9, ' tell()' ); + ok( seek($f,0,0), ' seek set' ); + $b = <$f>; - print "not " unless $b eq "SomeData\n"; - ok; - print "not " unless -f $f; - ok; - eval { die "Message" }; - # warn $@; - print "not " unless $@ =~ /<\$f> line 1/; - ok; - print "not " unless close($f); - ok; - unlink("afile"); + is( $b, "SomeData\n", ' readline' ); + ok( -f $f, ' still a file' ); + + eval { die "Message" }; + like( $@, qr/<\$f> line 1/, ' die message correct' ); + + ok( close($f), ' close()' ); + ok( unlink("afile"), ' unlink()' ); } -# 10..12 { - print "# \$!='$!'\nnot " unless open(my $f,'>', 'afile'); - ok; - print $f "a row\n"; - print "not " unless close($f); - ok; - print "not " unless -s 'afile' < 10; - ok; + ok( open(my $f,'>', 'afile'), "open(my \$f, '>', 'afile')" ); + ok( (print $f "a row\n"), ' print'); + ok( close($f), ' close' ); + ok( -s 'afile' < 10, ' -s' ); } -# 13..15 { - print "# \$!='$!'\nnot " unless open(my $f,'>>', 'afile'); - ok; - print $f "a row\n"; - print "not " unless close($f); - ok; - print "not " unless -s 'afile' > 10; - ok; + ok( open(my $f,'>>', 'afile'), "open(my \$f, '>>', 'afile')" ); + ok( (print $f "a row\n"), ' print' ); + ok( close($f), ' close' ); + ok( -s 'afile' > 10, ' -s' ); } -# 16..18 { - print "# \$!='$!'\nnot " unless open(my $f, '<', 'afile'); - ok; - @rows = <$f>; - print "not " unless @rows == 2; - ok; - print "not " unless close($f); - ok; + ok( open(my $f, '<', 'afile'), "open(my \$f, '<', 'afile')" ); + my @rows = <$f>; + is( scalar @rows, 2, ' readline, list context' ); + is( $rows[0], "a row\n", ' first line read' ); + is( $rows[1], "a row\n", ' second line' ); + ok( close($f), ' close' ); } -# 19..23 { - print "not " unless -s 'afile' < 20; - ok; - print "# \$!='$!'\nnot " unless open(my $f, '+<', 'afile'); - ok; - @rows = <$f>; - print "not " unless @rows == 2; - ok; - seek $f, 0, 1; - print $f "yet another row\n"; - print "not " unless close($f); - ok; - print "not " unless -s 'afile' > 20; - ok; - - unlink("afile"); -} + ok( -s 'afile' < 20, '-s' ); -# 24..26 -if ($Is_VMS) { - for (24..26) { print "ok $_ # skipped: not Unix fork\n"; $test++;} + ok( open(my $f, '+<', 'afile'), 'open +<' ); + my @rows = <$f>; + is( scalar @rows, 2, ' readline, list context' ); + ok( seek($f, 0, 1), ' seek cur' ); + ok( (print $f "yet another row\n"), ' print' ); + ok( close($f), ' close' ); + ok( -s 'afile' > 20, ' -s' ); + + unlink("afile"); } -else { - print "# \$!='$!'\nnot " unless open(my $f, '-|', <<'EOC'); - ./perl -e "print qq(a row\n); print qq(another row\n)" + +SKIP: { + skip "open -| busted and noisy on VMS", 3 if $Is_VMS; + + ok( open(my $f, '-|', <<EOC), 'open -|' ); + $Perl -e "print qq(a row\\n); print qq(another row\\n)" EOC - ok; - @rows = <$f>; - print "not " unless @rows == 2; - ok; - print "not " unless close($f); - ok; -} -# 27..30 -if ($Is_VMS) { - for (27..30) { print "ok $_ # skipped: not Unix fork\n"; $test++;} + my @rows = <$f>; + is( scalar @rows, 2, ' readline, list context' ); + ok( close($f), ' close' ); } -else { - print "# \$!='$!'\nnot " unless open(my $f, '|-', <<'EOC'); - ./perl -pe "s/^not //" + +SKIP: { + skip "Output for |- doesn't go to shell on MacOS", 5 if $Is_MacOS; + + ok( open(my $f, '|-', <<EOC), 'open |-' ); + $Perl -pe "s/^not //" EOC - ok; - @rows = <$f>; - print $f "not ok $test\n"; $test++; - print $f "not ok $test\n"; $test++; - print "#\nnot " unless close($f); + + my @rows = <$f>; + my $test = curr_test; + print $f "not ok $test - piped in\n"; + next_test; + + $test = curr_test; + print $f "not ok $test - piped in\n"; + next_test; + ok( close($f), ' close' ); sleep 1; - ok; + pass('flushing'); } -# 31..32 -eval <<'EOE' and print "not "; -open my $f, '<&', 'afile'; -1; -EOE -ok; -$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not "; -ok; -# local $file tests +ok( !eval { open my $f, '<&', 'afile'; 1; }, '<& on a non-filehandle' ); +like( $@, qr/Bad filehandle:\s+afile/, ' right error' ); + -# 33..41 +# local $file tests { - unlink("afile") if -f "afile"; - print "$!\nnot " unless open(local $f,"+>afile"); - ok; + unlink("afile") if -f "afile"; + + ok( open(local $f,"+>afile"), 'open local $f, "+>", ...' ); binmode $f; - print "not " unless -f "afile"; - ok; - print "not " unless print $f "SomeData\n"; - ok; - print "not " unless tell($f) == 9; - ok; - print "not " unless seek($f,0,0); - ok; + + ok( -f "afile", ' -f' ); + ok( (print $f "SomeData\n"), ' print' ); + is( tell($f), 9, ' tell' ); + ok( seek($f,0,0), ' seek set' ); + $b = <$f>; - print "not " unless $b eq "SomeData\n"; - ok; - print "not " unless -f $f; - ok; - eval { die "Message" }; - # warn $@; - print "not " unless $@ =~ /<\$f> line 1/; - ok; - print "not " unless close($f); - ok; - unlink("afile"); + is( $b, "SomeData\n", ' readline' ); + ok( -f $f, ' still a file' ); + + eval { die "Message" }; + like( $@, qr/<\$f> line 1/, ' proper die message' ); + ok( close($f), ' close' ); + + unlink("afile"); } -# 42..44 { - print "# \$!='$!'\nnot " unless open(local $f,'>', 'afile'); - ok; - print $f "a row\n"; - print "not " unless close($f); - ok; - print "not " unless -s 'afile' < 10; - ok; + ok( open(local $f,'>', 'afile'), 'open local $f, ">", ...' ); + ok( (print $f "a row\n"), ' print'); + ok( close($f), ' close'); + ok( -s 'afile' < 10, ' -s' ); } -# 45..47 { - print "# \$!='$!'\nnot " unless open(local $f,'>>', 'afile'); - ok; - print $f "a row\n"; - print "not " unless close($f); - ok; - print "not " unless -s 'afile' > 10; - ok; + ok( open(local $f,'>>', 'afile'), 'open local $f, ">>", ...' ); + ok( (print $f "a row\n"), ' print'); + ok( close($f), ' close'); + ok( -s 'afile' > 10, ' -s' ); } -# 48..50 { - print "# \$!='$!'\nnot " unless open(local $f, '<', 'afile'); - ok; - @rows = <$f>; - print "not " unless @rows == 2; - ok; - print "not " unless close($f); - ok; + ok( open(local $f, '<', 'afile'), 'open local $f, "<", ...' ); + my @rows = <$f>; + is( scalar @rows, 2, ' readline list context' ); + ok( close($f), ' close' ); } -# 51..55 +ok( -s 'afile' < 20, ' -s' ); + { - print "not " unless -s 'afile' < 20; - ok; - print "# \$!='$!'\nnot " unless open(local $f, '+<', 'afile'); - ok; - @rows = <$f>; - print "not " unless @rows == 2; - ok; - seek $f, 0, 1; - print $f "yet another row\n"; - print "not " unless close($f); - ok; - print "not " unless -s 'afile' > 20; - ok; - - unlink("afile"); -} + ok( open(local $f, '+<', 'afile'), 'open local $f, "+<", ...' ); + my @rows = <$f>; + is( scalar @rows, 2, ' readline list context' ); + ok( seek($f, 0, 1), ' seek cur' ); + ok( (print $f "yet another row\n"), ' print' ); + ok( close($f), ' close' ); + ok( -s 'afile' > 20, ' -s' ); -# 56..58 -if ($Is_VMS) { - for (56..58) { print "ok $_ # skipped: not Unix fork\n"; $test++;} + unlink("afile"); } -else { - print "# \$!='$!'\nnot " unless open(local $f, '-|', <<'EOC'); - ./perl -e "print qq(a row\n); print qq(another row\n)" + +SKIP: { + skip "open -| busted and noisy on VMS", 3 if $Is_VMS; + + ok( open(local $f, '-|', <<EOC), 'open local $f, "-|", ...' ); + $Perl -e "print qq(a row\\n); print qq(another row\\n)" EOC - ok; - @rows = <$f>; - print "not " unless @rows == 2; - ok; - print "not " unless close($f); - ok; -} + my @rows = <$f>; -# 59..62 -if ($Is_VMS) { - for (59..62) { print "ok $_ # skipped: not Unix fork\n"; $test++;} + is( scalar @rows, 2, ' readline list context' ); + ok( close($f), ' close' ); } -else { - print "# \$!='$!'\nnot " unless open(local $f, '|-', <<'EOC'); - ./perl -pe "s/^not //" + +SKIP: { + skip "Output for |- doesn't go to shell on MacOS", 5 if $Is_MacOS; + + ok( open(local $f, '|-', <<EOC), 'open local $f, "|-", ...' ); + $Perl -pe "s/^not //" EOC - ok; - @rows = <$f>; - print $f "not ok $test\n"; $test++; - print $f "not ok $test\n"; $test++; - print "#\nnot " unless close($f); + + my @rows = <$f>; + my $test = curr_test; + print $f "not ok $test - piping\n"; + next_test; + + $test = curr_test; + print $f "not ok $test - piping\n"; + next_test; + ok( close($f), ' close' ); sleep 1; - ok; + pass("Flush"); } -# 63..64 -eval <<'EOE' and print "not "; -open local $f, '<&', 'afile'; -1; -EOE -ok; -$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not "; -ok; -# 65..66 +ok( !eval { open local $f, '<&', 'afile'; 1 }, 'local <& on non-filehandle'); +like( $@, qr/Bad filehandle:\s+afile/, ' right error' ); + { local *F; for (1..2) { - if ($Is_Dos) { - open(F, "echo \\#foo|") or print "not "; - } else { - open(F, "echo #foo|") or print "not "; - } - print <F>; - close F; + ok( open(F, qq{$Perl -le "print 'ok'"|}), 'open to pipe' ); + is(scalar <F>, "ok\n", ' readline'); + ok( close F, ' close' ); } - ok; + for (1..2) { - if ($Is_Dos) { - open(F, "-|", "echo \\#foo") or print "not "; - } else { - open(F, "-|", "echo #foo") or print "not "; - } - print <F>; - close F; + ok( open(F, "-|", qq{$Perl -le "print 'ok'"}), 'open -|'); + is( scalar <F>, "ok\n", ' readline'); + ok( close F, ' close' ); } - ok; +} + + +# other dupping techniques +{ + ok( open(my $stdout, ">&", \*STDOUT), 'dup \*STDOUT into lexical fh'); + ok( open(STDOUT, ">&", $stdout), 'restore dupped STDOUT from lexical fh'); +} + +SKIP: { + skip "This perl uses perlio", 1 if $Config{useperlio}; + skip "This system doesn't understand EINVAL", 1 unless exists $!{EINVAL}; + + no warnings 'io'; + ok( !open(F,'>',\my $s) && $!{EINVAL}, 'open(reference) raises EINVAL' ); +} + +{ + ok( !eval { open F, "BAR", "QUUX" }, 'Unknown open() mode' ); + like( $@, qr/\QUnknown open() mode 'BAR'/, ' right error' ); } diff --git a/gnu/usr.bin/perl/t/io/pipe.t b/gnu/usr.bin/perl/t/io/pipe.t index 96935e3f88c..c32f3b1046c 100644 --- a/gnu/usr.bin/perl/t/io/pipe.t +++ b/gnu/usr.bin/perl/t/io/pipe.t @@ -4,61 +4,84 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require Config; import Config; - unless ($Config{'d_fork'}) { - print "1..0 # Skip: no fork\n"; - exit 0; + require './test.pl'; + + if (!$Config{'d_fork'}) { + skip_all("fork required to pipe"); + } + else { + plan(tests => 22); } } +my $Perl = which_perl(); + + $| = 1; -print "1..15\n"; -# External program 'tr' assumed. -open(PIPE, "|-") || (exec 'tr', 'YX', 'ko'); -print PIPE "Xk 1\n"; -print PIPE "oY 2\n"; +open(PIPE, "|-") || exec $Perl, '-pe', 'tr/YX/ko/'; + +printf PIPE "Xk %d - open |- || exec\n", curr_test(); +next_test(); +printf PIPE "oY %d - again\n", curr_test(); +next_test(); close PIPE; -if ($^O eq 'vmesa') { - # Doesn't work, yet. - for (3..6) { - print "ok $_ # skipped\n"; - } -} else { +SKIP: { + # Technically this should be TODO. Someone try it if you happen to + # have a vmesa machine. + skip "Doesn't work here yet", 4 if $^O eq 'vmesa'; + if (open(PIPE, "-|")) { while(<PIPE>) { s/^not //; print; } - close PIPE; # avoid zombies which disrupt test 12 + close PIPE; # avoid zombies } else { - # External program 'echo' assumed. - print STDOUT "not ok 3\n"; - exec 'echo', 'not ok 4'; + printf STDOUT "not ok %d - open -|\n", curr_test(); + next_test(); + my $tnum = curr_test; + next_test(); + exec $Perl, '-le', "print q{not ok $tnum - again}"; } - pipe(READER,WRITER) || die "Can't open pipe"; - - if ($pid = fork) { - close WRITER; - while(<READER>) { - s/^not //; - y/A-Z/a-z/; - print; - } - close READER; # avoid zombies which disrupt test 12 + # This has to be *outside* the fork + next_test() for 1..2; + + SKIP: { + skip "fork required", 2 unless $Config{d_fork}; + + pipe(READER,WRITER) || die "Can't open pipe"; + + if ($pid = fork) { + close WRITER; + while(<READER>) { + s/^not //; + y/A-Z/a-z/; + print; + } + close READER; # avoid zombies + } + else { + die "Couldn't fork" unless defined $pid; + close READER; + printf WRITER "not ok %d - pipe & fork\n", curr_test; + next_test; + + open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT"; + close WRITER; + + my $tnum = curr_test; + next_test; + exec $Perl, '-le', "print q{not ok $tnum - with fh dup }"; + } + + # This has to be done *outside* the fork. + next_test() for 1..2; } - else { - die "Couldn't fork" unless defined $pid; - close READER; - print WRITER "not ok 5\n"; - open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT"; - close WRITER; - # External program 'echo' assumed. - exec 'echo', 'not ok 6'; - } -} +} wait; # Collect from $pid pipe(READER,WRITER) || die "Can't open pipe"; @@ -68,109 +91,108 @@ $SIG{'PIPE'} = 'broken_pipe'; sub broken_pipe { $SIG{'PIPE'} = 'IGNORE'; # loop preventer - print "ok 7\n"; + printf "ok %d - SIGPIPE\n", curr_test; } -print WRITER "not ok 7\n"; +printf WRITER "not ok %d - SIGPIPE\n", curr_test; close WRITER; sleep 1; -print "ok 8\n"; +next_test; +pass(); # VMS doesn't like spawning subprocesses that are still connected to -# STDOUT. Someone should modify tests #9 to #12 to work with VMS. - -if ($^O eq 'VMS') { - print "ok 9 # skipped\n"; - print "ok 10 # skipped\n"; - print "ok 11 # skipped\n"; - print "ok 12 # skipped\n"; - exit; -} - -if ($Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' || $^O eq 'posix-bc') { - # Sfio doesn't report failure when closing a broken pipe - # that has pending output. Go figure. MachTen doesn't either, - # but won't write to broken pipes, so nothing's pending at close. - # BeOS will not write to broken pipes, either. - # Nor does POSIX-BC. - print "ok 9 # skipped\n"; -} -else { - local $SIG{PIPE} = 'IGNORE'; - open NIL, '|true' or die "open failed: $!"; - sleep 5; - print NIL 'foo' or die "print failed: $!"; - if (close NIL) { - print "not ok 9\n"; - } - else { - print "ok 9\n"; +# STDOUT. Someone should modify these tests to work with VMS. + +SKIP: { + skip "doesn't like spawning subprocesses that are still connected", 10 + if $^O eq 'VMS'; + + SKIP: { + # Sfio doesn't report failure when closing a broken pipe + # that has pending output. Go figure. MachTen doesn't either, + # but won't write to broken pipes, so nothing's pending at close. + # BeOS will not write to broken pipes, either. + # Nor does POSIX-BC. + skip "Won't report failure on broken pipe", 1 + if $Config{d_sfio} || $^O eq 'machten' || $^O eq 'beos' || + $^O eq 'posix-bc'; + + local $SIG{PIPE} = 'IGNORE'; + open NIL, qq{|$Perl -e "exit 0"} or die "open failed: $!"; + sleep 5; + if (print NIL 'foo') { + # If print was allowed we had better get an error on close + ok( !close NIL, 'close error on broken pipe' ); + } + else { + ok(close NIL, 'print failed on broken pipe'); + } } -} - -if ($^O eq 'vmesa') { - # These don't work, yet. - print "ok 10 # skipped\n"; - print "ok 11 # skipped\n"; - print "ok 12 # skipped\n"; - exit; -} - -# check that errno gets forced to 0 if the piped program exited non-zero -open NIL, '|exit 23;' or die "fork failed: $!"; -$! = 1; -if (close NIL) { - print "not ok 10\n# successful close\n"; -} -elsif ($! != 0) { - print "not ok 10\n# errno $!\n"; -} -elsif ($? == 0) { - print "not ok 10\n# status 0\n"; -} -else { - print "ok 10\n"; -} -if ($^O eq 'mpeix') { - print "ok 11 # skipped\n"; - print "ok 12 # skipped\n"; -} else { - # check that status for the correct process is collected - my $zombie = fork or exit 37; - my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n"; - $SIG{ALRM} = sub { return }; - alarm(1); - my $close = close FH; - if ($? == 13*256 && ! length $close && ! $!) { - print "ok 11\n"; - } else { - print "not ok 11\n# close $close\$?=$? \$!=", $!+0, ":$!\n"; - }; - my $wait = wait; - if ($? == 37*256 && $wait == $zombie && ! $!) { - print "ok 12\n"; - } else { - print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$? \$!=", $!+0, ":$!\n"; + SKIP: { + skip "Don't work yet", 9 if $^O eq 'vmesa'; + + # check that errno gets forced to 0 if the piped program exited + # non-zero + open NIL, qq{|$Perl -e "exit 23";} or die "fork failed: $!"; + $! = 1; + ok(!close NIL, 'close failure on non-zero piped exit'); + is($!, '', ' errno'); + isnt($?, 0, ' status'); + + SKIP: { + skip "Don't work yet", 6 if $^O eq 'mpeix'; + + # check that status for the correct process is collected + my $zombie; + unless( $zombie = fork ) { + $NO_ENDING=1; + exit 37; + } + my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n"; + $SIG{ALRM} = sub { return }; + alarm(1); + is( close FH, '', 'close failure for... umm, something' ); + is( $?, 13*256, ' status' ); + is( $!, '', ' errno'); + + my $wait = wait; + is( $?, 37*256, 'status correct after wait' ); + is( $wait, $zombie, ' wait pid' ); + is( $!, '', ' errno'); + } } } # Test new semantics for missing command in piped open # 19990114 M-J. Dominus mjd@plover.com { local *P; - print (((open P, "| " ) ? "not " : ""), "ok 13\n"); - print (((open P, " |" ) ? "not " : ""), "ok 14\n"); + ok( !open(P, "| "), 'missing command in piped open input' ); + ok( !open(P, " |"), ' output'); } # check that status is unaffected by implicit close { local(*NIL); - open NIL, '|exit 23;' or die "fork failed: $!"; + open NIL, qq{|$Perl -e "exit 23"} or die "fork failed: $!"; $? = 42; # NIL implicitly closed here } -if ($? != 42) { - print "# status $?, expected 42\nnot "; -} -print "ok 15\n"; +is($?, 42, 'status unaffected by implicit close'); $? = 0; + +# check that child is reaped if the piped program can't be executed +{ + open NIL, '/no_such_process |'; + close NIL; + + my $child = 0; + eval { + local $SIG{ALRM} = sub { die; }; + alarm 2; + $child = wait; + alarm 0; + }; + + is($child, -1, 'child reaped if piped program cannot be executed'); +} diff --git a/gnu/usr.bin/perl/t/io/tell.t b/gnu/usr.bin/perl/t/io/tell.t index c840c9232a1..416b869ea6f 100644 --- a/gnu/usr.bin/perl/t/io/tell.t +++ b/gnu/usr.bin/perl/t/io/tell.t @@ -2,11 +2,16 @@ # $RCSfile: tell.t,v $$Revision$$Date$ +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + print "1..23\n"; $TST = 'tst'; -$Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'dos' or +$Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin'); open($TST, 'harness') || (die "Can't open harness"); @@ -50,7 +55,7 @@ if ($. == 0) { print "not ok 14\n"; } else { print "ok 14\n"; } $curline = $.; open(other, 'harness') || (die "Can't open harness: $!"); -binmode other if $^O eq 'MSWin32'; +binmode other if (($^O eq 'MSWin32') || ($^O eq 'NetWare')); { local($.); |