aelemfast optimization opclass problem (c.f. [perl #38279])
[p5sagit/p5-mst-13.2.git] / ext / B / t / lint.t
CommitLineData
94011a57 1#!./perl -w
2
3BEGIN {
5638aaac 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 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 17}
18
ca0b1549 19plan tests => 16; # adjust also number of skipped tests !
94011a57 20
21# Runs a separate perl interpreter with the appropriate lint options
22# turned on
23sub 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
34runlint 'context', '$foo = @bar', <<'RESULT';
35Implicit scalar context for array in scalar assignment at -e line 1
36RESULT
37
38runlint 'context', '$foo = length @bar', <<'RESULT';
39Implicit scalar context for array in length at -e line 1
40RESULT
41
42runlint 'implicit-read', '/foo/', <<'RESULT';
43Implicit match on $_ at -e line 1
44RESULT
45
46runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
47Implicit substitution on $_ at -e line 1
48RESULT
49
ca0b1549 50{
51 my $res = runperl(
52 switches => [ "-MB::Lint" ],
ce5918c5 53 prog => 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
ca0b1549 54 stderr => 1,
55 );
56 like( $res, qr/X ok\./, 'Lint plugin' );
57}
58
94011a57 59SKIP : {
60
61 use Config;
40f1df11 62 skip("Doesn't work with threaded perls",11)
f5ba1307 63 if $Config{useithreads} || ($] < 5.009 && $Config{use5005threads});
94011a57 64
65 runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach';
66Implicit use of $_ in foreach at -e line 1
67RESULT
68
69 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
70Use of $_ at -e line 1
71RESULT
72
73 runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print';
74Use of $_ at -e line 1
75RESULT
76
77 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
78Illegal reference to private name _f at -e line 1
79RESULT
80
81 runlint 'private-names', '$A::_x', <<'RESULT';
82Illegal reference to private name _x at -e line 1
83RESULT
84
bfecbe02 85 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
94011a57 86Illegal reference to private method name _f at -e line 1
87RESULT
bfecbe02 88 'private-names (method)';
94011a57 89
90 runlint 'undefined-subs', 'foo()', <<'RESULT';
91Undefined subroutine foo called at -e line 1
92RESULT
93
94 runlint 'regexp-variables', 'print $&', <<'RESULT';
95Use of regexp variable $& at -e line 1
96RESULT
97
0091380b 98 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
94011a57 99Use of regexp variable $& at -e line 1
100RESULT
94011a57 101
40f1df11 102 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
103
104 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
105Bare sub name 'bare' interpreted as string at -e line 1
106Bare sub name 'bare' interpreted as string at -e line 1
107RESULT
108
94011a57 109}