D'oh. Don't turn on warnings on the #! line without actually testing
[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);
6 require './test.pl';
7}
8
40f1df11 9plan tests => 15; # adjust also number of skipped tests !
94011a57 10
11# Runs a separate perl interpreter with the appropriate lint options
12# turned on
13sub 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
24runlint 'context', '$foo = @bar', <<'RESULT';
25Implicit scalar context for array in scalar assignment at -e line 1
26RESULT
27
28runlint 'context', '$foo = length @bar', <<'RESULT';
29Implicit scalar context for array in length at -e line 1
30RESULT
31
32runlint 'implicit-read', '/foo/', <<'RESULT';
33Implicit match on $_ at -e line 1
34RESULT
35
36runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
37Implicit substitution on $_ at -e line 1
38RESULT
39
40SKIP : {
41
42 use Config;
40f1df11 43 skip("Doesn't work with threaded perls",11)
3db8f154 44 if $Config{useithreads};
94011a57 45
46 runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach';
47Implicit use of $_ in foreach at -e line 1
48RESULT
49
50 runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
51Use of $_ at -e line 1
52RESULT
53
54 runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print';
55Use of $_ at -e line 1
56RESULT
57
58 runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
59Illegal reference to private name _f at -e line 1
60RESULT
61
62 runlint 'private-names', '$A::_x', <<'RESULT';
63Illegal reference to private name _x at -e line 1
64RESULT
65
bfecbe02 66 runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
94011a57 67Illegal reference to private method name _f at -e line 1
68RESULT
bfecbe02 69 'private-names (method)';
94011a57 70
71 runlint 'undefined-subs', 'foo()', <<'RESULT';
72Undefined subroutine foo called at -e line 1
73RESULT
74
75 runlint 'regexp-variables', 'print $&', <<'RESULT';
76Use of regexp variable $& at -e line 1
77RESULT
78
0091380b 79 runlint 'regexp-variables', 's/./$&/', <<'RESULT';
94011a57 80Use of regexp variable $& at -e line 1
81RESULT
94011a57 82
40f1df11 83 runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
84
85 runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
86Bare sub name 'bare' interpreted as string at -e line 1
87Bare sub name 'bare' interpreted as string at -e line 1
88RESULT
89
94011a57 90}