]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/14-callbacks.t
Allow passing ref-to-undef as callbacks to install a noop callback
[perl/modules/Variable-Magic.git] / t / 14-callbacks.t
index ce87f51fec8e2cc99400b4f842a4bf7d303666bf..6a1f56f1e0cc35704a06123ff1843d44a01ae5e0 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 22;
+use Test::More tests => 26;
 
 use Variable::Magic qw<wizard cast>;
 
@@ -65,6 +65,21 @@ is($x, $n, 'callback returning undef fails');
  is($x, $n, 'short string callback returns the right thing');
 }
 
+{
+ my $wiz = eval { wizard get => \undef };
+ is($@, '', 'wizard with a ref-to-undef callback doesn\'t croak');
+ my $b = $n;
+ my $res = eval { cast $b, $wiz };
+ is($@, '', 'cast a wizard with a ref-to-undef callback doesn\'t croak');
+ my $x;
+ eval {
+  local $SIG{__WARN__} = sub { die };
+  $x = $b;
+ };
+ is($@, '', 'ref-to-undef callback doesn\'t warn/croak');
+ is($x, $n, 'ref-to-undef callback returns the right thing');
+}
+
 my @callers;
 $wiz = wizard get => sub {
  my @c;