Commit | Line | Data |
94011a57 |
1 | #!./perl -w |
2 | |
3 | BEGIN { |
9b494a7e |
4 | if ( $ENV{PERL_CORE} ) { |
5 | chdir('t') if -d 't'; |
6 | @INC = ( '.', '../lib' ); |
7 | } |
8 | else { |
9 | unshift @INC, 't'; |
10 | push @INC, "../../t"; |
5638aaac |
11 | } |
9cd8f857 |
12 | require Config; |
9b494a7e |
13 | if ( ( $Config::Config{'extensions'} !~ /\bB\b/ ) ) { |
9cd8f857 |
14 | print "1..0 # Skip -- Perl configured without B module\n"; |
15 | exit 0; |
16 | } |
5638aaac |
17 | require 'test.pl'; |
94011a57 |
18 | } |
354c4f67 |
19 | use strict; |
20 | use warnings; |
94011a57 |
21 | |
2adc4a42 |
22 | plan tests => 29; |
94011a57 |
23 | |
24 | # Runs a separate perl interpreter with the appropriate lint options |
25 | # turned on |
26 | sub runlint ($$$;$) { |
9b494a7e |
27 | my ( $opts, $prog, $result, $testname ) = @_; |
94011a57 |
28 | my $res = runperl( |
9b494a7e |
29 | switches => ["-MO=Lint,$opts"], |
30 | prog => $prog, |
31 | stderr => 1, |
94011a57 |
32 | ); |
33 | $res =~ s/-e syntax OK\n$//; |
354c4f67 |
34 | local $::Level = $::Level + 1; |
94011a57 |
35 | is( $res, $result, $testname || $opts ); |
36 | } |
37 | |
9b494a7e |
38 | runlint 'magic-diamond', 'while(<>){}', <<'RESULT'; |
39 | Use of <> at -e line 1 |
40 | RESULT |
41 | |
42 | runlint 'magic-diamond', 'while(<ARGV>){}', <<'RESULT'; |
43 | Use of <> at -e line 1 |
44 | RESULT |
45 | |
46 | runlint 'magic-diamond', 'while(<FOO>){}', <<'RESULT'; |
47 | RESULT |
48 | |
94011a57 |
49 | runlint 'context', '$foo = @bar', <<'RESULT'; |
50 | Implicit scalar context for array in scalar assignment at -e line 1 |
51 | RESULT |
52 | |
53 | runlint 'context', '$foo = length @bar', <<'RESULT'; |
54 | Implicit scalar context for array in length at -e line 1 |
55 | RESULT |
56 | |
2e9e4ed7 |
57 | runlint 'context', 'our @bar', ''; |
58 | |
59 | runlint 'context', 'exists $BAR{BAZ}', ''; |
60 | |
94011a57 |
61 | runlint 'implicit-read', '/foo/', <<'RESULT'; |
62 | Implicit match on $_ at -e line 1 |
63 | RESULT |
64 | |
3ee1325f |
65 | runlint 'implicit-read', 'grep /foo/, ()', ''; |
66 | |
67 | runlint 'implicit-read', 'grep { /foo/ } ()', ''; |
68 | |
94011a57 |
69 | runlint 'implicit-write', 's/foo/bar/', <<'RESULT'; |
70 | Implicit substitution on $_ at -e line 1 |
71 | RESULT |
72 | |
9b494a7e |
73 | runlint 'implicit-read', 'for ( @ARGV ) { 1 }', |
74 | <<'RESULT', 'implicit-read in foreach'; |
94011a57 |
75 | Implicit use of $_ in foreach at -e line 1 |
76 | RESULT |
77 | |
9b494a7e |
78 | runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach'; |
2e9e4ed7 |
79 | |
9b494a7e |
80 | runlint 'dollar-underscore', '$_ = 1', <<'RESULT'; |
94011a57 |
81 | Use of $_ at -e line 1 |
82 | RESULT |
83 | |
2adc4a42 |
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', ''; |
2e9e4ed7 |
87 | |
9b494a7e |
88 | runlint 'dollar-underscore', 'print', |
89 | <<'RESULT', 'dollar-underscore in print'; |
94011a57 |
90 | Use of $_ at -e line 1 |
91 | RESULT |
92 | |
9b494a7e |
93 | runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT'; |
94 | Illegal reference to private name '_f' at -e line 1 |
94011a57 |
95 | RESULT |
96 | |
9b494a7e |
97 | runlint 'private-names', '$A::_x', <<'RESULT'; |
98 | Illegal reference to private name '_x' at -e line 1 |
94011a57 |
99 | RESULT |
100 | |
9b494a7e |
101 | runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT', |
102 | Illegal reference to private method name '_f' at -e line 1 |
94011a57 |
103 | RESULT |
bfecbe02 |
104 | 'private-names (method)'; |
94011a57 |
105 | |
9b494a7e |
106 | runlint 'undefined-subs', 'foo()', <<'RESULT'; |
107 | Nonexistant subroutine 'foo' called at -e line 1 |
108 | RESULT |
109 | |
110 | runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT'; |
111 | Undefined subroutine 'foo' called at -e line 1 |
94011a57 |
112 | RESULT |
113 | |
9b494a7e |
114 | runlint 'regexp-variables', 'print $&', <<'RESULT'; |
94011a57 |
115 | Use of regexp variable $& at -e line 1 |
116 | RESULT |
117 | |
9b494a7e |
118 | runlint 'regexp-variables', 's/./$&/', <<'RESULT'; |
94011a57 |
119 | Use of regexp variable $& at -e line 1 |
120 | RESULT |
94011a57 |
121 | |
9b494a7e |
122 | runlint 'bare-subs', 'sub bare(){1};$x=bare', ''; |
40f1df11 |
123 | |
9b494a7e |
124 | runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT'; |
40f1df11 |
125 | Bare sub name 'bare' interpreted as string at -e line 1 |
126 | Bare sub name 'bare' interpreted as string at -e line 1 |
127 | RESULT |
2adc4a42 |
128 | |
129 | { |
130 | |
131 | # Check for backwards-compatible plugin support. This was where |
132 | # preloaded mdoules would register themselves with B::Lint. |
133 | my $res = runperl( |
134 | switches => ["-MB::Lint"], |
135 | prog => |
136 | 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()', |
137 | stderr => 1, |
138 | ); |
139 | like( $res, qr/X ok\./, 'Lint legacy plugin' ); |
140 | } |
141 | |
142 | { |
143 | |
144 | # Check for Module::Plugin support |
145 | my $res = runperl( |
146 | switches => [ '-I../ext/B/t/pluglib', '-MO=Lint,none' ], |
147 | prog => 1, |
148 | stderr => 1, |
149 | ); |
150 | like( $res, qr/Module::Pluggable ok\./, 'Lint uses Module::Pluggable' ); |
151 | } |