X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-basic.t;h=399e5529516439e531964e572df0a08d3dbb7eda;hb=953c765f87448964b3818e2617e8186e1545a7e1;hp=abf5a3d2b64eb3844c2146593e06ad46d6bd54c6;hpb=c2e8dfbf550e0a15ff415a698c806e1fc8ca03fe;p=perl%2Fmodules%2FPerl-Critic-Policy-Dynamic-NoIndirect.git diff --git a/t/10-basic.t b/t/10-basic.t index abf5a3d..399e552 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -3,10 +3,14 @@ use strict; use warnings; -my $subtests; -BEGIN { $subtests = 3 } +my ($tests, $reports, $subtests); +BEGIN { + $tests = 15; + $reports = 25; + $subtests = 3; +} -use Test::More tests => $subtests * 14; +use Test::More tests => $tests + $subtests * $reports; use Perl::Critic::TestUtils qw/pcritique_with_violations/; @@ -14,6 +18,12 @@ Perl::Critic::TestUtils::block_perlcriticrc(); 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 $/ = "####"; @@ -22,7 +32,7 @@ my $policy = 'Dynamic::NoIndirect'; while () { 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) }; @@ -32,6 +42,8 @@ my $policy = 'Dynamic::NoIndirect'; next; } + is @violations, @expected, "right count of violations $id"; + for my $v (@violations) { my $exp = shift @expected; @@ -43,9 +55,7 @@ my $policy = 'Dynamic::NoIndirect'; 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"; } @@ -67,11 +77,30 @@ my $x = new X new X; ---- [ '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', 'X', 1, 9 ], [ 'new', 'X', 2, 9 ] #### +my $x = new + X; +---- +[ 'new', 'X', 1, 9 ] +#### +my $x = new + X new + X; +---- +[ 'new', 'X', 1, 9 ], [ 'new', 'X', 2, 4 ] +#### +my $x = new new; +---- +[ 'new', 'new', 1, 9 ] +#### our $obj; my $x = new $obj; ---- @@ -87,9 +116,26 @@ my $x = new $obj new $obj; ---- [ '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; ---- [ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 3, 9 ] - +#### +our $obj; +my $x = new + $obj; +---- +[ 'new', '$obj', 2, 9 ] +#### +our $obj; +my $x = new + $obj new + $obj; +---- +[ 'new', '$obj', 2, 9 ], [ 'new', '$obj', 3, 7 ]