actually, this isn't our fault, this is just generic 5.8 brokenness
[gitmo/Package-Stash.git] / t / edge-cases.t
index 7c82626..49f56ed 100755 (executable)
@@ -26,8 +26,8 @@ use Package::Stash;
 }
 
 my $stash = Package::Stash->new('Foo');
-{ local $TODO = ($] < 5.010 || $Package::Stash::IMPLEMENTATION eq 'PP')
-      ? "undef scalars aren't visible on 5.8, or from pure perl at all"
+{ local $TODO = $] < 5.010
+      ? "undef scalars aren't visible on 5.8"
       : undef;
 ok($stash->has_symbol('$SCALAR'), '$SCALAR');
 }
@@ -53,4 +53,38 @@ is(ref($constant), 'CODE', "expanded a constant into a coderef");
 is(ref($stash->get_symbol('$glob')), '', "nothing yet");
 is(ref($stash->get_or_add_symbol('$glob')), 'SCALAR', "got an empty scalar");
 
+SKIP: {
+    skip "PP doesn't support anon stashes before 5.14", 4
+        if $] < 5.014 && $Package::Stash::IMPLEMENTATION eq 'PP';
+    local $TODO = "don't know how to properly inflate a stash entry";
+
+    my $anon = {}; # not using Package::Anon
+    $anon->{foo} = -1;     # stub
+    $anon->{bar} = '$&';   # stub with prototype
+    $anon->{baz} = \"foo"; # constant
+
+    my $stash = Package::Stash->new($anon);
+    is(
+        exception {
+            is(ref($stash->get_symbol('&foo')), 'CODE',
+               "stub expanded into a glob");
+            is(ref($stash->get_symbol('&bar')), 'CODE',
+               "stub with prototype expanded into a glob");
+            is(ref($stash->get_symbol('&baz')), 'CODE',
+               "constant expanded into a glob");
+        },
+        undef,
+        "can call get_symbol on weird stash entries"
+    );
+}
+
+{
+    my $warning;
+    local $SIG{__WARN__} = sub { $warning = $_[0] };
+    my $stash = Package::Stash->new('Bar');
+    $stash->add_symbol('&foo' => sub { });
+    $stash->add_symbol('&foo' => sub { });
+    is($warning, undef, "no redefinition warnings");
+}
+
 done_testing;