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 local $Level = $Level + 1;
33 is( $res, $result, $testname || $opts );
36 runlint 'magic-diamond', 'while(<>){}', <<'RESULT';
37 Use of <> at -e line 1
40 runlint 'magic-diamond', 'while(<ARGV>){}', <<'RESULT';
41 Use of <> at -e line 1
44 runlint 'magic-diamond', 'while(<FOO>){}', <<'RESULT';
47 runlint 'context', '$foo = @bar', <<'RESULT';
48 Implicit scalar context for array in scalar assignment at -e line 1
51 runlint 'context', '$foo = length @bar', <<'RESULT';
52 Implicit scalar context for array in length at -e line 1
55 runlint 'context', 'our @bar', '';
57 runlint 'context', 'exists $BAR{BAZ}', '';
59 runlint 'implicit-read', '/foo/', <<'RESULT';
60 Implicit match on $_ at -e line 1
63 runlint 'implicit-read', 'grep /foo/, ()', '';
65 runlint 'implicit-read', 'grep { /foo/ } ()', '';
67 runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
68 Implicit substitution on $_ at -e line 1
71 runlint 'implicit-read', 'for ( @ARGV ) { 1 }',
72 <<'RESULT', 'implicit-read in foreach';
73 Implicit use of $_ in foreach at -e line 1
76 runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach';
78 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
79 Use of $_ at -e line 1
82 runlint 'dollar-underscore', 'sub foo {}; foo( $_ ) for @A', '';
83 runlint 'dollar-underscore', 'sub foo {}; map { foo( $_ ) } @A', '';
84 runlint 'dollar-underscore', 'sub foo {}; grep { foo( $_ ) } @A', '';
86 runlint 'dollar-underscore', 'print',
87 <<'RESULT', 'dollar-underscore in print';
88 Use of $_ at -e line 1
91 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
92 Illegal reference to private name '_f' at -e line 1
95 runlint 'private-names', '$A::_x', <<'RESULT';
96 Illegal reference to private name '_x' at -e line 1
99 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
100 Illegal reference to private method name '_f' at -e line 1
102 'private-names (method)';
104 runlint 'undefined-subs', 'foo()', <<'RESULT';
105 Nonexistant subroutine 'foo' called at -e line 1
108 runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT';
109 Undefined subroutine 'foo' called at -e line 1
112 runlint 'regexp-variables', 'print $&', <<'RESULT';
113 Use of regexp variable $& at -e line 1
116 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
117 Use of regexp variable $& at -e line 1
120 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
122 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
123 Bare sub name 'bare' interpreted as string at -e line 1
124 Bare sub name 'bare' interpreted as string at -e line 1
129 # Check for backwards-compatible plugin support. This was where
130 # preloaded mdoules would register themselves with B::Lint.
132 switches => ["-MB::Lint"],
134 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
137 like( $res, qr/X ok\./, 'Lint legacy plugin' );
142 # Check for Module::Plugin support
144 switches => [ '-I../ext/B/t/pluglib', '-MO=Lint,none' ],
148 like( $res, qr/Module::Pluggable ok\./, 'Lint uses Module::Pluggable' );