X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-simple.t;h=236fc1d73485a15072d0faa289a1a4cc2e015f32;hb=c471e8c9f86ad8817761816101358f8ae1035915;hp=37d348e9f0b56a0c0b5b6cec9bab4bee3302e530;hpb=8556481280524737222300317146a23b801f6be0;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/10-simple.t b/t/10-simple.t index 37d348e..236fc1d 100644 --- a/t/10-simple.t +++ b/t/10-simple.t @@ -1,33 +1,64 @@ #!perl -T -use Test::More tests => 14; +use strict; +use warnings; -use Variable::Magic qw/wizard gensig getsig cast dispell/; +use Test::More tests => 46; + +use Variable::Magic qw/wizard gensig getsig cast dispell MGf_COPY MGf_DUP MGf_LOCAL VMG_UVAR/; + +my $args = 7; +++$args if MGf_COPY; +++$args if MGf_DUP; +++$args if MGf_LOCAL; +$args += 4 if VMG_UVAR; +for (0 .. 20) { + next if $_ == $args; + eval { Variable::Magic::_wizard(('hlagh') x $_) }; + like($@, qr/Wrong\s+number\s+of\s+arguments/, '_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\(\)/, 'wizard called with an odd number of arguments croaks'); +} my $sig = gensig; 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'); +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 }; -ok(!$@, "cast croaks ($@)"); -ok($res, 'cast invalid'); +is($@, '', 'cast doesn\'t croak'); +ok($res, 'cast is valid'); $res = eval { dispell $a, $wiz }; -ok(!$@, "dispell from wizard croaks ($@)"); -ok($res, 'dispell from wizard invalid'); +is($@, '', 'dispell from wizard doesn\'t croak'); +ok($res, 'dispell from wizard is valid'); $res = eval { cast $a, $wiz }; -ok(!$@, "re-cast croaks ($@)"); -ok($res, 're-cast invalid'); +is($@, '', 're-cast doesn\'t croak'); +ok($res, 're-cast is valid'); -$res = eval { dispell $a, $wiz }; -ok(!$@, "re-dispell croaks ($@)"); -ok($res, 're-dispell invalid'); +$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'); + +$res = eval { dispell $a, undef }; +like($@, qr/Invalid\s+wizard\s+object/, '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'); +ok($res, 're-dispell from good sig is valid'); + +$res = eval { dispell my $b, $wiz }; +is($@, '', 'dispell non-magic object doesn\'t croak'); +is($res, 0, 'dispell non-magic object returns 0'); $sig = gensig; { @@ -37,5 +68,9 @@ $sig = gensig; } my $c = 3; $res = eval { cast $c, $sig }; -ok(!$@, "cast from obsolete signature croaks ($@)"); -ok(!defined($res), 'cast from obsolete signature returns undef'); +is($@, '', 'cast from obsolete signature doesn\'t croak'); +is($res, undef, 'cast from obsolete signature returns undef'); + +$res = eval { cast $c, undef }; +like($@, qr/Invalid\s+numeric\s+signature/, 'cast from undef croaks'); +is($res, undef, 'cast from undef doesn\'t return anything');