9 use Test::More tests => (1 + $tests + 1) + 3 + 3 + 3 + 5 + 1;
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 \d+\)';
18 qr/^warn:Indirect call of method "new" on object "$pkg" at $file line \d+/;
22 my $code = do { local $/; <DATA> };
23 my (%res, $num, @left);
26 local $SIG{__WARN__} = sub {
28 my $w = join '', 'warn:', @_;
29 if ($w =~ /"P(\d+)"/ and not exists $res{$1}) {
32 push @left, "[$num] $w";
37 is $@, '', 'DATA compiled fine';
42 like $w, expect("P$_"), "$_ should warn";
44 is $w, undef, "$_ shouldn't warn";
48 is @left, 0, 'nothing left';
49 diag "Extraneous warnings:\n", @left if @left;
55 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
56 eval 'return; no indirect; my $x = new Foo';
58 is $@, '', "eval 'no indirect; my \$x = new Foo'";
59 is @w, 1, 'got one warning';
60 diag join "\n", 'All warnings:', @w if @w > 1;
61 like $w[0], expect('Foo'), 'correct warning';
67 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
70 eval 'return; my $x = new Bar';
73 is $@, '', "no indirect; eval 'my \$x = new Bar'";
75 is @w, 0, 'no warnings caught';
78 is @w, 1, 'got one warning';
79 diag join "\n", 'All warnings:', @w if @w > 1;
80 like $w[0], expect('Bar'), 'correct warning';
87 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
88 eval "return; no indirect; use indirect::TestRequired1; my \$x = new Foo;";
90 is $@, '', 'first require test doesn\'t croak prematurely';
91 is @w, 1, 'first require threw only one warning';
92 diag join "\n", 'All warnings:', @w if @w > 1;
93 like $w[0], expect('Foo'), 'first require test catch errors in current scope';
99 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
100 eval "return; no indirect; use indirect::TestRequired2; my \$x = new Bar;";
102 is $@, '', 'second require test doesn\'t croak prematurely';
103 @w = grep !/^warn:Attempt\s+to\s+free\s+unreferenced/, @w if $] <= 5.008003;
105 like $w, expect('Baz', 't/lib/indirect/TestRequired2.pm'),
106 'second require test caught error for Baz';
108 skip 'The pragma doesn\'t propagte into eval STRING before perl 5.10' => 1
111 like $w, expect('Blech'), 'second require test caught error for Blech';
114 like $w, expect('Bar'), 'second require test caught error for Bar';
115 is_deeply \@w, [ ], 'second require test doesn\'t have more errors';
121 no indirect ':fatal';
122 use indirect::Test1::il1 ();
123 use indirect::Test1::il2 ();
125 is $@, '', 'RT #47902';
156 eval { my $i = new P9 };
159 eval { no indirect; my $j = new P10 };
163 new P11 do { use indirect; new P12 };
168 new P13 do { no indirect; new P14 };
173 new P15 do { use indirect; new P16 };
178 new P17 do { no indirect; new P18 };