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