X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-simple.t;h=1617fdc997b152ee97779423b1acbbd4d06e2066;hb=e8a50f8f820a7aa610721b06af9251468a635e6b;hp=1fdefcd61aa3e8b418e9863eecf5cd38b0b2b229;hpb=20763a0bc2e3d1987ead055b78ef2481aa18514c;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/10-simple.t b/t/10-simple.t index 1fdefcd..1617fdc 100644 --- a/t/10-simple.t +++ b/t/10-simple.t @@ -3,11 +3,13 @@ use strict; use warnings; -use Test::More tests => 46; +use Test::More tests => 48; use Variable::Magic qw/wizard gensig getsig cast dispell MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/; -my $args = 7; +my $inv_wiz_obj = qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/; + +my $args = 8; ++$args if MGf_COPY; ++$args if MGf_DUP; ++$args if MGf_LOCAL; @@ -25,14 +27,18 @@ for (0 .. 3) { my $sig = gensig; +my $a = 1; +my $res = eval { cast $a, $sig }; +like($@, $inv_wiz_obj, 'cast from wrong sig croaks'); +is($res, undef, 'cast from wrong sig doesn\'t return anything'); + my $wiz = eval { wizard sig => $sig }; is($@, '', 'wizard doesn\'t croak'); ok(defined $wiz, 'wizard is defined'); is(ref $wiz, 'SCALAR', 'wizard is a scalar ref'); is($sig, getsig $wiz, 'wizard signature is correct'); -my $a = 1; -my $res = eval { cast $a, $wiz }; +$res = eval { cast $a, $wiz }; is($@, '', 'cast doesn\'t croak'); ok($res, 'cast is valid'); @@ -45,12 +51,12 @@ is($@, '', 're-cast doesn\'t croak'); ok($res, 're-cast is valid'); $res = eval { dispell $a, gensig }; -is($@, '', 're-dispell from wrong sig doesn\'t croak'); -is($res, undef, 're-dispell from wrong sig doesn\'t return anything'); +like($@, $inv_wiz_obj, 're-dispell from wrong sig croaks'); +is($res, undef, 're-dispell from wrong sig doesn\'t return anything'); $res = eval { dispell $a, undef }; -like($@, qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/, 're-dispell from undef croaks'); -is($res, undef, 're-dispell from undef doesn\'t return anything'); +like($@, $inv_wiz_obj, 're-dispell from undef croaks'); +is($res, undef, 're-dispell from undef doesn\'t return anything'); $res = eval { dispell $a, $sig }; is($@, '', 're-dispell from good sig doesn\'t croak'); @@ -68,9 +74,9 @@ $sig = gensig; } my $c = 3; $res = eval { cast $c, $sig }; -is($@, '', 'cast from obsolete signature doesn\'t croak'); -is($res, undef, 'cast from obsolete signature returns undef'); +like($@, $inv_wiz_obj, 'cast from obsolete signature croaks'); +is($res, undef, 'cast from obsolete signature returns undef'); $res = eval { cast $c, undef }; -like($@, qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/, 'cast from undef croaks'); -is($res, undef, 'cast from undef doesn\'t return anything'); +like($@, $inv_wiz_obj, 'cast from undef croaks'); +is($res, undef, 'cast from undef doesn\'t return anything');