6 @INC = ('.', '../lib');
12 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
13 print "1..0 # Skip -- Perl configured without B module\n";
19 plan tests => 24; # adjust also number of skipped tests !
21 # Runs a separate perl interpreter with the appropriate lint options
24 my ($opts,$prog,$result,$testname) = @_;
26 switches => [ "-MO=Lint,$opts" ],
30 $res =~ s/-e syntax OK\n$//;
31 is( $res, $result, $testname || $opts );
34 runlint 'context', '$foo = @bar', <<'RESULT';
35 Implicit scalar context for array in scalar assignment at -e line 1
38 runlint 'context', '$foo = length @bar', <<'RESULT';
39 Implicit scalar context for array in length at -e line 1
42 runlint 'context', 'our @bar', '';
44 runlint 'context', 'exists $BAR{BAZ}', '';
46 runlint 'implicit-read', '/foo/', <<'RESULT';
47 Implicit match on $_ at -e line 1
50 runlint 'implicit-read', 'grep /foo/, ()', '';
52 runlint 'implicit-read', 'grep { /foo/ } ()', '';
54 runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
55 Implicit substitution on $_ at -e line 1
60 switches => [ "-MB::Lint" ],
61 prog => 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
64 like( $res, qr/X ok\./, 'Lint plugin' );
70 skip("Doesn't work with threaded perls",15)
71 if $Config{useithreads} || ($] < 5.009 && $Config{use5005threads});
73 runlint 'implicit-read', 'for ( @ARGV ) { 1 }', <<'RESULT', 'implicit-read in foreach';
74 Implicit use of $_ in foreach at -e line 1
77 runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach';
79 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
80 Use of $_ at -e line 1
83 runlint 'dollar-underscore', 'foo( $_ ) for @A', '';
84 runlint 'dollar-underscore', 'map { foo( $_ ) } @A', '';
85 runlint 'dollar-underscore', 'grep { foo( $_ ) } @A', '';
87 runlint 'dollar-underscore', 'print', <<'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 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