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 | |
9b494a7e |
20 | plan tests => 28; |
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$//; |
32 | is( $res, $result, $testname || $opts ); |
33 | } |
34 | |
9b494a7e |
35 | runlint 'magic-diamond', 'while(<>){}', <<'RESULT'; |
36 | Use of <> at -e line 1 |
37 | RESULT |
38 | |
39 | runlint 'magic-diamond', 'while(<ARGV>){}', <<'RESULT'; |
40 | Use of <> at -e line 1 |
41 | RESULT |
42 | |
43 | runlint 'magic-diamond', 'while(<FOO>){}', <<'RESULT'; |
44 | RESULT |
45 | |
94011a57 |
46 | runlint 'context', '$foo = @bar', <<'RESULT'; |
47 | Implicit scalar context for array in scalar assignment at -e line 1 |
48 | RESULT |
49 | |
50 | runlint 'context', '$foo = length @bar', <<'RESULT'; |
51 | Implicit scalar context for array in length at -e line 1 |
52 | RESULT |
53 | |
2e9e4ed7 |
54 | runlint 'context', 'our @bar', ''; |
55 | |
56 | runlint 'context', 'exists $BAR{BAZ}', ''; |
57 | |
94011a57 |
58 | runlint 'implicit-read', '/foo/', <<'RESULT'; |
59 | Implicit match on $_ at -e line 1 |
60 | RESULT |
61 | |
3ee1325f |
62 | runlint 'implicit-read', 'grep /foo/, ()', ''; |
63 | |
64 | runlint 'implicit-read', 'grep { /foo/ } ()', ''; |
65 | |
94011a57 |
66 | runlint 'implicit-write', 's/foo/bar/', <<'RESULT'; |
67 | Implicit substitution on $_ at -e line 1 |
68 | RESULT |
69 | |
ca0b1549 |
70 | { |
71 | my $res = runperl( |
9b494a7e |
72 | switches => ["-MB::Lint"], |
73 | prog => |
74 | 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()', |
75 | stderr => 1, |
ca0b1549 |
76 | ); |
77 | like( $res, qr/X ok\./, 'Lint plugin' ); |
78 | } |
79 | |
9b494a7e |
80 | runlint 'implicit-read', 'for ( @ARGV ) { 1 }', |
81 | <<'RESULT', 'implicit-read in foreach'; |
94011a57 |
82 | Implicit use of $_ in foreach at -e line 1 |
83 | RESULT |
84 | |
9b494a7e |
85 | runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach'; |
2e9e4ed7 |
86 | |
9b494a7e |
87 | runlint 'dollar-underscore', '$_ = 1', <<'RESULT'; |
94011a57 |
88 | Use of $_ at -e line 1 |
89 | RESULT |
90 | |
9b494a7e |
91 | runlint 'dollar-underscore', 'foo( $_ ) for @A', ''; |
92 | runlint 'dollar-underscore', 'map { foo( $_ ) } @A', ''; |
93 | runlint 'dollar-underscore', 'grep { foo( $_ ) } @A', ''; |
2e9e4ed7 |
94 | |
9b494a7e |
95 | runlint 'dollar-underscore', 'print', |
96 | <<'RESULT', 'dollar-underscore in print'; |
94011a57 |
97 | Use of $_ at -e line 1 |
98 | RESULT |
99 | |
9b494a7e |
100 | runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT'; |
101 | Illegal reference to private name '_f' at -e line 1 |
94011a57 |
102 | RESULT |
103 | |
9b494a7e |
104 | runlint 'private-names', '$A::_x', <<'RESULT'; |
105 | Illegal reference to private name '_x' at -e line 1 |
94011a57 |
106 | RESULT |
107 | |
9b494a7e |
108 | runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT', |
109 | Illegal reference to private method name '_f' at -e line 1 |
94011a57 |
110 | RESULT |
bfecbe02 |
111 | 'private-names (method)'; |
94011a57 |
112 | |
9b494a7e |
113 | runlint 'undefined-subs', 'foo()', <<'RESULT'; |
114 | Nonexistant subroutine 'foo' called at -e line 1 |
115 | RESULT |
116 | |
117 | runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT'; |
118 | Undefined subroutine 'foo' called at -e line 1 |
94011a57 |
119 | RESULT |
120 | |
9b494a7e |
121 | runlint 'regexp-variables', 'print $&', <<'RESULT'; |
94011a57 |
122 | Use of regexp variable $& at -e line 1 |
123 | RESULT |
124 | |
9b494a7e |
125 | runlint 'regexp-variables', 's/./$&/', <<'RESULT'; |
94011a57 |
126 | Use of regexp variable $& at -e line 1 |
127 | RESULT |
94011a57 |
128 | |
9b494a7e |
129 | runlint 'bare-subs', 'sub bare(){1};$x=bare', ''; |
40f1df11 |
130 | |
9b494a7e |
131 | runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT'; |
40f1df11 |
132 | Bare sub name 'bare' interpreted as string at -e line 1 |
133 | Bare sub name 'bare' interpreted as string at -e line 1 |
134 | RESULT |