use strict;
use warnings;
-my ($tests, $subtests);
+my ($tests, $reports, $subtests);
BEGIN {
- $tests = 13;
+ $tests = 15;
+ $reports = 25;
$subtests = 3;
}
-use Test::More tests => $tests + $subtests * 21;
+use Test::More tests => $tests + $subtests * $reports;
use Perl::Critic::TestUtils qw/pcritique_with_violations/;
my $policy = 'Dynamic::NoIndirect';
+sub expect {
+ my ($meth, $obj) = @_;
+ $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\"";
+ qr/^Indirect call of method \"\Q$meth\E\" on $obj/,
+}
+
{
local $/ = "####";
while (<DATA>) {
s/^\s+//s;
- my ($code, $expected) = split /^-+$/m, $_, 2;
+ my ($code, $expected) = split /^-{4,}$/m, $_, 2;
my @expected = eval $expected;
my @violations = eval { pcritique_with_violations($policy, \$code) };
my $pos = $v->location;
my ($meth, $obj, $line, $col) = @$exp;
- like $v->description,
- qr/^Indirect call of method \"\Q$meth\E\" on object \"\Q$obj\E\"/,
- "description $id";
+ like $v->description, expect($meth, $obj), "description $id";
is $pos->[0], $line, "line $id";
is $pos->[1], $col, "column $id";
}
----
[ 'new', 'X', 1, 9 ], [ 'new', 'X', 1, 18 ]
####
+my $x = new X new Y;
+----
+[ 'new', 'X', 1, 9 ], [ 'new', 'Y', 1, 18 ]
+####
my $x = new X;
my $y = new X;
----
----
[ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 2, 21 ]
####
+our ($o1, $o2);
+my $x = new $o1 new $o2;
+----
+[ 'new', '$o1', 2, 9 ], [ 'new', '$o2', 2, 21 ]
+####
our $obj;
my $x = new $obj;
my $y = new $obj;