From: Vincent Pit Date: Fri, 5 Sep 2008 23:25:13 +0000 (+0200) Subject: Correct backtrace when wizard() croaks, and test it X-Git-Tag: v0.20~17 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=ed119184e2325cba49804db12687cc7b2526b87c;p=perl%2Fmodules%2FVariable-Magic.git Correct backtrace when wizard() croaks, and test it --- diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index ffc67b4..ea1836e 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -277,7 +277,12 @@ sub wizard { push @cbs, 'dup' if MGf_DUP; push @cbs, 'local' if MGf_LOCAL; push @cbs, qw/fetch store exists delete/ if VMG_UVAR; - return _wizard(map $opts{$_}, @cbs); + my $ret = eval { _wizard(map $opts{$_}, @cbs) }; + if (my $err = $@) { + $err =~ s/\sat\s+.*?\n//; + croak $err; + } + return $ret; } =head2 C diff --git a/t/10-simple.t b/t/10-simple.t index 236fc1d..854cdde 100644 --- a/t/10-simple.t +++ b/t/10-simple.t @@ -15,12 +15,12 @@ $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'); + 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\(\)/, 'wizard called with an odd number of arguments croaks'); + 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 $sig = gensig; @@ -49,7 +49,7 @@ 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'); +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'); $res = eval { dispell $a, $sig }; @@ -72,5 +72,5 @@ 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'); +like($@, qr/Invalid\s+numeric\s+signature\s+at\s+\Q$0\E/, 'cast from undef croaks'); is($res, undef, 'cast from undef doesn\'t return anything'); diff --git a/t/12-sig.t b/t/12-sig.t index 636ad7e..662546d 100644 --- a/t/12-sig.t +++ b/t/12-sig.t @@ -25,7 +25,7 @@ my ($a, $b, $c, $d) = 1 .. 4; is($sig, getsig $wiz2, 'retrieved wizard signature is correct'); my $wiz3 = eval { wizard sig => [ ] }; - like($@, qr/Invalid\s+numeric\s+signature/, 'non numeric signature croaks'); + like($@, qr/Invalid\s+numeric\s+signature\s+at\s+\Q$0\E/, 'non numeric signature croaks'); is($wiz3, undef, 'non numeric signature doesn\'t return anything'); my $a = 1; diff --git a/t/13-data.t b/t/13-data.t index d1dc440..94e73e5 100644 --- a/t/13-data.t +++ b/t/13-data.t @@ -54,7 +54,7 @@ is($@, '', 'getdata from invalid sig doesn\'t croak'); is($data, undef, 'getdata from invalid sig returns undef'); $data = eval { getdata $a, undef }; -like($@, qr/Invalid\s+wizard\s+object/, 'getdata from undef croaks'); +like($@, qr/Invalid\s+wizard\s+object\s+at\s+\Q$0\E/, 'getdata from undef croaks'); is($data, undef, 'getdata from undef doesn\'t return anything'); $res = eval { dispell $a, $wiz };