From: Vincent Pit Date: Mon, 23 Mar 2009 14:24:38 +0000 (+0100) Subject: More stash tests for functions/methods X-Git-Tag: v0.33~5 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Magic.git;a=commitdiff_plain;h=9998c368f87b94cfd7218aeb8f265947f6e6d8e1 More stash tests for functions/methods --- diff --git a/t/35-stash.t b/t/35-stash.t index a1b6a7d..dc66fa6 100644 --- a/t/35-stash.t +++ b/t/35-stash.t @@ -9,7 +9,7 @@ use Variable::Magic qw/wizard cast dispell VMG_UVAR VMG_OP_INFO_NAME VMG_OP_INFO my $run; if (VMG_UVAR) { - plan tests => 13; + plan tests => 23; $run = 1; } else { plan skip_all => 'uvar magic is required to test symbol table hooks'; @@ -56,35 +56,110 @@ cast %Hlagh::, $wiz; }, 'stash: variables'; } +{ + local %mg; + + eval q[ + die "ok\n"; + package Hlagh; + sub eat; + sub shoot; + sub leave { "bye" }; + sub shoot { "bang" }; + ]; + + is $@, "ok\n", 'stash: function definitions compiled fine'; + is_deeply \%mg, { + store => [ qw/eat shoot leave shoot/ ], + }, 'stash: function definitions'; +} + { local %mg; eval q{ die "ok\n"; package Hlagh; - foo(); - bar(); - foo(); + eat(); + shoot(); + leave(); + roam(); + yawn(); + roam(); }; is $@, "ok\n", 'stash: function calls compiled fine'; is_deeply \%mg, { - fetch => [ qw/foo bar foo/ ], - store => [ qw/foo bar foo/ ], + fetch => [ qw/eat shoot leave roam yawn roam/ ], + store => [ qw/eat shoot leave roam yawn roam/ ], }, 'stash: function calls'; } +{ + local %mg; + + eval q{ Hlagh->shoot() }; + + is $@, '', 'stash: valid method call ran fine'; + is_deeply \%mg, { + fetch => [ qw/shoot/ ], + }, 'stash: valid method call'; +} + +{ + local %mg; + + eval q[ + package Hlagher; + our @ISA; + BEGIN { @ISA = 'Hlagh' } + Hlagher->shoot() + ]; + + is $@, '', 'inherited valid method call ran fine'; + is_deeply \%mg, { + fetch => [ qw/ISA shoot/ ], + }, 'stash: direct method call'; +} + +{ + local %mg; + + eval q{ Hlagh->unknown() }; + + like $@, qr/^Can't locate object method "unknown" via package "Hlagh"/, 'stash: invalid method call croaked'; + is_deeply \%mg, { + fetch => [ qw/unknown/ ], + store => [ qw/unknown AUTOLOAD/ ], + }, 'stash: invalid method call'; +} + +{ + local %mg; + + eval q{ Hlagher->also_unknown() }; + + like $@, qr/^Can't locate object method "also_unknown" via package "Hlagher"/, 'stash: invalid inherited method call croaked'; + is_deeply \%mg, { + fetch => [ qw/also_unknown AUTOLOAD/ ], + }, 'stash: invalid method call'; +} + { local %mg; eval q{ package Hlagh; - undef &foo; + undef &nevermentioned; + undef &eat; + undef &shoot; }; is $@, '', 'stash: delete executed fine'; is_deeply \%mg, { - store => [ qw/foo foo foo/ ], + store => [ + qw/nevermentioned nevermentioned eat eat shoot shoot nevermentioned/ + ], }, 'stash: delete'; }