git-flavoured autodie 1.997 patch
[p5sagit/p5-mst-13.2.git] / t / lib / autodie / filehandles.t
1 #!/usr/bin/perl -w
2
3 package main;
4
5 use strict;
6 use Test::More;
7
8 # We may see failures with package filehandles if Fatal/autodie
9 # incorrectly pulls out a cached subroutine from a different package.
10
11 # We're using Fatal because package filehandles are likely to
12 # see more use with Fatal than autodie.
13
14 use Fatal qw(open);
15
16 eval {
17     open(FILE, '<', $0);
18 };
19
20
21 if ($@) {
22     # Holy smokes!  We couldn't even open our own file, bail out...
23
24     plan skip_all => q{Can't open $0 for filehandle tests}
25 }
26
27 plan tests => 4;
28
29 my $line = <FILE>;
30
31 like($line, qr{perl}, 'Looks like we opened $0 correctly');
32
33 close(FILE);
34
35 package autodie::test;
36 use Test::More;
37
38 use Fatal qw(open);
39
40 eval {
41     open(FILE2, '<', $0);
42 };
43
44 is($@,"",'Opened $0 in autodie::test');
45
46 my $line2 = <FILE2>;
47
48 like($line2, qr{perl}, '...and we can read from $0 fine');
49
50 close(FILE2);
51
52 package main;
53
54 # This shouldn't read anything, because FILE2 should be inside
55 # autodie::test
56
57 no warnings;    # Otherwise we see problems with FILE2
58 my $wrong_line = <FILE2>;
59
60 ok(! defined($wrong_line),q{Filehandles shouldn't leak between packages});