my @data = ();
require './test.pl';
-plan(tests => 41);
+plan(tests => 63);
sub compare {
+ local $Level = $Level + 1;
+
return unless @expect;
return ::fail() unless(@_ == @expect);
3;
}
+sub EOF {
+ ::compare(EOF => @_);
+ @data ? '' : 1;
+}
+
sub WRITE {
::compare(WRITE => @_);
$data = substr($_[1],$_[3] || 0, $_[2]);
sub CLOSE {
::compare(CLOSE => @_);
-
5;
}
$r = printf $fh @expect[2,3];
is($r, 2);
-$text = (@data = ("the line\n"))[0];
+@data = ("the line\n");
+@expect = (EOF => $ob, 1);
+is(eof($fh), '');
+
+$text = $data[0];
@expect = (READLINE => $ob);
$ln = <$fh>;
is($ln, $text);
+@expect = (EOF => $ob, 0);
+is(eof, 1);
+
@expect = ();
@in = @data = qw(a line at a time);
@line = <$fh>;
}
{
+ package Bar::Say;
+ use feature 'say';
+ use base qw(Implement);
+
+ my $ors;
+ sub PRINT {
+ $ors = $\;
+ my $self = shift;
+ return $self->SUPER::PRINT(@_);
+ }
+
+ my $fh = Symbol::gensym;
+ @expect = (TIEHANDLE => 'Bar::Say');
+ ::ok( my $obj = tie *$fh, 'Bar::Say' );
+
+ local $\ = 'something';
+ @expect = (PRINT => $obj, "stuff", "and", "things");
+ ::ok( print $fh @expect[2..4] );
+ ::is( $ors, 'something' );
+
+ ::ok( say $fh @expect[2..4] );
+ ::is( $ors, "\n", 'say sets $\ to \n in PRINT' );
+ ::is( $\, "something", " and it's localized" );
+}
+
+{
# Test for change #11536
package Foo;
use strict;
sub READLINE { "foobar\n" }
}
-
+{
+ # make sure the new eof() features work with @ARGV magic
+ local *ARGV;
+ @ARGV = ('haha');
+
+ @expect = (TIEHANDLE => 'Implement');
+ $ob = tie *ARGV, 'Implement';
+ is(ref($ob), 'Implement');
+ is(tied(*ARGV), $ob);
+
+ @data = ("stuff\n");
+ @expect = (EOF => $ob, 1);
+ is(eof(ARGV), '');
+ @expect = (EOF => $ob, 2);
+ is(eof(), '');
+ shift @data;
+ @expect = (EOF => $ob, 0);
+ is(eof, 1);
+}