]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - t/40-guard.t
Introduce a scope guard object
[perl/modules/CPANPLUS-Dist-Gentoo.git] / t / 40-guard.t
diff --git a/t/40-guard.t b/t/40-guard.t
new file mode 100644 (file)
index 0000000..954deab
--- /dev/null
@@ -0,0 +1,36 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+
+use CPANPLUS::Dist::Gentoo::Guard;
+
+my $called = 0;
+my $hook = sub { $called++ };
+
+is $called, 0, 'not called yet';
+{
+ my $guard = CPANPLUS::Dist::Gentoo::Guard->new($hook);
+ is $called, 0, 'creating the guard doesn\'t call the hook';
+}
+is $called, 1, 'called at end of scope';
+
+$called = 0;
+is $called, 0, '$called reset';
+{
+ my $guard = CPANPLUS::Dist::Gentoo::Guard->new($hook);
+ $guard->unarm;
+ is $called, 0, 'unarming the guard doesn\'t call the hook';
+}
+is $called, 0, 'not called at end of scope';
+
+$called = 0;
+is $called, 0, '$called reset again';
+{
+ my $guard = CPANPLUS::Dist::Gentoo::Guard->new($hook);
+ $guard->DESTROY;
+ is $called, 1, 'called DESTROY explicitely';
+}
+is $called, 1, 'the hook was called only once';