]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/14-callbacks.t
dffb6d957ba7729b383815e1005258b3142612a0
[perl/modules/Variable-Magic.git] / t / 14-callbacks.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 7;
7
8 use Variable::Magic qw/wizard cast/;
9
10 my $wiz = eval { wizard get => sub { undef } };
11 ok(!$@, "wizard creation doesn't croak ($@)");
12 ok(defined $wiz, 'wizard is defined');
13 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
14
15 my $n = int rand 1000;
16 my $a = $n;
17
18 my $res = eval { cast $a, $wiz };
19 ok(!$@, "cast doesn't croak ($@)");
20 ok($res, 'cast is valid');
21
22 my $x;
23 eval {
24  local $SIG{__WARN__} = sub { die };
25  $x = $a
26 };
27 ok(!$@, 'callback returning undef doesn\'t warn/croak');
28 is($x, $n, 'callback returning undef fails');