Test loading during global destruction
Dagfinn Ilmari Mannsåker [Thu, 24 Oct 2013 22:02:43 +0000 (23:02 +0100)]
dist.ini
t/global_destruction_load.t [new file with mode: 0644]
t/lib/TryUser.pm [new file with mode: 0644]

index 4ed975c..f468c64 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -22,6 +22,11 @@ Git::NextVersion_version_regexp = ^Try-Tiny-(.+)$
 skip = ^perl$
 ; tests for optional Sub::Name stuff
 skip = ^Sub::Name$
+; tests optionally require Capture::Tiny
+skip = ^Capture::Tiny$
 
 [Prereqs]
 perl = 5.006
+
+[Prereqs / TestRecommends]
+Capture::Tiny = 0.12 ; capture_stderr
diff --git a/t/global_destruction_load.t b/t/global_destruction_load.t
new file mode 100644 (file)
index 0000000..acf3a8c
--- /dev/null
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+    plan skip_all => 'Capture::Tiny required'
+        unless eval { require Capture::Tiny; 1 };
+    plan tests => 3;
+    Capture::Tiny->import(qw(capture_stderr));
+}
+
+for my $func (qw(try catch finally)) {
+    is capture_stderr {
+        system $^X, qw(-It/lib -we),
+            qq{sub DESTROY { require TryUser; TryUser->test_$func }} .
+             q{our $o; $o = bless []};
+    }, '', "$func gets installed when loading Try::Tiny during global destruction";
+}
diff --git a/t/lib/TryUser.pm b/t/lib/TryUser.pm
new file mode 100644 (file)
index 0000000..c44d36b
--- /dev/null
@@ -0,0 +1,9 @@
+package TryUser;
+
+use Try::Tiny;
+
+sub test_try { try { } }
+sub test_catch { try { } catch { } }
+sub test_finally { try { } finally { } }
+
+1;