summaryrefslogtreecommitdiff
path: root/cpan/autodie/t/exceptions.t
diff options
context:
space:
mode:
Diffstat (limited to 'cpan/autodie/t/exceptions.t')
-rwxr-xr-xcpan/autodie/t/exceptions.t45
1 files changed, 45 insertions, 0 deletions
diff --git a/cpan/autodie/t/exceptions.t b/cpan/autodie/t/exceptions.t
new file mode 100755
index 0000000000..2f8c2382fc
--- /dev/null
+++ b/cpan/autodie/t/exceptions.t
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -w
+use strict;
+use Test::More;
+
+BEGIN { plan skip_all => "Perl 5.10 only tests" if $] < 5.010; }
+
+# These are tests that depend upon 5.10 (eg, smart-match).
+# Basic tests should go in basic_exceptions.t
+
+use 5.010;
+use constant NO_SUCH_FILE => 'this_file_had_better_not_exist_xyzzy';
+
+plan 'no_plan';
+
+eval {
+ use autodie ':io';
+ open(my $fh, '<', NO_SUCH_FILE);
+};
+
+ok($@, "Exception thrown" );
+ok($@ ~~ 'open', "Exception from open" );
+ok($@ ~~ ':file', "Exception from open / class :file" );
+ok($@ ~~ ':io', "Exception from open / class :io" );
+ok($@ ~~ ':all', "Exception from open / class :all" );
+
+eval {
+ no warnings 'once'; # To prevent the following close from complaining.
+ close(THIS_FILEHANDLE_AINT_OPEN);
+};
+
+ok(! $@, "Close without autodie should fail silent");
+
+eval {
+ use autodie ':io';
+ close(THIS_FILEHANDLE_AINT_OPEN);
+};
+
+like($@, qr{Can't close filehandle 'THIS_FILEHANDLE_AINT_OPEN'},"Nice msg from close");
+
+ok($@, "Exception thrown" );
+ok($@ ~~ 'close', "Exception from close" );
+ok($@ ~~ ':file', "Exception from close / class :file" );
+ok($@ ~~ ':io', "Exception from close / class :io" );
+ok($@ ~~ ':all', "Exception from close / class :all" );
+