]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/lib/Variable/Magic/TestWatcher.pm
Protect $@ inside Variable::Magic::TestWatcher::init_watcher
[perl/modules/Variable-Magic.git] / t / lib / Variable / Magic / TestWatcher.pm
index 672ae12599e92946a99d6bc74e604ed7a9d87bf6..a8499226e06232d82de7b5ca2d67492b4149e143 100644 (file)
@@ -5,12 +5,12 @@ use warnings;
 
 use Test::More;
 
-use Carp qw/croak/;
-use Variable::Magic qw/wizard/;
+use Carp qw<croak>;
+use Variable::Magic qw<wizard>;
 
-use base qw/Exporter/;
+use base qw<Exporter>;
 
-our @EXPORT = qw/init check/;
+our @EXPORT = qw<init_watcher watch>;
 
 sub _types {
  my $t = shift;
@@ -24,10 +24,11 @@ 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;
+ local $@;
  %mg  = ();
  $wiz = eval 'wizard ' . join(', ', map {
   "$_ => sub { \$mg{$_}++;" . ($_ eq 'len' ? '$_[2]' : '0') . '}'
@@ -37,7 +38,7 @@ sub init ($;$) {
  return $wiz;
 }
 
-sub check (&;$$) {
+sub watch (&;$$) {
  my $code = shift;
  my $exp  = _types shift;
  my $desc = shift;
@@ -45,7 +46,10 @@ sub check (&;$$) {
  my @ret;
  local %mg = ();
  local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1;
- if (defined $want and not $want) { # scalar context
+ local $@;
+ if (not defined $want) { # void context
+  eval { $code->() };
+ } elsif (not $want) { # scalar context
   $ret[0] = eval { $code->() };
  } else {
   @ret = eval { $code->() };