]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/lib/Variable/Magic/TestWatcher.pm
Properly unmortalize the wizard after removing it from the global hash
[perl/modules/Variable-Magic.git] / t / lib / Variable / Magic / TestWatcher.pm
index a8b5297d11ece058169c62ad8e76c943762080ab..bcbd67e5987ffa91d6c85268df2a72c19c1b1add 100644 (file)
@@ -10,7 +10,7 @@ use Variable::Magic qw/wizard/;
 
 use base qw/Exporter/;
 
-our @EXPORT = qw/init check/;
+our @EXPORT = qw/init_watcher watch/;
 
 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,16 +37,22 @@ 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 = ();
  local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1;
- my @ret = eval { $code->() };
+ if (defined $want and 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;