#!./perl
BEGIN {
chdir 't' if -d 't';
print "1..0 # Skip: not perlio\n";
exit 0;
}
}
$| = 1;
print "1..25\n";
my $fh;
my $var = "ok 2\n";
print "ok 1\n";
print <$fh>;
print "ok 3\n";
print "ok 4\n";
print "ok 5\n";
print "ok 6\n";
print $var;
$var = "foo\nbar\n";
print "ok 8\n";
print "ok 9\n";
if (!$rv) {
print "# Close on scalar failed: $!\n";
print "not ";
}
print "ok 10\n";
# Test that semantics are similar to normal file-based I/O
# Check that ">" clobbers the scalar
$var = "Something";
print "# Got [$var], expect []\n";
print "ok 11\n";
# Check that file offset set to beginning of scalar
print "# Got $off, expect 0\n";
print "ok 12\n";
# Check that writes go where they should and update the offset
$var = "Something";
print $fh "Brea";
print "# Got $off, expect 4\n";
print "ok 13\n";
print "# Got [$var], expect [Breathing]\n";
print "ok 14\n";
# Check that ">>" appends to the scalar
$var = "Something ";
print "# Got $off, expect 10\n";
print "ok 15\n";
print "# Got [$var], expect [Something ]\n";
print "ok 16\n";
# Check that further writes go to the very end of the scalar
$var .= "else ";
print "# Got [$var], expect [Something else ]\n";
print "ok 17\n";
print "# Got $off, expect 10\n";
print "ok 18\n";
print $fh "is here";
print "# Got [$var], expect [Something else is here]\n";
print "ok 19\n";
# Check that updates to the scalar from elsewhere do not
# cause problems
$var = "line one\nline two\line three\n";
while (<$fh>) {
}
print "# Got [$var], expect [foo]\n";
print "ok 20\n";
# Check that dup'ing the handle works
$var = '';
print $fh "ok 21\n";
print $dup "ok 22\n";
while (<$dup>) {
print;
}
# Check reading from non-string scalars
# reading from magic scalars
print <$fh>;
# don't warn when writing to an undefined scalar
{
use warnings;
my $ok = 1;
}