]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/12-sig.t
Importing Variable-Magic-0.10.tar.gz
[perl/modules/Variable-Magic.git] / t / 12-sig.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 24;
7
8 use Variable::Magic qw/wizard getsig cast dispell SIG_MIN/;
9
10 my $sig = 300;
11
12 my ($a, $b, $c, $d) = 1 .. 4;
13
14 {
15  my $wiz = eval { wizard sig => $sig };
16  ok(!$@, "wizard creation error ($@)");
17  ok(defined $wiz, 'wizard is defined');
18  ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref');
19  ok($sig == getsig $wiz, 'wizard signature is correct');
20
21  my $wiz2 = eval { wizard sig => $sig };
22  ok(!$@, "wizard retrieve error ($@)");
23  ok(defined $wiz2, 'retrieved wizard is defined');
24  ok(ref $wiz2 eq 'SCALAR', 'retrieved wizard is a scalar ref');
25  ok($sig == getsig $wiz2, 'retrieved wizard signature is correct');
26
27  my $a = 1;
28  my $res = eval { cast $a, $wiz };
29  ok(!$@, "cast from wizard croaks ($@)");
30  ok($res, 'cast from wizard invalid');
31
32  $res = eval { dispell $a, $wiz2 };
33  ok(!$@, "dispell from retrieved wizard croaks ($@)");
34  ok($res, 'dispell from retrieved wizard invalid');
35
36  $res = eval { cast $b, $sig };
37  ok(!$@, "cast from integer croaks ($@)");
38  ok($res, 'cast from integer invalid');
39 }
40
41 my $res = eval { cast $c, $sig + 0.1 };
42 ok(!$@, "cast from float croaks ($@)");
43 ok($res, 'cast from float invalid');
44
45 $res = eval { cast $d, sprintf "%u", $sig };
46 ok(!$@, "cast from string croaks ($@)");
47 ok($res, 'cast from string invalid');
48
49 $res = eval { dispell $b, $sig };
50 ok(!$@, "dispell from integer croaks ($@)");
51 ok($res, 'dispell from integer invalid');
52
53 $res = eval { dispell $c, $sig + 0.1 };
54 ok(!$@, "dispell from float croaks ($@)");
55 ok($res, 'dispell from float invalid');
56
57 $res = eval { dispell $d, sprintf "%u", $sig };
58 ok(!$@, "dispell from string croaks ($@)");
59 ok($res, 'dispell from string invalid');
60