diff options
author | markm <markm@FreeBSD.org> | 1998-09-09 07:00:04 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 1998-09-09 07:00:04 +0000 |
commit | 4fcbc3669aa997848e15198cc9fb856287a6788c (patch) | |
tree | 58b20e81687d6d5931f120b50802ed21225bf440 /contrib/perl5/t/io | |
download | FreeBSD-src-4fcbc3669aa997848e15198cc9fb856287a6788c.zip FreeBSD-src-4fcbc3669aa997848e15198cc9fb856287a6788c.tar.gz |
Initial import of Perl5. The king is dead; long live the king!
Diffstat (limited to 'contrib/perl5/t/io')
-rwxr-xr-x | contrib/perl5/t/io/argv.t | 48 | ||||
-rwxr-xr-x | contrib/perl5/t/io/dup.t | 39 | ||||
-rwxr-xr-x | contrib/perl5/t/io/fs.t | 159 | ||||
-rwxr-xr-x | contrib/perl5/t/io/inplace.t | 36 | ||||
-rwxr-xr-x | contrib/perl5/t/io/iprefix.t | 36 | ||||
-rwxr-xr-x | contrib/perl5/t/io/pipe.t | 135 | ||||
-rwxr-xr-x | contrib/perl5/t/io/print.t | 32 | ||||
-rwxr-xr-x | contrib/perl5/t/io/read.t | 26 | ||||
-rwxr-xr-x | contrib/perl5/t/io/tell.t | 44 |
9 files changed, 555 insertions, 0 deletions
diff --git a/contrib/perl5/t/io/argv.t b/contrib/perl5/t/io/argv.t new file mode 100755 index 0000000..d99865e --- /dev/null +++ b/contrib/perl5/t/io/argv.t @@ -0,0 +1,48 @@ +#!./perl + +# $RCSfile: argv.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:25 $ + +print "1..5\n"; + +open(try, '>Io.argv.tmp') || (die "Can't open temp file."); +print try "a line\n"; +close try; + +if ($^O eq 'MSWin32') { + $x = `.\\perl -e "while (<>) {print \$.,\$_;}" Io.argv.tmp Io.argv.tmp`; +} +else { + $x = `./perl -e 'while (<>) {print \$.,\$_;}' Io.argv.tmp Io.argv.tmp`; +} +if ($x eq "1a line\n2a line\n") {print "ok 1\n";} else {print "not ok 1\n";} + +if ($^O eq 'MSWin32') { + $x = `.\\perl -le "print 'foo'" | .\\perl -e "while (<>) {print \$_;}" Io.argv.tmp -`; +} +else { + $x = `echo foo|./perl -e 'while (<>) {print $_;}' Io.argv.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 $_;}'`; +} +if ($x eq "foo\n") {print "ok 3\n";} else {print "not ok 3 :$x:\n";} + +@ARGV = ('Io.argv.tmp', 'Io.argv.tmp', '/dev/null', 'Io.argv.tmp'); +while (<>) { + $y .= $. . $_; + if (eof()) { + if ($. == 3) {print "ok 4\n";} else {print "not ok 4\n";} + } +} + +if ($y eq "1a line\n2a line\n3a line\n") + {print "ok 5\n";} +else + {print "not ok 5\n";} + +unlink 'Io.argv.tmp'; diff --git a/contrib/perl5/t/io/dup.t b/contrib/perl5/t/io/dup.t new file mode 100755 index 0000000..f312671 --- /dev/null +++ b/contrib/perl5/t/io/dup.t @@ -0,0 +1,39 @@ +#!./perl + +# $RCSfile: dup.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:27 $ + +print "1..6\n"; + +print "ok 1\n"; + +open(dupout,">&STDOUT"); +open(duperr,">&STDERR"); + +open(STDOUT,">Io.dup") || die "Can't open stdout"; +open(STDERR,">&STDOUT") || die "Can't open stderr"; + +select(STDERR); $| = 1; +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? +} +else { + system 'echo ok 4'; + system 'echo ok 5 1>&2'; +} + +close(STDOUT); +close(STDERR); + +open(STDOUT,">&dupout"); +open(STDERR,">&duperr"); + +if ($^O eq 'MSWin32') { print `type Io.dup` } +else { system 'cat Io.dup' } +unlink 'Io.dup'; + +print STDOUT "ok 6\n"; diff --git a/contrib/perl5/t/io/fs.t b/contrib/perl5/t/io/fs.t new file mode 100755 index 0000000..164a667 --- /dev/null +++ b/contrib/perl5/t/io/fs.t @@ -0,0 +1,159 @@ +#!./perl + +# $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $ + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Config; + +$Is_Dosish = ($^O eq 'dos' or $^O eq 'os2'); + +# avoid win32 (for now) +do { print "1..0\n"; exit(0); } if $^O eq 'MSWin32'; + +print "1..26\n"; + +$wd = (($^O eq 'MSWin32') ? `cd` : `pwd`); +chop($wd); + +if ($^O eq 'MSWin32') { `del tmp`; `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 ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";} +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";} + +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";} + +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('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";} + +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";} + +if ((chmod 0777,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";} + +($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) == 0777) {print "ok 7\n";} +else {print "not ok 7\n";} + +if ($Is_Dosish) {print "ok 8 # skipped: no link\n";} +elsif ((chmod 0700,'c','x') == 2) {print "ok 8\n";} +else {print "not ok 8\n";} + +($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) == 0700) {print "ok 9\n";} +else {print "not ok 9\n";} + +($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) == 0700) {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";} + +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 +$foo = (utime 500000000,500000000 + $delta,'b'); +if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";} +($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, + $blksize,$blocks) = stat('b'); +if ($ino) {print "ok 17\n";} else {print "not ok 17\n";} +if ($wd =~ m#/afs/# || $^O eq 'amigaos') + {print "ok 18 # skipped: granularity of the filetime\n";} +elsif ($atime == 500000000 && $mtime == 500000000 + $delta) + {print "ok 18\n";} +else + {print "not ok 18 $atime $mtime\n";} + +if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";} +($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";} +unlink 'c'; + +chdir $wd || die "Can't cd back to $wd"; +rmdir 'tmp'; + +unlink 'c'; +if ($^O ne 'MSWin32' and `ls -l perl 2>/dev/null` =~ /^l.*->/) { + # we have symbolic links + if (symlink("TEST","c")) {print "ok 21\n";} else {print "not ok 21\n";} + $foo = `grep perl c`; + if ($foo) {print "ok 22\n";} else {print "not ok 22\n";} + unlink 'c'; +} +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"; + { select FH; $| = 1; select STDOUT } + print FH "helloworld\n"; + truncate FH, 5; + if ($^O eq 'dos') { + close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp"; + } + if (-s "Iofs.tmp" == 5) {print "ok 25\n"} else {print "not ok 25\n"} + truncate FH, 0; + if ($^O eq 'dos') { + 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; +} +unlink "Iofs.tmp"; diff --git a/contrib/perl5/t/io/inplace.t b/contrib/perl5/t/io/inplace.t new file mode 100755 index 0000000..ff410a7 --- /dev/null +++ b/contrib/perl5/t/io/inplace.t @@ -0,0 +1,36 @@ +#!./perl + +$^I = $^O eq 'VMS' ? '_bak' : '.bak'; + +# $RCSfile: inplace.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:29 $ + +print "1..2\n"; + +@ARGV = ('.a','.b','.c'); +if ($^O eq 'MSWin32') { + $CAT = '.\perl -e "print<>"'; + `.\\perl -le "print 'foo'" > .a`; + `.\\perl -le "print 'foo'" > .b`; + `.\\perl -le "print 'foo'" > .c`; +} +elsif ($^O eq 'VMS') { + $CAT = 'MCR []perl. -e "print<>"'; + `MCR []perl. -le "print 'foo'" > ./.a`; + `MCR []perl. -le "print 'foo'" > ./.b`; + `MCR []perl. -le "print 'foo'" > ./.c`; +} +else { + $CAT = 'cat'; + `echo foo | tee .a .b .c`; +} +while (<>) { + s/foo/bar/; +} +continue { + print; +} + +if (`$CAT .a .b .c` eq "bar\nbar\nbar\n") {print "ok 1\n";} else {print "not ok 1\n";} +if (`$CAT .a$^I .b$^I .c$^I` eq "foo\nfoo\nfoo\n") {print "ok 2\n";} else {print "not ok 2\n";} + +unlink '.a', '.b', '.c', ".a$^I", ".b$^I", ".c$^I"; diff --git a/contrib/perl5/t/io/iprefix.t b/contrib/perl5/t/io/iprefix.t new file mode 100755 index 0000000..10a5c5f --- /dev/null +++ b/contrib/perl5/t/io/iprefix.t @@ -0,0 +1,36 @@ +#!./perl + +$^I = 'bak*'; + +# Modified from the original inplace.t to test adding prefixes + +print "1..2\n"; + +@ARGV = ('.a','.b','.c'); +if ($^O eq 'MSWin32') { + $CAT = '.\perl -e "print<>"'; + `.\\perl -le "print 'foo'" > .a`; + `.\\perl -le "print 'foo'" > .b`; + `.\\perl -le "print 'foo'" > .c`; +} +elsif ($^O eq 'VMS') { + $CAT = 'MCR []perl. -e "print<>"'; + `MCR []perl. -le "print 'foo'" > ./.a`; + `MCR []perl. -le "print 'foo'" > ./.b`; + `MCR []perl. -le "print 'foo'" > ./.c`; +} +else { + $CAT = 'cat'; + `echo foo | tee .a .b .c`; +} +while (<>) { + s/foo/bar/; +} +continue { + print; +} + +if (`$CAT .a .b .c` eq "bar\nbar\nbar\n") {print "ok 1\n";} else {print "not ok 1\n";} +if (`$CAT bak.a bak.b bak.c` eq "foo\nfoo\nfoo\n") {print "ok 2\n";} else {print "not ok 2\n";} + +unlink '.a', '.b', '.c', 'bak.a', 'bak.b', 'bak.c'; diff --git a/contrib/perl5/t/io/pipe.t b/contrib/perl5/t/io/pipe.t new file mode 100755 index 0000000..ba7a9b0 --- /dev/null +++ b/contrib/perl5/t/io/pipe.t @@ -0,0 +1,135 @@ +#!./perl + +# $RCSfile: pipe.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:31 $ + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require Config; import Config; + unless ($Config{'d_fork'}) { + print "1..0\n"; + exit 0; + } +} + +$| = 1; +print "1..12\n"; + +open(PIPE, "|-") || (exec 'tr', 'YX', 'ko'); +print PIPE "Xk 1\n"; +print PIPE "oY 2\n"; +close PIPE; + +if (open(PIPE, "-|")) { + while(<PIPE>) { + s/^not //; + print; + } + close PIPE; # avoid zombies which disrupt test 12 +} +else { + print STDOUT "not ok 3\n"; + exec 'echo', 'not ok 4'; +} + +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 +} +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; + exec 'echo', 'not ok 6'; +} + + +pipe(READER,WRITER) || die "Can't open pipe"; +close READER; + +$SIG{'PIPE'} = 'broken_pipe'; + +sub broken_pipe { + $SIG{'PIPE'} = 'IGNORE'; # loop preventer + print "ok 7\n"; +} + +print WRITER "not ok 7\n"; +close WRITER; +sleep 1; +print "ok 8\n"; + +# 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\n"; + print "ok 10\n"; + print "ok 11\n"; + print "ok 12\n"; + exit; +} + +if ($Config{d_sfio} || $^O eq machten || $^O eq beos) { + # 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. + print "ok 9\n"; +} +else { + local $SIG{PIPE} = 'IGNORE'; + open NIL, '|true' or die "open failed: $!"; + sleep 2; + print NIL 'foo' or die "print failed: $!"; + if (close NIL) { + print "not ok 9\n"; + } + else { + print "ok 9\n"; + } +} + +# 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"; +} + +# check that status for the correct process is collected +wait; # Collect from $pid +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"; +} diff --git a/contrib/perl5/t/io/print.t b/contrib/perl5/t/io/print.t new file mode 100755 index 0000000..180b1e8 --- /dev/null +++ b/contrib/perl5/t/io/print.t @@ -0,0 +1,32 @@ +#!./perl + +# $RCSfile: print.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:32 $ + +print "1..16\n"; + +$foo = 'STDOUT'; +print $foo "ok 1\n"; + +print "ok 2\n","ok 3\n","ok 4\n"; +print STDOUT "ok 5\n"; + +open(foo,">-"); +print foo "ok 6\n"; + +printf "ok %d\n",7; +printf("ok %d\n",8); + +@a = ("ok %d%c",9,ord("\n")); +printf @a; + +$a[1] = 10; +printf STDOUT @a; + +$, = ' '; +$\ = "\n"; + +print "ok","11"; + +@x = ("ok","12\nok","13\nok"); +@y = ("15\nok","16"); +print @x,"14\nok",@y; diff --git a/contrib/perl5/t/io/read.t b/contrib/perl5/t/io/read.t new file mode 100755 index 0000000..b27fde1 --- /dev/null +++ b/contrib/perl5/t/io/read.t @@ -0,0 +1,26 @@ +#!./perl + +# $RCSfile$ + +print "1..1\n"; + +open(A,"+>a"); +print A "_"; +seek(A,0,0); + +$b = "abcd"; +$b = ""; + +read(A,$b,1,4); + +close(A); + +unlink("a"); + +if ($b eq "\000\000\000\000_") { + print "ok 1\n"; +} else { # Probably "\000bcd_" + print "not ok 1\n"; +} + +unlink 'a'; diff --git a/contrib/perl5/t/io/tell.t b/contrib/perl5/t/io/tell.t new file mode 100755 index 0000000..83904e8 --- /dev/null +++ b/contrib/perl5/t/io/tell.t @@ -0,0 +1,44 @@ +#!./perl + +# $RCSfile: tell.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:33 $ + +print "1..13\n"; + +$TST = 'tst'; + +open($TST, '../Configure') || (die "Can't open ../Configure"); +binmode $TST if $^O eq 'MSWin32'; +if (eof(tst)) { print "not ok 1\n"; } else { print "ok 1\n"; } + +$firstline = <$TST>; +$secondpos = tell; + +$x = 0; +while (<tst>) { + if (eof) {$x++;} +} +if ($x == 1) { print "ok 2\n"; } else { print "not ok 2\n"; } + +$lastpos = tell; + +unless (eof) { print "not ok 3\n"; } else { print "ok 3\n"; } + +if (seek($TST,0,0)) { print "ok 4\n"; } else { print "not ok 4\n"; } + +if (eof) { print "not ok 5\n"; } else { print "ok 5\n"; } + +if ($firstline eq <tst>) { print "ok 6\n"; } else { print "not ok 6\n"; } + +if ($secondpos == tell) { print "ok 7\n"; } else { print "not ok 7\n"; } + +if (seek(tst,0,1)) { print "ok 8\n"; } else { print "not ok 8\n"; } + +if (eof($TST)) { print "not ok 9\n"; } else { print "ok 9\n"; } + +if ($secondpos == tell) { print "ok 10\n"; } else { print "not ok 10\n"; } + +if (seek(tst,0,2)) { print "ok 11\n"; } else { print "not ok 11\n"; } + +if ($lastpos == tell) { print "ok 12\n"; } else { print "not ok 12\n"; } + +unless (eof) { print "not ok 13\n"; } else { print "ok 13\n"; } |