From: Jesse Luehrs Date: Fri, 5 Aug 2011 19:41:11 +0000 (-0500) Subject: refactor tests a bit X-Git-Tag: 0.31~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa9c54a31b72a6cc7bdce3efcc27dd010e593564;p=gitmo%2FPackage-Stash.git refactor tests a bit --- diff --git a/t/compile-time.t b/t/compile-time.t new file mode 100644 index 0000000..90debf2 --- /dev/null +++ b/t/compile-time.t @@ -0,0 +1,9 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use lib 't/lib'; +use Test::More; + +use_ok('CompileTime'); + +done_testing; diff --git a/t/edge-cases.t b/t/edge-cases.t index 6bed48e..7c82626 100755 --- a/t/edge-cases.t +++ b/t/edge-cases.t @@ -53,38 +53,4 @@ 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"); -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"); -is(exception { bless \$bar, 'Foo'; $Bar->add_symbol('$bar2', $bar) }, undef, - "can add PVMG values"); -is(exception { $Bar->add_symbol('$baz', qr/foo/) }, undef, - "can add regex values"); -is(exception { undef $bar; $Bar->add_symbol('$quux', \$bar) }, undef, - "can add undef values that aren't NULL"); - -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; diff --git a/t/scalar-values.t b/t/scalar-values.t new file mode 100644 index 0000000..c4e8736 --- /dev/null +++ b/t/scalar-values.t @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use lib 't/lib'; +use Test::More; +use Test::Fatal; + +use B; +use Package::Stash; +use Scalar::Util qw(reftype); +use Symbol; + +my $Bar = Package::Stash->new('Bar'); + +my $pviv = 3; +$pviv =~ s/3/4/; +isa_ok(B::svref_2object(\$pviv), 'B::PVIV'); +is(exception { $Bar->add_symbol('$pviv', \$pviv) }, undef, + "can add PVIV values"); + +my $pvnv = 4.5; +$pvnv =~ s/4/5/; +isa_ok(B::svref_2object(\$pvnv), 'B::PVNV'); +is(exception { $Bar->add_symbol('$pvnv', \$pvnv) }, undef, + "can add PVNV values"); + +my $pvmg = "foo"; +bless \$pvmg, 'Foo'; +isa_ok(B::svref_2object(\$pvmg), 'B::PVMG'); +is(exception { $Bar->add_symbol('$pvmg', \$pvmg) }, undef, + "can add PVMG values"); + +my $regexp = qr/foo/; +isa_ok(B::svref_2object($regexp), 'B::REGEXP'); +is(exception { $Bar->add_symbol('$regexp', $regexp) }, undef, + "can add REGEXP values"); + +my $pvgv = Symbol::gensym; +isa_ok(B::svref_2object($pvgv), 'B::GV'); +isnt(exception { $Bar->add_symbol('$pvgv', $pvgv) }, undef, + "can't add PVGV values"); + +my $pvlv = "foo"; +isa_ok(B::svref_2object(\substr($pvlv, 0, 1)), 'B::PVLV'); +is(exception { $Bar->add_symbol('$pvlv', \substr($pvlv, 0, 1)) }, undef, + "can add PVLV values"); + +my $vstring = v1.2.3; +is(reftype(\$vstring), 'VSTRING'); +is(exception { $Bar->add_symbol('$vstring', \$vstring) }, undef, + "can add vstring values"); + +done_testing; diff --git a/t/stash-deletion.t b/t/stash-deletion.t new file mode 100644 index 0000000..e331234 --- /dev/null +++ b/t/stash-deletion.t @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use lib 't/lib'; +use Test::More; + +use Package::Stash; + +{ + 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;