summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-01-19 18:25:53 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-01-19 22:38:36 -0800
commit66ad6b0e59b2bd380bf0a09a63b25d333de52323 (patch)
treed6c205a6658040fa498ba6b91aac5a601c160169
parent84da5602d79c53542bee8b70ec90a6130da1175e (diff)
downloadperl-66ad6b0e59b2bd380bf0a09a63b25d333de52323.tar.gz
PerlIO::scalar: tests for trailing null
using Eric Brine’s function.
-rw-r--r--ext/PerlIO-scalar/t/scalar.t25
1 files changed, 24 insertions, 1 deletions
diff --git a/ext/PerlIO-scalar/t/scalar.t b/ext/PerlIO-scalar/t/scalar.t
index 48883b6a78..ccf66dd9e8 100644
--- a/ext/PerlIO-scalar/t/scalar.t
+++ b/ext/PerlIO-scalar/t/scalar.t
@@ -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";
@@ -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);
@@ -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';
+}