X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-basic.t;h=146c6a1390330f262f09457ef33f89b0ffc7c3d5;hb=6e8dbf3b02e4df3a7304b7acbe47037575fc952d;hp=399e5529516439e531964e572df0a08d3dbb7eda;hpb=953c765f87448964b3818e2617e8186e1545a7e1;p=perl%2Fmodules%2FPerl-Critic-Policy-Dynamic-NoIndirect.git diff --git a/t/10-basic.t b/t/10-basic.t index 399e552..146c6a1 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -5,8 +5,8 @@ use warnings; my ($tests, $reports, $subtests); BEGIN { - $tests = 15; - $reports = 25; + $tests = 28; + $reports = 43; $subtests = 3; } @@ -24,6 +24,9 @@ sub expect { qr/^Indirect call of method \"\Q$meth\E\" on $obj/, } +sub zap (&) { } + +TEST: { local $/ = "####"; @@ -33,13 +36,24 @@ sub expect { 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"; @@ -49,7 +63,7 @@ sub expect { unless ($exp) { fail "Unexpected violation for chunk $id: " . $v->description; - next; + next TEST; } my $pos = $v->location; @@ -69,6 +83,9 @@ my $x = new X; ---- [ '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 ] @@ -102,6 +119,10 @@ my $x = new new; [ 'new', 'new', 1, 9 ] #### our $obj; +use indirect; my $x = new $obj; +---- +#### +our $obj; my $x = new $obj; ---- [ 'new', '$obj', 2, 9 ] @@ -139,3 +160,60 @@ my $x = new $obj; ---- [ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 3, 7 ] +#### +my $x = main::zap { }; +---- +#### +my $x = meh { }; +---- +[ 'meh', '{', 1, 9 ] +#### +my $x = meh { + 1 +}; +---- +[ 'meh', '{', 1, 9 ] +#### +my $x = + meh { 1; 1 + }; +---- +[ 'meh', '{', 2, 2 ] +#### +my $x = meh { + new X; +}; +---- +[ 'meh', '{', 1, 9 ], [ 'new', 'X', 2, 2 ] +#### +our $obj; +my $x = meh { + new $obj; +} +---- +[ 'meh', '{', 2, 9 ], [ 'new', '$obj', 3, 2 ] +#### +my $x = meh { } new + X; +---- +[ 'meh', '{', 1, 9 ], [ 'new', 'X', 1, 17 ] +#### +our $obj; +my $x = meh { } new + $obj; +---- +[ 'meh', '{', 2, 9 ], [ 'new', '$obj', 2, 17 ] +#### +our $obj; +my $x = meh { new X } new $obj; +---- +[ 'meh', '{', 2, 9 ], [ 'new', 'X', 2, 15 ], [ 'new', '$obj', 2, 23 ] +#### +our $obj; +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 ]