Skip to content

Commit

Permalink
PerlIO::scalar: tests for trailing null
Browse files Browse the repository at this point in the history
using Eric Brine’s function.
  • Loading branch information
Father Chrysostomos committed Jan 20, 2012
1 parent 84da560 commit 66ad6b0
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ext/PerlIO-scalar/t/scalar.t
Expand Up @@ -16,7 +16,7 @@ use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END); # Not 0, 1, 2 everywhere.

$| = 1;

use Test::More tests => 76;
use Test::More tests => 79;

my $fh;
my $var = "aaa\n";
Expand Down Expand Up @@ -318,6 +318,7 @@ EOF
pass 'seeking on a glob copy from the end';
}

# [perl #108398]
sub has_trailing_nul(\$) {
my ($ref) = @_;
my $sv = B::svref_2object($ref);
Expand All @@ -331,3 +332,25 @@ sub has_trailing_nul(\$) {
my $trailing = unpack 'P', pack 'J', $pv_addr+$cur;
return $trailing eq "\0";
}
SKIP: {
if ($Config::Config{'extensions'} !~ m!\bPerlIO/scalar\b!) {
skip "no B", 1;
}
require B;

open my $fh, ">", \my $memfile or die $!;

print $fh "abc";
ok has_trailing_nul $memfile,
'write appends trailing null when growing string';

seek $fh, 0,SEEK_SET;
print $fh "abc";
ok has_trailing_nul $memfile,
'write appends trailing null when not growing string';

seek $fh, 200, SEEK_SET;
print $fh "abc";
ok has_trailing_nul $memfile,
'write appends null when growing string after seek past end';
}

0 comments on commit 66ad6b0

Please sign in to comment.