9 use Test::More tests => (1 + $tests + 1) + 3 + 3 + 3 + 5 + 1;
11 BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
15 my %wrong = map { $_ => 1 } 2, 3, 5, 7, 9, 10, 14, 15, 17, 18;
18 my ($pkg, $file) = @_;
19 $file = $file ? quotemeta $file : '\(eval \d+\)';
20 qr/^warn:Indirect call of method "new" on object "$pkg" at $file line \d+/;
24 my $code = do { local $/; <DATA> };
25 my (%res, $num, @left);
28 local $SIG{__WARN__} = sub {
30 my $w = join '', 'warn:', @_;
31 if ($w =~ /"P(\d+)"/ and not exists $res{$1}) {
34 push @left, "[$num] $w";
39 is $@, '', 'DATA compiled fine';
44 like $w, expect("P$_"), "$_ should warn";
46 is $w, undef, "$_ shouldn't warn";
50 is @left, 0, 'nothing left';
51 diag "Extraneous warnings:\n", @left if @left;
57 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
58 eval 'return; no indirect; my $x = new Foo';
60 is $@, '', "eval 'no indirect; my \$x = new Foo'";
61 is @w, 1, 'got one warning';
62 diag join "\n", 'All warnings:', @w if @w > 1;
63 like $w[0], expect('Foo'), 'correct warning';
69 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
72 eval 'return; my $x = new Bar';
75 is $@, '', "no indirect; eval 'my \$x = new Bar'";
77 is @w, 0, 'no warnings caught';
80 is @w, 1, 'got one warning';
81 diag join "\n", 'All warnings:', @w if @w > 1;
82 like $w[0], expect('Bar'), 'correct warning';
89 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
90 eval "return; no indirect; use indirect::TestRequired1; my \$x = new Foo;";
92 is $@, '', 'first require test doesn\'t croak prematurely';
93 is @w, 1, 'first require threw only one warning';
94 diag join "\n", 'All warnings:', @w if @w > 1;
95 like $w[0], expect('Foo'), 'first require test catch errors in current scope';
101 local $SIG{__WARN__} = sub { push @w, join '', 'warn:', @_ };
102 eval "return; no indirect; use indirect::TestRequired2; my \$x = new Bar;";
104 is $@, '', 'second require test doesn\'t croak prematurely';
105 @w = grep !/^warn:Attempt\s+to\s+free\s+unreferenced/, @w if $] <= 5.008003;
107 like $w, expect('Baz', 't/lib/indirect/TestRequired2.pm'),
108 'second require test caught error for Baz';
110 skip 'The pragma doesn\'t propagte into eval STRING before perl 5.10' => 1
113 like $w, expect('Blech'), 'second require test caught error for Blech';
116 like $w, expect('Bar'), 'second require test caught error for Bar';
117 is_deeply \@w, [ ], 'second require test doesn\'t have more errors';
123 no indirect ':fatal';
124 use indirect::Test1::il1 ();
125 use indirect::Test1::il2 ();
127 is $@, '', 'RT #47902';
158 eval { my $i = new P9 };
161 eval { no indirect; my $j = new P10 };
165 new P11 do { use indirect; new P12 };
170 new P13 do { no indirect; new P14 };
175 new P15 do { use indirect; new P16 };
180 new P17 do { no indirect; new P18 };