X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-simple.t;h=1692b44a8616f35ae9064a6670207588ad4145b8;hb=ae89b589d2187cf0ed57bbb6132b9d4a8da29abb;hp=becb24fd76aab326580c6d61b04327046b92c7ac;hpb=77a84f75f33e3ee44e61182dec76699e23025375;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/10-simple.t b/t/10-simple.t index becb24f..1692b44 100644 --- a/t/10-simple.t +++ b/t/10-simple.t @@ -1,31 +1,62 @@ #!perl -T -use Test::More tests => 12; +use strict; +use warnings; -use Variable::Magic qw/wizard gensig getsig cast dispell/; +use Test::More tests => 43; -my $sig = gensig; +use Variable::Magic qw; -my $wiz = eval { wizard sig => $sig }; -ok(!$@, "wizard creation error ($@)"); -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 $inv_wiz_obj = qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/; + +my $args = 9; +++$args if MGf_LOCAL; +$args += 5 if VMG_UVAR; +for (0 .. 20) { + next if $_ == $args; + eval { Variable::Magic::_wizard(('hlagh') x $_) }; + like($@, qr/Wrong\s+number\s+of\s+arguments\s+at\s+\Q$0\E/, '_wizard called directly with a wrong number of arguments croaks'); +} + +for (0 .. 3) { + eval { wizard(('dong') x (2 * $_ + 1)) }; + like($@, qr/Wrong\s+number\s+of\s+arguments\s+for\s+&?wizard\(\)\s+at\s+\Q$0\E/, 'wizard called with an odd number of arguments croaks'); +} + +my $wiz = eval { wizard }; +is($@, '', 'wizard doesn\'t croak'); +ok(defined $wiz, 'wizard is defined'); +is(ref $wiz, 'SCALAR', 'wizard is a scalar ref'); -my $a = 0; my $res = eval { cast $a, $wiz }; -ok(!$@, "cast error 1 ($@)"); -ok($res, 'cast error 2'); +is($@, '', 'cast doesn\'t croak'); +ok($res, 'cast is valid'); $res = eval { dispell $a, $wiz }; -ok(!$@, "dispell from wizard error 1 ($@)"); -ok($res, 'dispell from wizard error 2'); +is($@, '', 'dispell from wizard doesn\'t croak'); +ok($res, 'dispell from wizard is valid'); $res = eval { cast $a, $wiz }; -ok(!$@, "re-cast error 1 ($@)"); -ok($res, 're-cast error 2'); +is($@, '', 're-cast doesn\'t croak'); +ok($res, 're-cast is valid'); + +$res = eval { dispell $a, \"blargh" }; +like($@, $inv_wiz_obj, 're-dispell from wrong wizard croaks'); +is($res, undef, 're-dispell from wrong wizard doesn\'t return anything'); + +$res = eval { dispell $a, undef }; +like($@, $inv_wiz_obj, 're-dispell from undef croaks'); +is($res, undef, 're-dispell from undef doesn\'t return anything'); + +$res = eval { dispell $a, $wiz }; +is($@, '', 're-dispell from good wizard doesn\'t croak'); +ok($res, 're-dispell from good wizard is valid'); -$res = eval { dispell $a, $sig }; -ok(!$@, "dispell from signature error 1 ($@)"); -ok($res, 'dispell from signature error 2'); +$res = eval { dispell my $b, $wiz }; +is($@, '', 'dispell non-magic object doesn\'t croak'); +is($res, 0, 'dispell non-magic object returns 0'); +my $c = 3; +$res = eval { cast $c, undef }; +like($@, $inv_wiz_obj, 'cast from undef croaks'); +is($res, undef, 'cast from undef doesn\'t return anything');