7 BEGIN { $subtests = 3 }
9 use Test::More tests => $subtests * 14;
11 use Perl::Critic::TestUtils qw/pcritique_with_violations/;
13 Perl::Critic::TestUtils::block_perlcriticrc();
15 my $policy = 'Dynamic::NoIndirect';
25 my ($code, $expected) = split /^-+$/m, $_, 2;
26 my @expected = eval $expected;
28 my @violations = eval { pcritique_with_violations($policy, \$code) };
31 diag "Compilation $id failed: $@";
35 for my $v (@violations) {
36 my $exp = shift @expected;
39 fail "Unexpected violation for chunk $id: " . $v->description;
43 my $pos = $v->location;
44 my ($meth, $obj, $line, $col) = @$exp;
47 qr/^Indirect call of method \"\Q$meth\E\" on object \"\Q$obj\E\"/,
49 is $pos->[0], $line, "line $id";
50 is $pos->[1], $col, "column $id";
62 my $x = new X; $x = new X;
64 [ 'new', 'X', 1, 9 ], [ 'new', 'X', 1, 21 ]
68 [ 'new', 'X', 1, 9 ], [ 'new', 'X', 1, 18 ]
73 [ 'new', 'X', 1, 9 ], [ 'new', 'X', 2, 9 ]
78 [ 'new', '$obj', 2, 9 ]
81 my $x = new $obj; $x = new $obj;
83 [ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 2, 24 ]
86 my $x = new $obj new $obj;
88 [ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 2, 21 ]
94 [ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 3, 9 ]