make the namespace cache lazy and weak, in case the stash is deleted
[gitmo/Package-Stash.git] / t / 07-edge-cases.t
index feec31e..acd92e8 100755 (executable)
@@ -3,6 +3,7 @@ use strict;
 use warnings;
 use lib 't/lib';
 use Test::More;
+use Test::Fatal;
 
 use Package::Stash;
 
@@ -47,4 +48,37 @@ ok($stash->has_symbol('%added'), '%added');
 my $constant = $stash->get_symbol('&FOO');
 is(ref($constant), 'CODE', "expanded a constant into a coderef");
 
+# ensure get doesn't prevent subsequent vivification (not sure what the deal
+# was here)
+is(ref($stash->get_symbol('$glob')), '', "nothing yet");
+is(ref($stash->get_or_add_symbol('$glob')), 'SCALAR', "got an empty scalar");
+
+my $Bar = Package::Stash->new('Bar');
+my $foo = 3;
+$foo =~ s/3/4/;
+my $bar = 4.5;
+$bar =~ s/4/5/;
+
+is(exception { $Bar->add_symbol('$foo', \$foo) }, undef,
+   "can add PVIV values");
+is(exception { $Bar->add_symbol('$bar', \$bar) }, undef,
+   "can add PVNV values");
+
+use_ok('CompileTime');
+
+{
+    package Gets::Deleted;
+    sub bar { }
+}
+
+{
+    my $delete = Package::Stash->new('Gets::Deleted');
+    ok($delete->has_symbol('&bar'), "sees the method");
+    {
+        no strict 'refs';
+        delete ${'main::Gets::'}{'Deleted::'};
+    }
+    ok(!$delete->has_symbol('&bar'), "method goes away when stash is deleted");
+}
+
 done_testing;