]> git.vpit.fr Git - perl/modules/Variable-Temp.git/blob - t/12-destroy.t
This is 0.04
[perl/modules/Variable-Temp.git] / t / 12-destroy.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Variable::Temp 'set_temp';
7
8 use Test::More tests => 16;
9
10 use lib 't/lib';
11 use VPIT::TestHelpers;
12
13 my $x_is_destroyed       = 0;
14 my $x_temp1_is_destroyed = 0;
15 my $x_temp2_is_destroyed = 0;
16
17 {
18  my $x = VPIT::TestHelpers::Guard->new(sub {
19   is $x_temp1_is_destroyed, 1;
20   is $x_temp2_is_destroyed, 1;
21   ++$x_is_destroyed;
22  });
23  is $x_is_destroyed, 0;
24
25  set_temp $x => VPIT::TestHelpers::Guard->new(sub {
26   is $x_is_destroyed,       0;
27   is $x_temp2_is_destroyed, 1;
28   ++$x_temp1_is_destroyed;
29  });
30  is $x_is_destroyed,       0;
31  is $x_temp1_is_destroyed, 0;
32  is $x_temp2_is_destroyed, 0;
33
34  set_temp $x => VPIT::TestHelpers::Guard->new(sub {
35   is $x_is_destroyed,       0;
36   is $x_temp1_is_destroyed, 0;
37   ++$x_temp2_is_destroyed;
38  });
39  is $x_is_destroyed,       0;
40  is $x_temp1_is_destroyed, 0;
41  is $x_temp2_is_destroyed, 0;
42 }
43
44 is $x_is_destroyed,       1;
45 is $x_temp1_is_destroyed, 1;
46 is $x_temp2_is_destroyed, 1;