X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F33-code.t;h=a2d6711c2ff0af41ce60de4c21e74d7db10ccfa7;hb=HEAD;hp=da26dc6b8721ffe9dff6a5c7c6bd4c2cf9f18bb7;hpb=582d5acf296ae639bf0bca66bfbba842b745a637;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/33-code.t b/t/33-code.t index da26dc6..a2d6711 100644 --- a/t/33-code.t +++ b/t/33-code.t @@ -3,44 +3,56 @@ use strict; use warnings; -use Test::More tests => 2 * 10 + 9 + 1; +use Test::More tests => 2 * 12 + 11 + 1; -use Variable::Magic qw/cast dispell/; +use Variable::Magic qw; use lib 't/lib'; use Variable::Magic::TestWatcher; -my $wiz = init - [ qw/get set len clear free copy dup local fetch store exists delete/ ], +my $wiz = init_watcher + [ qw ], 'code'; my $x = 0; sub hlagh { ++$x }; -check { cast &hlagh, $wiz } { }, 'cast'; +watch { cast &hlagh, $wiz } { }, 'cast'; is $x, 0, 'code: cast didn\'t called code'; -check { hlagh() } { }, 'call without arguments'; +watch { hlagh() } { }, 'call without arguments'; is $x, 1, 'code: call without arguments succeeded'; -check { hlagh(1, 2, 3) } { }, 'call with arguments'; +watch { hlagh(1, 2, 3) } { }, 'call with arguments'; is $x, 2, 'code: call with arguments succeeded'; -check { undef *hlagh } { free => 1 }, 'undef symbol table entry'; +watch { undef *hlagh } { free => 1 }, 'undef symbol table entry'; is $x, 2, 'code: undef symbol table entry didn\'t call code'; my $y = 0; -check { *hlagh = sub { ++$y } } { }, 'redefining sub'; +watch { *hlagh = sub { ++$y } } { }, 'redefining sub'; -check { cast &hlagh, $wiz } { }, 're-cast'; +watch { cast &hlagh, $wiz } { }, 're-cast'; is $y, 0, 'code: re-cast didn\'t called code'; -my ($r) = check { \&hlagh } { }, 'reference'; +my ($r) = watch { \&hlagh } { }, 'reference'; is $y, 0, 'code: reference didn\'t called code'; -check { $r->() } { }, 'call reference'; +watch { $r->() } { }, 'call reference'; is $y, 1, 'code: call reference succeeded'; is $x, 2, 'code: call reference didn\'t called the previous code'; -check { dispell &hlagh, $wiz } { }, 'dispell'; -is $y, 1, 'code: dispell didn\'t called code'; +my $z = 0; +watch { + no warnings 'redefine'; + *hlagh = sub { ++$z } +} { }, 'redefining sub 2'; + +watch { hlagh() } { }, 'call without arguments 2'; +is $z, 1, 'code: call without arguments 2 succeeded'; +is $y, 1, 'code: call without arguments 2 didn\'t called the previous code'; + +watch { dispell &hlagh, $wiz } { }, 'dispell'; +is $z, 1, 'code: dispell didn\'t called code'; + +$Variable::Magic::TestWatcher::mg_end = { free => 1 };