Commit | Line | Data |
---|---|---|
94011a57 JH |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
5638aaac SM |
4 | if ($ENV{PERL_CORE}){ |
5 | chdir('t') if -d 't'; | |
6 | @INC = ('.', '../lib'); | |
7 | } else { | |
8 | unshift @INC, 't'; | |
9 | push @INC, "../../t"; | |
10 | } | |
9cd8f857 NC |
11 | require Config; |
12 | if (($Config::Config{'extensions'} !~ /\bB\b/) ){ | |
13 | print "1..0 # Skip -- Perl configured without B module\n"; | |
14 | exit 0; | |
15 | } | |
5638aaac | 16 | require 'test.pl'; |
94011a57 JH |
17 | } |
18 | ||
2e9e4ed7 | 19 | plan tests => 24; # adjust also number of skipped tests ! |
94011a57 JH |
20 | |
21 | # Runs a separate perl interpreter with the appropriate lint options | |
22 | # turned on | |
23 | sub runlint ($$$;$) { | |
24 | my ($opts,$prog,$result,$testname) = @_; | |
25 | my $res = runperl( | |
26 | switches => [ "-MO=Lint,$opts" ], | |
27 | prog => $prog, | |
28 | stderr => 1, | |
29 | ); | |
30 | $res =~ s/-e syntax OK\n$//; | |
31 | is( $res, $result, $testname || $opts ); | |
32 | } | |
33 | ||
34 | runlint 'context', '$foo = @bar', <<'RESULT'; | |
35 | Implicit scalar context for array in scalar assignment at -e line 1 | |
36 | RESULT | |
37 | ||
38 | runlint 'context', '$foo = length @bar', <<'RESULT'; | |
39 | Implicit scalar context for array in length at -e line 1 | |
40 | RESULT | |
41 | ||
2e9e4ed7 JJ |
42 | runlint 'context', 'our @bar', ''; |
43 | ||
44 | runlint 'context', 'exists $BAR{BAZ}', ''; | |
45 | ||
94011a57 JH |
46 | runlint 'implicit-read', '/foo/', <<'RESULT'; |
47 | Implicit match on $_ at -e line 1 | |
48 | RESULT | |
49 | ||
3ee1325f JJ |
50 | runlint 'implicit-read', 'grep /foo/, ()', ''; |
51 | ||
52 | runlint 'implicit-read', 'grep { /foo/ } ()', ''; | |
53 | ||
94011a57 JH |
54 | runlint 'implicit-write', 's/foo/bar/', <<'RESULT'; |
55 | Implicit substitution on $_ at -e line 1 | |
56 | RESULT | |
57 | ||
ca0b1549 JJ |
58 | { |
59 | my $res = runperl( | |
60 | switches => [ "-MB::Lint" ], | |
ce5918c5 | 61 | prog => 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()', |
ca0b1549 JJ |
62 | stderr => 1, |
63 | ); | |
64 | like( $res, qr/X ok\./, 'Lint plugin' ); | |
65 | } | |
66 | ||
94011a57 JH |
67 | SKIP : { |
68 | ||
69 | use Config; | |
8b9f58b6 | 70 | skip("Doesn't work with threaded perls",15) |
f5ba1307 | 71 | if $Config{useithreads} || ($] < 5.009 && $Config{use5005threads}); |
94011a57 | 72 | |
2e9e4ed7 | 73 | runlint 'implicit-read', 'for ( @ARGV ) { 1 }', <<'RESULT', 'implicit-read in foreach'; |
94011a57 JH |
74 | Implicit use of $_ in foreach at -e line 1 |
75 | RESULT | |
76 | ||
2e9e4ed7 JJ |
77 | runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach'; |
78 | ||
94011a57 JH |
79 | runlint 'dollar-underscore', '$_ = 1', <<'RESULT'; |
80 | Use of $_ at -e line 1 | |
81 | RESULT | |
82 | ||
2e9e4ed7 JJ |
83 | runlint 'dollar-underscore', 'foo( $_ ) for @A', ''; |
84 | runlint 'dollar-underscore', 'map { foo( $_ ) } @A', ''; | |
85 | runlint 'dollar-underscore', 'grep { foo( $_ ) } @A', ''; | |
86 | ||
94011a57 JH |
87 | runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print'; |
88 | Use of $_ at -e line 1 | |
89 | RESULT | |
90 | ||
91 | runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT'; | |
92 | Illegal reference to private name _f at -e line 1 | |
93 | RESULT | |
94 | ||
95 | runlint 'private-names', '$A::_x', <<'RESULT'; | |
96 | Illegal reference to private name _x at -e line 1 | |
97 | RESULT | |
98 | ||
bfecbe02 | 99 | runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT', |
94011a57 JH |
100 | Illegal reference to private method name _f at -e line 1 |
101 | RESULT | |
bfecbe02 | 102 | 'private-names (method)'; |
94011a57 JH |
103 | |
104 | runlint 'undefined-subs', 'foo()', <<'RESULT'; | |
105 | Undefined subroutine foo called at -e line 1 | |
106 | RESULT | |
107 | ||
108 | runlint 'regexp-variables', 'print $&', <<'RESULT'; | |
109 | Use of regexp variable $& at -e line 1 | |
110 | RESULT | |
111 | ||
0091380b | 112 | runlint 'regexp-variables', 's/./$&/', <<'RESULT'; |
94011a57 JH |
113 | Use of regexp variable $& at -e line 1 |
114 | RESULT | |
94011a57 | 115 | |
40f1df11 RGS |
116 | runlint 'bare-subs', 'sub bare(){1};$x=bare', ''; |
117 | ||
118 | runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT'; | |
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 | |
122 | ||
94011a57 | 123 | } |