]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - t/40-guard.t
Introduce a scope guard object
[perl/modules/CPANPLUS-Dist-Gentoo.git] / t / 40-guard.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 9;
7
8 use CPANPLUS::Dist::Gentoo::Guard;
9
10 my $called = 0;
11 my $hook = sub { $called++ };
12
13 is $called, 0, 'not called yet';
14 {
15  my $guard = CPANPLUS::Dist::Gentoo::Guard->new($hook);
16  is $called, 0, 'creating the guard doesn\'t call the hook';
17 }
18 is $called, 1, 'called at end of scope';
19
20 $called = 0;
21 is $called, 0, '$called reset';
22 {
23  my $guard = CPANPLUS::Dist::Gentoo::Guard->new($hook);
24  $guard->unarm;
25  is $called, 0, 'unarming the guard doesn\'t call the hook';
26 }
27 is $called, 0, 'not called at end of scope';
28
29 $called = 0;
30 is $called, 0, '$called reset again';
31 {
32  my $guard = CPANPLUS::Dist::Gentoo::Guard->new($hook);
33  $guard->DESTROY;
34  is $called, 1, 'called DESTROY explicitely';
35 }
36 is $called, 1, 'the hook was called only once';