summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorBen Morrow <ben@morrow.me.uk>2009-01-05 17:31:54 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-06-21 13:32:33 +0200
commitd018fae575c7e183deffddccedc84f1f5d7ddacb (patch)
tree0d32cd42d51431c450df588c28e36d7546ef064f /t
parent3f1788e11f2685299067ac0f8d3e4fd141a5b5cd (diff)
downloadperl-d018fae575c7e183deffddccedc84f1f5d7ddacb.tar.gz
Tests for deleting stash entries.
Diffstat (limited to 't')
-rw-r--r--t/op/stash.t86
1 files changed, 82 insertions, 4 deletions
diff --git a/t/op/stash.t b/t/op/stash.t
index 4d8bc7c54d..e2f8901011 100644
--- a/t/op/stash.t
+++ b/t/op/stash.t
@@ -7,7 +7,7 @@ BEGIN {
BEGIN { require "./test.pl"; }
-plan( tests => 13 );
+plan( tests => 30 );
# Used to segfault (bug #15479)
fresh_perl_is(
@@ -58,6 +58,84 @@ ok( !eval q{ defined %schoenmaker:: }, 'works in eval("")' );
# now tests with strictures
-use strict;
-ok( !defined %pig::, q(referencing a non-existent stash doesn't produce stricture errors) );
-ok( !exists $pig::{bodine}, q(referencing a non-existent stash element doesn't produce stricture errors) );
+{
+ use strict;
+ ok( !defined %pig::, q(referencing a non-existent stash doesn't produce stricture errors) );
+ ok( !exists $pig::{bodine}, q(referencing a non-existent stash element doesn't produce stricture errors) );
+}
+
+SKIP: {
+ eval { require B; 1 } or skip "no B", 12;
+
+ *b = \&B::svref_2object;
+ my $CVf_ANON = B::CVf_ANON();
+
+ my $sub = do {
+ package one;
+ \&{"one"};
+ };
+ delete $one::{one};
+ my $gv = b($sub)->GV;
+
+ isa_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
+ is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
+ is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
+ is( eval { $gv->STASH->NAME }, "one", "...but leaves stash intact");
+
+ $sub = do {
+ package two;
+ \&{"two"};
+ };
+ %two:: = ();
+ $gv = b($sub)->GV;
+
+ isa_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
+ is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
+ is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
+ is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
+
+ $sub = do {
+ package three;
+ \&{"three"};
+ };
+ undef %three::;
+ $gv = b($sub)->GV;
+
+ isa_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
+ is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
+ is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
+ is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
+
+ TODO: {
+ local $TODO = "anon CVs not accounted for yet";
+
+ $sub = do {
+ package four;
+ sub { 1 };
+ };
+ %four:: = ();
+ $gv = b($sub)->GV;
+
+ isa_ok( $gv, "B::GV", "cleared stash leaves anon CV with valid GV");
+ is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
+
+ $sub = do {
+ package five;
+ sub { 1 };
+ };
+ undef %five::;
+ $gv = b($sub)->GV;
+
+ isa_ok( $gv, "B::GV", "undefed stash leaves anon CV with valid GV");
+ is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
+ }
+
+ # [perl #58530]
+ fresh_perl_is(
+ 'sub foo { 1 }; use overload q/""/ => \&foo;' .
+ 'delete $main::{foo}; bless []',
+ "",
+ {},
+ "no segfault with overload/deleted stash entry [#58530]",
+ );
+}