X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-simple.t;h=99136bddb1dd0c960dcd1b5c7ea7d045c467e2eb;hb=refs%2Ftags%2Fv0.09;hp=becb24fd76aab326580c6d61b04327046b92c7ac;hpb=77a84f75f33e3ee44e61182dec76699e23025375;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/10-simple.t b/t/10-simple.t index becb24f..99136bd 100644 --- a/t/10-simple.t +++ b/t/10-simple.t @@ -1,6 +1,9 @@ #!perl -T -use Test::More tests => 12; +use strict; +use warnings; + +use Test::More tests => 16; use Variable::Magic qw/wizard gensig getsig cast dispell/; @@ -12,20 +15,34 @@ ok(defined $wiz, 'wizard is defined'); ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref'); ok($sig == getsig $wiz, 'wizard signature is correct'); -my $a = 0; +my $a = 1; my $res = eval { cast $a, $wiz }; -ok(!$@, "cast error 1 ($@)"); -ok($res, 'cast error 2'); +ok(!$@, "cast croaks ($@)"); +ok($res, 'cast invalid'); $res = eval { dispell $a, $wiz }; -ok(!$@, "dispell from wizard error 1 ($@)"); -ok($res, 'dispell from wizard error 2'); +ok(!$@, "dispell from wizard croaks ($@)"); +ok($res, 'dispell from wizard invalid'); $res = eval { cast $a, $wiz }; -ok(!$@, "re-cast error 1 ($@)"); -ok($res, 're-cast error 2'); - -$res = eval { dispell $a, $sig }; -ok(!$@, "dispell from signature error 1 ($@)"); -ok($res, 'dispell from signature error 2'); +ok(!$@, "re-cast croaks ($@)"); +ok($res, 're-cast invalid'); +$res = eval { dispell $a, $wiz }; +ok(!$@, "re-dispell croaks ($@)"); +ok($res, 're-dispell invalid'); + +$res = eval { dispell my $b, $wiz }; +ok(!$@, "dispell non-magic object fails ($@)"); +ok($res == 0, 'dispell non-magic object doesn\'t return 0'); + +$sig = gensig; +{ + my $wiz = wizard sig => $sig; + my $b = 2; + my $res = cast $b, $wiz; +} +my $c = 3; +$res = eval { cast $c, $sig }; +ok(!$@, "cast from obsolete signature croaks ($@)"); +ok(!defined($res), 'cast from obsolete signature returns undef');