Revision 267b9e4f
Von Sven Schöling vor etwa 13 Jahren hinzugefügt
t/structure/no_lexicals_in_postif.t | ||
---|---|---|
1 |
use strict; |
|
2 |
|
|
3 |
use lib 't'; |
|
4 |
|
|
5 |
use Support::Files; |
|
6 |
|
|
7 |
use Test::More tests => scalar(@Support::Files::testitems); |
|
8 |
use PPI; |
|
9 |
|
|
10 |
my $fh; |
|
11 |
{ |
|
12 |
local $^W = 0; # Don't complain about non-existent filehandles |
|
13 |
if (-e \*Test::More::TESTOUT) { |
|
14 |
$fh = \*Test::More::TESTOUT; |
|
15 |
} elsif (-e \*Test::Builder::TESTOUT) { |
|
16 |
$fh = \*Test::Builder::TESTOUT; |
|
17 |
} else { |
|
18 |
$fh = \*STDOUT; |
|
19 |
} |
|
20 |
} |
|
21 |
|
|
22 |
my @testitems = @Support::Files::testitems; |
|
23 |
|
|
24 |
foreach my $file (@testitems) { |
|
25 |
my $clean = 1; |
|
26 |
my $doc = PPI::Document->new($file); |
|
27 |
my $stmts = $doc->find('Statement::Variable'); |
|
28 |
|
|
29 |
for my $var (@{ $stmts || [] }) { |
|
30 |
# local can have valid uses like this, and our is extremely uncommon |
|
31 |
next unless $var->type eq 'my'; |
|
32 |
|
|
33 |
# no if? alright |
|
34 |
next unless $var->find(sub { $_[1]->content eq 'if' }); |
|
35 |
|
|
36 |
# token "if" is not in the top level struvture - no problem |
|
37 |
# most likely an anonymous sub or a complicated map/grep/reduce |
|
38 |
next unless grep { $_->content eq 'if' } $var->schildren; |
|
39 |
|
|
40 |
$clean = 0; |
|
41 |
print $fh "?: $var \n"; |
|
42 |
} |
|
43 |
|
|
44 |
ok $clean, $file; |
|
45 |
} |
Auch abrufbar als: Unified diff
Testcase, der alle Vorkommnisse von my $var = EXPR if COND; findet.