]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/14-callbacks.t
Importing Variable-Magic-0.16.tar.gz
[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 is($@, '',             '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 is($@, '', '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 is($@, '', 'callback returning undef doesn\'t warn/croak');
28 is($x, $n, 'callback returning undef fails');