4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '.', '../lib' );
13 if ( ( $Config::Config{'extensions'} !~ /\bB\b/ ) ) {
14 print "1..0 # Skip -- Perl configured without B module\n";
22 # Runs a separate perl interpreter with the appropriate lint options
25 my ( $opts, $prog, $result, $testname ) = @_;
27 switches => ["-MO=Lint,$opts"],
31 $res =~ s/-e syntax OK\n$//;
32 is( $res, $result, $testname || $opts );
35 runlint 'magic-diamond', 'while(<>){}', <<'RESULT';
36 Use of <> at -e line 1
39 runlint 'magic-diamond', 'while(<ARGV>){}', <<'RESULT';
40 Use of <> at -e line 1
43 runlint 'magic-diamond', 'while(<FOO>){}', <<'RESULT';
46 runlint 'context', '$foo = @bar', <<'RESULT';
47 Implicit scalar context for array in scalar assignment at -e line 1
50 runlint 'context', '$foo = length @bar', <<'RESULT';
51 Implicit scalar context for array in length at -e line 1
54 runlint 'context', 'our @bar', '';
56 runlint 'context', 'exists $BAR{BAZ}', '';
58 runlint 'implicit-read', '/foo/', <<'RESULT';
59 Implicit match on $_ at -e line 1
62 runlint 'implicit-read', 'grep /foo/, ()', '';
64 runlint 'implicit-read', 'grep { /foo/ } ()', '';
66 runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
67 Implicit substitution on $_ at -e line 1
72 switches => ["-MB::Lint"],
74 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
77 like( $res, qr/X ok\./, 'Lint plugin' );
80 runlint 'implicit-read', 'for ( @ARGV ) { 1 }',
81 <<'RESULT', 'implicit-read in foreach';
82 Implicit use of $_ in foreach at -e line 1
85 runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach';
87 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
88 Use of $_ at -e line 1
91 runlint 'dollar-underscore', 'foo( $_ ) for @A', '';
92 runlint 'dollar-underscore', 'map { foo( $_ ) } @A', '';
93 runlint 'dollar-underscore', 'grep { foo( $_ ) } @A', '';
95 runlint 'dollar-underscore', 'print',
96 <<'RESULT', 'dollar-underscore in print';
97 Use of $_ at -e line 1
100 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
101 Illegal reference to private name '_f' at -e line 1
104 runlint 'private-names', '$A::_x', <<'RESULT';
105 Illegal reference to private name '_x' at -e line 1
108 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
109 Illegal reference to private method name '_f' at -e line 1
111 'private-names (method)';
113 runlint 'undefined-subs', 'foo()', <<'RESULT';
114 Nonexistant subroutine 'foo' called at -e line 1
117 runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT';
118 Undefined subroutine 'foo' called at -e line 1
121 runlint 'regexp-variables', 'print $&', <<'RESULT';
122 Use of regexp variable $& at -e line 1
125 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
126 Use of regexp variable $& at -e line 1
129 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
131 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
132 Bare sub name 'bare' interpreted as string at -e line 1
133 Bare sub name 'bare' interpreted as string at -e line 1