pjf: dual life modules
[p5sagit/p5-mst-13.2.git] / lib / autodie / t / scope_leak.t
CommitLineData
0b09a93a 1#!/usr/bin/perl -w
2use strict;
3use FindBin;
4
5# Check for %^H leaking across file boundries. Many thanks
6# to chocolateboy for pointing out this can be a problem.
7
8use lib $FindBin::Bin;
9
10use Test::More 'no_plan';
11
12use constant NO_SUCH_FILE => 'this_file_had_better_not_exist';
13use autodie qw(open);
14
15eval {
16 open(my $fh, '<', NO_SUCH_FILE);
17};
18
19ok($@, "basic autodie test");
20
21use autodie_test_module;
22
23# If things don't work as they should, then the file we've
24# just loaded will still have an autodying main::open (although
25# its own open should be unaffected).
26
27eval {
28 leak_test(NO_SUCH_FILE);
29};
30
31is($@,"","autodying main::open should not leak to other files");
32
33eval {
34 autodie_test_module::your_open(NO_SUCH_FILE);
35};
36
37is($@,"","Other package open should be unaffected");
db4e6d09 38
39# Due to odd filenames reported when doing string evals,
40# older versions of autodie would not propogate into string evals.
41
42eval q{
43 open(my $fh, '<', NO_SUCH_FILE);
44};
45
46TODO: {
47 local $TODO = "No known way of propagating into string eval in 5.8"
48 if $] < 5.010;
49
50 ok($@, "Failing-open string eval should throw an exception");
51 isa_ok($@, 'autodie::exception');
52}
53
54eval q{
55 no autodie;
56
57 open(my $fh, '<', NO_SUCH_FILE);
58};
59
60is("$@","","disabling autodie in string context should work");
61
62eval {
63 open(my $fh, '<', NO_SUCH_FILE);
64};
65
66ok($@,"...but shouldn't disable it for the calling code.");
67isa_ok($@, 'autodie::exception');
68
69eval q{
70 no autodie;
71
72 use autodie qw(open);
73
74 open(my $fh, '<', NO_SUCH_FILE);
75};
76
77ok($@,"Wacky flipping of autodie in string eval should work too!");
78isa_ok($@, 'autodie::exception');