X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2Flib%2FVariable%2FMagic%2FTestWatcher.pm;h=98a4b08b85d279ac1e64fd9cd8936519c13fb792;hb=b34eec5b227be170f3cf8efdb8aaae400370960b;hp=ef988d18075554466b53ad3ee7307ff050784360;hpb=9345c3acac8d56b421b1d53b2d800294b77e9ad6;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/t/lib/Variable/Magic/TestWatcher.pm b/t/lib/Variable/Magic/TestWatcher.pm index ef988d1..98a4b08 100644 --- a/t/lib/Variable/Magic/TestWatcher.pm +++ b/t/lib/Variable/Magic/TestWatcher.pm @@ -5,12 +5,12 @@ use warnings; use Test::More; -use Carp qw/croak/; -use Variable::Magic qw/wizard/; +use Carp qw; +use Variable::Magic qw; -use base qw/Exporter/; +use base qw; -our @EXPORT = qw/init check/; +our @EXPORT = qw; sub _types { my $t = shift; @@ -24,7 +24,7 @@ sub _types { our ($wiz, $prefix, %mg); -sub init ($;$) { +sub init_watcher ($;$) { croak 'can\'t initialize twice' if defined $wiz; my $types = _types shift; $prefix = (defined) ? "$_: " : '' for shift; @@ -37,15 +37,25 @@ sub init ($;$) { return $wiz; } -sub check (&;$$) { +sub watch (&;$$) { my $code = shift; my $exp = _types shift; my $desc = shift; + my $want = wantarray; + my @ret; local %mg = (); - my @ret = eval { $code->() }; + local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1; + local $@; + if (not defined $want) { # void context + eval { $code->() }; + } elsif (not $want) { # scalar context + $ret[0] = eval { $code->() }; + } else { + @ret = eval { $code->() }; + } is $@, '', $prefix . $desc . ' doesn\'t croak'; is_deeply \%mg, $exp, $prefix . $desc . ' triggers magic correctly'; - return @ret; + return $want ? @ret : $ret[0]; } our $mg_end;