my ($tests, $reports, $subtests);
BEGIN {
- $tests = 25;
- $reports = 42;
+ $tests = 28;
+ $reports = 43;
$subtests = 3;
}
use Test::More tests => $tests + $subtests * $reports;
-use Perl::Critic::TestUtils qw/pcritique_with_violations/;
+use Perl::Critic::TestUtils qw<pcritique_with_violations>;
Perl::Critic::TestUtils::block_perlcriticrc();
sub zap (&) { }
+TEST:
{
local $/ = "####";
s/^\s+//s;
my ($code, $expected) = split /^-{4,}$/m, $_, 2;
- my @expected = eval $expected;
-
- my @violations = eval { pcritique_with_violations($policy, \$code) };
+ my @expected;
+ {
+ local $@;
+ @expected = eval $expected;
+ if ($@) {
+ diag "Compilation of expected code $id failed: $@";
+ next TEST;
+ }
+ }
- if ($@) {
- diag "Compilation $id failed: $@";
- next;
+ my @violations;
+ {
+ local $@;
+ @violations = eval { pcritique_with_violations($policy, \$code) };
+ if ($@) {
+ diag "Critique test $id failed: $@";
+ next TEST;
+ }
}
is @violations, @expected, "right count of violations $id";
unless ($exp) {
fail "Unexpected violation for chunk $id: " . $v->description;
- next;
+ next TEST;
}
my $pos = $v->location;
----
[ 'new', 'X', 1, 9 ]
####
+use indirect; my $x = new X;
+----
+####
my $x = new X; $x = new X;
----
[ 'new', 'X', 1, 9 ], [ 'new', 'X', 1, 21 ]
[ 'new', 'new', 1, 9 ]
####
our $obj;
+use indirect; my $x = new $obj;
+----
+####
+our $obj;
my $x = new $obj;
----
[ 'new', '$obj', 2, 9 ]
my $x = meh { new $obj } new X;
----
[ 'meh', '{', 2, 9 ], [ 'new', '$obj', 2, 15 ], [ 'new', 'X', 2, 26 ]
+####
+my $x = $invalid_global_when_strict_is_on; new X;
+----
+[ 'new', 'X', 1, 44 ]