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";
24 # Runs a separate perl interpreter with the appropriate lint options
27 my ( $opts, $prog, $result, $testname ) = @_;
29 switches => ["-MO=Lint,$opts"],
33 $res =~ s/-e syntax OK\n$//;
34 local $::Level = $::Level + 1;
35 is( $res, $result, $testname || $opts );
38 runlint 'magic-diamond', 'while(<>){}', <<'RESULT';
39 Use of <> at -e line 1
42 runlint 'magic-diamond', 'while(<ARGV>){}', <<'RESULT';
43 Use of <> at -e line 1
46 runlint 'magic-diamond', 'while(<FOO>){}', <<'RESULT';
49 runlint 'context', '$foo = @bar', <<'RESULT';
50 Implicit scalar context for array in scalar assignment at -e line 1
53 runlint 'context', '$foo = length @bar', <<'RESULT';
54 Implicit scalar context for array in length at -e line 1
57 runlint 'context', 'our @bar', '';
59 runlint 'context', 'exists $BAR{BAZ}', '';
61 runlint 'implicit-read', '/foo/', <<'RESULT';
62 Implicit match on $_ at -e line 1
65 runlint 'implicit-read', 'grep /foo/, ()', '';
67 runlint 'implicit-read', 'grep { /foo/ } ()', '';
69 runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
70 Implicit substitution on $_ at -e line 1
73 runlint 'implicit-read', 'for ( @ARGV ) { 1 }',
74 <<'RESULT', 'implicit-read in foreach';
75 Implicit use of $_ in foreach at -e line 1
78 runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach';
80 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
81 Use of $_ at -e line 1
84 runlint 'dollar-underscore', 'sub foo {}; foo( $_ ) for @A', '';
85 runlint 'dollar-underscore', 'sub foo {}; map { foo( $_ ) } @A', '';
86 runlint 'dollar-underscore', 'sub foo {}; grep { foo( $_ ) } @A', '';
88 runlint 'dollar-underscore', 'print',
89 <<'RESULT', 'dollar-underscore in print';
90 Use of $_ at -e line 1
93 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
94 Illegal reference to private name '_f' at -e line 1
97 runlint 'private-names', '$A::_x', <<'RESULT';
98 Illegal reference to private name '_x' at -e line 1
101 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
102 Illegal reference to private method name '_f' at -e line 1
104 'private-names (method)';
106 runlint 'undefined-subs', 'foo()', <<'RESULT';
107 Nonexistant subroutine 'foo' called at -e line 1
110 runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT';
111 Undefined subroutine 'foo' called at -e line 1
114 runlint 'regexp-variables', 'print $&', <<'RESULT';
115 Use of regexp variable $& at -e line 1
118 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
119 Use of regexp variable $& at -e line 1
122 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
124 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
125 Bare sub name 'bare' interpreted as string at -e line 1
126 Bare sub name 'bare' interpreted as string at -e line 1
131 # Check for backwards-compatible plugin support. This was where
132 # preloaded mdoules would register themselves with B::Lint.
134 switches => ["-MB::Lint"],
136 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
139 like( $res, qr/X ok\./, 'Lint legacy plugin' );
144 # Check for Module::Plugin support
146 switches => [ '-I../ext/B/t/pluglib', '-MO=Lint,none' ],
150 like( $res, qr/Module::Pluggable ok\./, 'Lint uses Module::Pluggable' );