If we don't build B, we should skip all its tests.
[p5sagit/p5-mst-13.2.git] / ext / B / t / lint.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = qw(../lib);
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     }
11     require './test.pl';
12 }
13
14 plan tests => 15; # adjust also number of skipped tests !
15
16 # Runs a separate perl interpreter with the appropriate lint options
17 # turned on
18 sub 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
29 runlint 'context', '$foo = @bar', <<'RESULT';
30 Implicit scalar context for array in scalar assignment at -e line 1
31 RESULT
32
33 runlint 'context', '$foo = length @bar', <<'RESULT';
34 Implicit scalar context for array in length at -e line 1
35 RESULT
36
37 runlint 'implicit-read', '/foo/', <<'RESULT';
38 Implicit match on $_ at -e line 1
39 RESULT
40
41 runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
42 Implicit substitution on $_ at -e line 1
43 RESULT
44
45 SKIP : {
46
47     use Config;
48     skip("Doesn't work with threaded perls",11)
49        if $Config{useithreads};
50
51     runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach';
52 Implicit use of $_ in foreach at -e line 1
53 RESULT
54
55     runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
56 Use of $_ at -e line 1
57 RESULT
58
59     runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print';
60 Use of $_ at -e line 1
61 RESULT
62
63     runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT';
64 Illegal reference to private name _f at -e line 1
65 RESULT
66
67     runlint 'private-names', '$A::_x', <<'RESULT';
68 Illegal reference to private name _x at -e line 1
69 RESULT
70
71     runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
72 Illegal reference to private method name _f at -e line 1
73 RESULT
74     'private-names (method)';
75
76     runlint 'undefined-subs', 'foo()', <<'RESULT';
77 Undefined subroutine foo called at -e line 1
78 RESULT
79
80     runlint 'regexp-variables', 'print $&', <<'RESULT';
81 Use of regexp variable $& at -e line 1
82 RESULT
83
84     runlint 'regexp-variables', 's/./$&/', <<'RESULT';
85 Use of regexp variable $& at -e line 1
86 RESULT
87
88     runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
89
90     runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
91 Bare sub name 'bare' interpreted as string at -e line 1
92 Bare sub name 'bare' interpreted as string at -e line 1
93 RESULT
94
95 }