X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-basic.t;h=55215c40110bc19d09d86893aa21b60d45224aea;hb=ef89faf5a36a866b83462cad90209f9cc68a7e41;hp=a1b1885751979264c9d691fc8de2340506b76e35;hpb=754541e0583f7da9be1ea92f0ea96be44b65cfaa;p=perl%2Fmodules%2FPerl-Critic-Policy-Dynamic-NoIndirect.git diff --git a/t/10-basic.t b/t/10-basic.t index a1b1885..55215c4 100644 --- a/t/10-basic.t +++ b/t/10-basic.t @@ -3,13 +3,14 @@ use strict; use warnings; -my ($tests, $subtests); +my ($tests, $reports, $subtests); BEGIN { - $tests = 8; + $tests = 25; + $reports = 42; $subtests = 3; } -use Test::More tests => $tests + $subtests * 14; +use Test::More tests => $tests + $subtests * $reports; use Perl::Critic::TestUtils qw/pcritique_with_violations/; @@ -17,6 +18,14 @@ 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/, +} + +sub zap (&) { } + { local $/ = "####"; @@ -25,7 +34,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) }; @@ -48,9 +57,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"; } @@ -72,11 +79,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; ---- @@ -92,9 +118,79 @@ 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 ] +#### +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 ]