13 sub ok { print "not " unless shift; print "ok ",$test++,"\n"; }
17 BEGIN { *ok = \*main::ok }
20 return unless @expect;
21 return ok(0) unless(@_ == @expect);
24 for($i = 0 ; $i < @_ ; $i++) {
25 next if $_[$i] eq $expect[$i];
33 compare(TIEHANDLE => @_);
34 my ($class,@val) = @_;
35 return bless \@val,$class;
44 compare(PRINTF => @_);
49 compare(READLINE => @_);
50 wantarray ? @data : shift @data;
60 substr($_[1],$_[3] || 0) = substr($data,0,$_[2]);
66 $data = substr($_[1],$_[3] || 0, $_[2]);
84 @expect = (TIEHANDLE => 'Implement');
85 my $ob = tie *$fh,'Implement';
86 ok(ref($ob) eq 'Implement');
87 ok(tied(*$fh) == $ob);
89 @expect = (PRINT => $ob,"some","text");
90 $r = print $fh @expect[2,3];
93 @expect = (PRINTF => $ob,"%s","text");
94 $r = printf $fh @expect[2,3];
97 $text = (@data = ("the line\n"))[0];
98 @expect = (READLINE => $ob);
103 @in = @data = qw(a line at a time);
106 Implement::compare(@line);
108 @expect = (GETC => $ob);
114 @expect = (READ => $ob, $buf, 3);
116 $r = read $fh,$buf,3;
122 @expect = (READ => $ob, $buf, 3,3);
124 $r = sysread $fh,$buf,3,3;
126 ok($buf eq "xyzabc");
129 @expect = (WRITE => $ob, $buf, 4,1);
131 $r = syswrite $fh,$buf,4,1;
136 @expect = (WRITE => $ob, $buf, 4);
138 $r = syswrite $fh,$buf,4;
143 @expect = (WRITE => $ob, $buf, 6);
145 $r = syswrite $fh,$buf;
147 ok($data eq "qwerty");
149 @expect = (CLOSE => $ob);
153 # Does aliasing work with tied FHs?
155 @expect = (PRINT => $ob,"some","text");
156 $r = print ALIAS @expect[2,3];
161 # Special case of aliasing STDERR, which used
162 # to dump core when warnings were enabled
164 @expect = (PRINT => $ob,"some","text");
165 $r = print STDERR @expect[2,3];