]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/14-callbacks.t
Importing Variable-Magic-0.10.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 ok(!$@, "wizard creation error ($@)");
12 ok(defined $wiz, 'wizard is defined');
13 ok(ref $wiz eq '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 croaks ($@)");
20 ok($res, 'cast invalid');
21
22 my $x;
23 eval {
24  local $SIG{__WARN__} = sub { die };
25  $x = $a
26 };
27 ok(!$@, 'callback returning undef croaks');
28 ok(defined($x) && ($x == $n), 'callback returning undef fails');