9 use Test::More tests => 1 + $tests + 1 + 2 + 3 + 5;
13 my %wrong = map { $_ => 1 } 2, 3, 5, 7, 9, 10, 14, 15, 17, 18;
16 my ($pkg, $file) = @_;
17 $file = $file ? quotemeta $file : '\(eval\s+\d+\)';
18 return qr/^warn:Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+$file\s+line\s+\d+/;
22 my $code = do { local $/; <DATA> };
23 my (%res, $num, @left);
25 local $SIG{__WARN__} = sub {
27 my $w = join '', 'warn:', @_;
28 if ($w =~ /"P(\d+)"/ and not exists $res{$1}) {
31 push @left, "[$num] $w";
34 eval "die qq{ok\\n}; $code";
35 is($@, "ok\n", 'DATA compiled fine');
40 like($w, expect("P$_"), "$_ should warn");
42 is($w, undef, "$_ shouldn't warn");
45 is(@left, 0, 'nothing left');
46 diag "Extraneous warnings:\n", @left if @left;
51 local $SIG{__WARN__} = sub {
52 $w = 'more than 2 warnings' if $w;
53 $w = join '', 'warn:', @_
56 eval 'no indirect; my $x = new Foo';
57 like($w, expect('Foo'), "eval 'no indirect; my \$x = new Foo'");
63 eval 'my $x = new Bar';
66 is($w, '', "eval 'no indirect; my \$x = new Bar'");
68 like($w, expect('Bar'), "no indirect; eval 'my \$x = new Bar'");
76 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
77 eval "die qq{ok\\n}; no indirect; use indirect::TestRequired1; my \$x = new Foo;";
79 is $@, "ok\n", 'first require test doesn\'t croak prematurely';
81 like $w, expect('Foo'), 'first require test catch errors in current scope';
82 is_deeply \@w, [ ], 'first require test doesn\'t propagate into the required file';
88 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
89 eval "die qq{ok\\n}; no indirect; use indirect::TestRequired2; my \$x = new Bar;";
91 @w = grep !/^warn:Attempt\s+to\s+free\s+unreferenced/, @w if $] <= 5.008003;
92 is $@, "ok\n", 'second require test doesn\'t croak prematurely';
94 like $w, expect('Baz', 't/lib/indirect/TestRequired2.pm'),
95 'second require test caught error for Baz';
97 skip 'The pragma doesn\'t propagte into eval STRING before perl 5.10' => 1
100 like $w, expect('Blech'), 'second require test caught error for Blech';
103 like $w, expect('Bar'), 'second require test caught error for Bar';
104 is_deeply \@w, [ ], 'second require test doesn\'t have more errors';
135 eval { my $i = new P9 };
138 eval { no indirect; my $j = new P10 };
142 new P11 do { use indirect; new P12 };
147 new P13 do { no indirect; new P14 };
152 new P15 do { use indirect; new P16 };
157 new P17 do { no indirect; new P18 };