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