Commit | Line | Data |
---|---|---|
94011a57 JH |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
5 | @INC = qw(../lib); | |
6 | require './test.pl'; | |
7 | } | |
8 | ||
9 | plan tests => 13; | |
10 | ||
11 | # Runs a separate perl interpreter with the appropriate lint options | |
12 | # turned on | |
13 | sub runlint ($$$;$) { | |
14 | my ($opts,$prog,$result,$testname) = @_; | |
15 | my $res = runperl( | |
16 | switches => [ "-MO=Lint,$opts" ], | |
17 | prog => $prog, | |
18 | stderr => 1, | |
19 | ); | |
20 | $res =~ s/-e syntax OK\n$//; | |
21 | is( $res, $result, $testname || $opts ); | |
22 | } | |
23 | ||
24 | runlint 'context', '$foo = @bar', <<'RESULT'; | |
25 | Implicit scalar context for array in scalar assignment at -e line 1 | |
26 | RESULT | |
27 | ||
28 | runlint 'context', '$foo = length @bar', <<'RESULT'; | |
29 | Implicit scalar context for array in length at -e line 1 | |
30 | RESULT | |
31 | ||
32 | runlint 'implicit-read', '/foo/', <<'RESULT'; | |
33 | Implicit match on $_ at -e line 1 | |
34 | RESULT | |
35 | ||
36 | runlint 'implicit-write', 's/foo/bar/', <<'RESULT'; | |
37 | Implicit substitution on $_ at -e line 1 | |
38 | RESULT | |
39 | ||
40 | SKIP : { | |
41 | ||
42 | use Config; | |
43 | skip("Doesn't work with threaded perls",9) if $Config{useithreads}; | |
44 | ||
45 | runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach'; | |
46 | Implicit use of $_ in foreach at -e line 1 | |
47 | RESULT | |
48 | ||
49 | runlint 'dollar-underscore', '$_ = 1', <<'RESULT'; | |
50 | Use of $_ at -e line 1 | |
51 | RESULT | |
52 | ||
53 | runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print'; | |
54 | Use of $_ at -e line 1 | |
55 | RESULT | |
56 | ||
57 | runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT'; | |
58 | Illegal reference to private name _f at -e line 1 | |
59 | RESULT | |
60 | ||
61 | runlint 'private-names', '$A::_x', <<'RESULT'; | |
62 | Illegal reference to private name _x at -e line 1 | |
63 | RESULT | |
64 | ||
65 | { | |
66 | local $TODO = q/doesn't catch methods/; | |
67 | runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT', | |
68 | Illegal reference to private method name _f at -e line 1 | |
69 | RESULT | |
70 | 'private-names'; | |
71 | } | |
72 | ||
73 | runlint 'undefined-subs', 'foo()', <<'RESULT'; | |
74 | Undefined subroutine foo called at -e line 1 | |
75 | RESULT | |
76 | ||
77 | runlint 'regexp-variables', 'print $&', <<'RESULT'; | |
78 | Use of regexp variable $& at -e line 1 | |
79 | RESULT | |
80 | ||
81 | { | |
82 | local $TODO = 'bug'; | |
83 | runlint 'regexp-variables', 's/./$&/', <<'RESULT'; | |
84 | Use of regexp variable $& at -e line 1 | |
85 | RESULT | |
86 | } | |
87 | ||
88 | } |