This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence "smartmatch is experimental" warnings in autodie
[perl5.git] / cpan / autodie / t / exceptions.t
CommitLineData
0b09a93a
PF
1#!/usr/bin/perl -w
2use strict;
3use Test::More;
4
5BEGIN { plan skip_all => "Perl 5.10 only tests" if $] < 5.010; }
6
7# These are tests that depend upon 5.10 (eg, smart-match).
8# Basic tests should go in basic_exceptions.t
9
10use 5.010;
11use constant NO_SUCH_FILE => 'this_file_had_better_not_exist_xyzzy';
3f5e3f2f 12no if $] >= 5.017011, warnings => "experimental::smartmatch";
0b09a93a
PF
13
14plan 'no_plan';
15
16eval {
17 use autodie ':io';
18 open(my $fh, '<', NO_SUCH_FILE);
19};
20
21ok($@, "Exception thrown" );
035fa39e
RGS
22ok($@ ~~ 'open', "Exception from open" );
23ok($@ ~~ ':file', "Exception from open / class :file" );
24ok($@ ~~ ':io', "Exception from open / class :io" );
25ok($@ ~~ ':all', "Exception from open / class :all" );
0b09a93a
PF
26
27eval {
28 no warnings 'once'; # To prevent the following close from complaining.
29 close(THIS_FILEHANDLE_AINT_OPEN);
30};
31
32ok(! $@, "Close without autodie should fail silent");
33
34eval {
35 use autodie ':io';
36 close(THIS_FILEHANDLE_AINT_OPEN);
37};
38
39like($@, qr{Can't close filehandle 'THIS_FILEHANDLE_AINT_OPEN'},"Nice msg from close");
40
41ok($@, "Exception thrown" );
035fa39e
RGS
42ok($@ ~~ 'close', "Exception from close" );
43ok($@ ~~ ':file', "Exception from close / class :file" );
44ok($@ ~~ ':io', "Exception from close / class :io" );
45ok($@ ~~ ':all', "Exception from close / class :all" );
0b09a93a 46