7 if ( ( $Config::Config{'extensions'} !~ /\bB\b/ ) ) {
8 print "1..0 # Skip -- Perl configured without B module\n";
18 # Runs a separate perl interpreter with the appropriate lint options
21 my ( $opts, $prog, $result, $testname ) = @_;
23 switches => ["-MO=Lint,$opts"],
27 $res =~ s/-e syntax OK\n$//;
28 local $::Level = $::Level + 1;
29 is( $res, $result, $testname || $opts );
32 runlint 'magic-diamond', 'while(<>){}', <<'RESULT';
33 Use of <> at -e line 1
36 runlint 'magic-diamond', 'while(<ARGV>){}', <<'RESULT';
37 Use of <> at -e line 1
40 runlint 'magic-diamond', 'while(<FOO>){}', <<'RESULT';
43 runlint 'context', '$foo = @bar', <<'RESULT';
44 Implicit scalar context for array in scalar assignment at -e line 1
47 runlint 'context', '$foo = length @bar', <<'RESULT';
48 Implicit scalar context for array in length at -e line 1
51 runlint 'context', 'our @bar', '';
53 runlint 'context', 'exists $BAR{BAZ}', '';
55 runlint 'implicit-read', '/foo/', <<'RESULT';
56 Implicit match on $_ at -e line 1
59 runlint 'implicit-read', 'grep /foo/, ()', '';
61 runlint 'implicit-read', 'grep { /foo/ } ()', '';
63 runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
64 Implicit substitution on $_ at -e line 1
67 runlint 'implicit-read', 'for ( @ARGV ) { 1 }',
68 <<'RESULT', 'implicit-read in foreach';
69 Implicit use of $_ in foreach at -e line 1
72 runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach';
74 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
75 Use of $_ at -e line 1
78 runlint 'dollar-underscore', 'sub foo {}; foo( $_ ) for @A', '';
79 runlint 'dollar-underscore', 'sub foo {}; map { foo( $_ ) } @A', '';
80 runlint 'dollar-underscore', 'sub foo {}; grep { foo( $_ ) } @A', '';
82 runlint 'dollar-underscore', 'print',
83 <<'RESULT', 'dollar-underscore in print';
84 Use of $_ at -e line 1
87 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
88 Illegal reference to private name '_f' at -e line 1
91 runlint 'private-names', '$A::_x', <<'RESULT';
92 Illegal reference to private name '_x' at -e line 1
95 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
96 Illegal reference to private method name '_f' at -e line 1
98 'private-names (method)';
100 runlint 'undefined-subs', 'foo()', <<'RESULT';
101 Nonexistant subroutine 'foo' called at -e line 1
104 runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT';
105 Undefined subroutine 'foo' called at -e line 1
108 runlint 'regexp-variables', 'print $&', <<'RESULT';
109 Use of regexp variable $& at -e line 1
112 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
113 Use of regexp variable $& at -e line 1
116 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
118 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
119 Bare sub name 'bare' interpreted as string at -e line 1
120 Bare sub name 'bare' interpreted as string at -e line 1
125 # Check for backwards-compatible plugin support. This was where
126 # preloaded mdoules would register themselves with B::Lint.
128 switches => ["-MB::Lint"],
130 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
133 like( $res, qr/X ok\./, 'Lint legacy plugin' );
138 # Check for Module::Plugin support
140 switches => [ '-It/pluglib', '-MO=Lint,none' ],
144 like( $res, qr/Module::Pluggable ok\./, 'Lint uses Module::Pluggable' );