1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate require Config; import Config; 7*0Sstevel@tonic-gate if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') { 8*0Sstevel@tonic-gate print "1..0\n"; 9*0Sstevel@tonic-gate exit 0; 10*0Sstevel@tonic-gate } 11*0Sstevel@tonic-gate if ($^O eq 'mpeix') { 12*0Sstevel@tonic-gate print "1..0 # Skip: broken on MPE/iX\n"; 13*0Sstevel@tonic-gate exit 0; 14*0Sstevel@tonic-gate } 15*0Sstevel@tonic-gate} 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gateuse FileHandle; 18*0Sstevel@tonic-gateuse strict subs; 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gateautoflush STDOUT 1; 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gate$mystdout = new_from_fd FileHandle 1,"w"; 23*0Sstevel@tonic-gate$| = 1; 24*0Sstevel@tonic-gateautoflush $mystdout; 25*0Sstevel@tonic-gateprint "1..12\n"; 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gateprint $mystdout "ok ".fileno($mystdout)."\n"; 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate$fh = (new FileHandle "./TEST", O_RDONLY 30*0Sstevel@tonic-gate or new FileHandle "TEST", O_RDONLY) 31*0Sstevel@tonic-gate and print "ok 2\n"; 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate$buffer = <$fh>; 35*0Sstevel@tonic-gateprint $buffer eq "#!./perl\n" ? "ok 3\n" : "not ok 3\n"; 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gateungetc $fh ord 'A'; 39*0Sstevel@tonic-gateCORE::read($fh, $buf,1); 40*0Sstevel@tonic-gateprint $buf eq 'A' ? "ok 4\n" : "not ok 4\n"; 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gateclose $fh; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate$fh = new FileHandle; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gateprint "not " unless ($fh->open("< TEST") && <$fh> eq $buffer); 47*0Sstevel@tonic-gateprint "ok 5\n"; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate$fh->seek(0,0); 50*0Sstevel@tonic-gateprint "#possible mixed CRLF/LF in t/TEST\nnot " unless (<$fh> eq $buffer); 51*0Sstevel@tonic-gateprint "ok 6\n"; 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate$fh->seek(0,2); 54*0Sstevel@tonic-gate$line = <$fh>; 55*0Sstevel@tonic-gateprint "not " if (defined($line) || !$fh->eof); 56*0Sstevel@tonic-gateprint "ok 7\n"; 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gateprint "not " unless ($fh->open("TEST","r") && !$fh->tell && $fh->close); 59*0Sstevel@tonic-gateprint "ok 8\n"; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gateautoflush STDOUT 0; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gateprint "not " if ($|); 64*0Sstevel@tonic-gateprint "ok 9\n"; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gateautoflush STDOUT 1; 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gateprint "not " unless ($|); 69*0Sstevel@tonic-gateprint "ok 10\n"; 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gateif ($^O eq 'dos') 72*0Sstevel@tonic-gate{ 73*0Sstevel@tonic-gate printf("ok %d\n",11); 74*0Sstevel@tonic-gate exit(0); 75*0Sstevel@tonic-gate} 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate($rd,$wr) = FileHandle::pipe; 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gateif ($^O eq 'VMS' || $^O eq 'os2' || $^O eq 'amigaos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || 80*0Sstevel@tonic-gate $Config{d_fork} ne 'define') { 81*0Sstevel@tonic-gate $wr->autoflush; 82*0Sstevel@tonic-gate $wr->printf("ok %d\n",11); 83*0Sstevel@tonic-gate print $rd->getline; 84*0Sstevel@tonic-gate} 85*0Sstevel@tonic-gateelse { 86*0Sstevel@tonic-gate if (fork) { 87*0Sstevel@tonic-gate $wr->close; 88*0Sstevel@tonic-gate print $rd->getline; 89*0Sstevel@tonic-gate } 90*0Sstevel@tonic-gate else { 91*0Sstevel@tonic-gate $rd->close; 92*0Sstevel@tonic-gate $wr->printf("ok %d\n",11); 93*0Sstevel@tonic-gate exit(0); 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate} 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gateprint FileHandle->new('','r') ? "not ok 12\n" : "ok 12\n"; 98