Integrate:
[p5sagit/p5-mst-13.2.git] / ext / B / t / lint.t
CommitLineData
94011a57 1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = qw(../lib);
9cd8f857 6 require Config;
7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
9 exit 0;
10 }
94011a57 11 require './test.pl';
12}
13
40f1df11 14plan tests => 15; # adjust also number of skipped tests !
94011a57 15
16# Runs a separate perl interpreter with the appropriate lint options
17# turned on
18sub runlint ($$$;$) {
19 my ($opts,$prog,$result,$testname) = @_;
20 my $res = runperl(
21 switches => [ "-MO=Lint,$opts" ],
22 prog => $prog,
23 stderr => 1,
24 );
25 $res =~ s/-e syntax OK\n$//;
26 is( $res, $result, $testname || $opts );
27}
28
29runlint 'context', '$foo = @bar', <<'RESULT';
30Implicit scalar context for array in scalar assignment at -e line 1
31RESULT
32
33runlint 'context', '$foo = length @bar', <<'RESULT';
34Implicit scalar context for array in length at -e line 1
35RESULT
36
37runlint 'implicit-read', '/foo/', <<'RESULT';
38Implicit match on $_ at -e line 1
39RESULT
40
41runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
42Implicit substitution on $_ at -e line 1
43RESULT
44
45SKIP : {
46
47 use Config;
40f1df11 48 skip("Doesn't work with threaded perls",11)
f5ba1307 49 if $Config{useithreads} || ($] < 5.009 && $Config{use5005threads});
94011a57 50
51 runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach';
52Implicit use of $_ in foreach at -e line 1
53RESULT
54
55 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
56Use of $_ at -e line 1
57RESULT
58
59 runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print';
60Use of $_ at -e line 1
61RESULT
62
63 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
64Illegal reference to private name _f at -e line 1
65RESULT
66
67 runlint 'private-names', '$A::_x', <<'RESULT';
68Illegal reference to private name _x at -e line 1
69RESULT
70
bfecbe02 71 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
94011a57 72Illegal reference to private method name _f at -e line 1
73RESULT
bfecbe02 74 'private-names (method)';
94011a57 75
76 runlint 'undefined-subs', 'foo()', <<'RESULT';
77Undefined subroutine foo called at -e line 1
78RESULT
79
80 runlint 'regexp-variables', 'print $&', <<'RESULT';
81Use of regexp variable $& at -e line 1
82RESULT
83
0091380b 84 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
94011a57 85Use of regexp variable $& at -e line 1
86RESULT
94011a57 87
40f1df11 88 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
89
90 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
91Bare sub name 'bare' interpreted as string at -e line 1
92Bare sub name 'bare' interpreted as string at -e line 1
93RESULT
94
94011a57 95}