#!perl -T
-package Dongs;
+package NotEmpty;
sub new;
use strict;
use warnings;
-use Test::More tests => 3 * 4;
+use Test::More tests => 3 * 9;
+
+BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} }
sub meh;
+my @warns;
+
+sub try {
+ my ($code) = @_;
+
+ @warns = ();
+ {
+ local $SIG{__WARN__} = sub { push @warns, @_ };
+ eval $code;
+ }
+}
+
{
- local $/ = "####\n";
+ local $/ = "####";
while (<DATA>) {
chomp;
s/\s*$//;
- local $SIG{__WARN__} = sub { die 'warn:' . join(' ', @_) };
- {
- use indirect;
- eval "die qq{ok\\n}; $_";
- }
- is($@, "ok\n", "use indirect: $_");
- {
- no indirect;
- eval "die qq{ok\n}; $_";
- }
- is($@, "ok\n", "no indirect: $_");
- s/Hlagh/Dongs/g;
- {
- use indirect;
- eval "die qq{ok\\n}; $_";
- }
- is($@, "ok\n", "use indirect, defined: $_");
+ s/(.*?)$//m;
+ my ($skip, $prefix) = split /#+/, $1;
+ $skip = 0 unless defined $skip;
+ $prefix = '' unless defined $prefix;
+ s/\s*//;
+
+SKIP:
{
- no indirect;
- eval "die qq{the code compiled but it shouldn't have\n}; $_";
+ skip "$_: $skip" => 9 if do { local $@; eval $skip };
+
+ {
+ local $_ = $_;
+ s/Pkg/Empty/g;
+
+ try "return; $prefix; use indirect; $_";
+ is $@, '', "use indirect: $_";
+ is @warns, 0, 'correct number of reports';
+
+ try "return; $prefix; no indirect; $_";
+ is $@, '', "no indirect: $_";
+ is @warns, 0, 'correct number of reports';
+ }
+
+ {
+ local $_ = $_;
+ s/Pkg/NotEmpty/g;
+
+ try "return; $prefix; use indirect; $_";
+ is $@, '', "use indirect, defined: $_";
+ is @warns, 0, 'correct number of reports';
+
+ try "return; $prefix; no indirect; $_";
+ is $@, '', "use indirect, defined: $_";
+ is @warns, 1, 'correct number of reports';
+ like $warns[0], qr/^Indirect call of method "meh" on object "NotEmpty" at \(eval \d+\) line \d+/, 'report 0 is correct';
+ }
}
- like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"meh"\s+on\s+object\s+"Dongs"/, "no indirect, defined: $_");
}
}
__DATA__
-meh Hlagh->new;
+
+meh Pkg->new;
####
-meh Hlagh->new();
+meh Pkg->new();
####
-meh Hlagh->new, "Wut";
+meh Pkg->new, "Wut";