Re: Patches: B, CGI, ExtUtils::MM_Unix
[p5sagit/p5-mst-13.2.git] / ext / B / t / lint.t
index 6f21eaf..d5ee215 100644 (file)
@@ -1,12 +1,22 @@
 #!./perl -w
 
 BEGIN {
-    chdir 't' if -d 't';
-    @INC = qw(../lib);
-    require './test.pl';
+    if ($ENV{PERL_CORE}){
+       chdir('t') if -d 't';
+       @INC = ('.', '../lib');
+    } else {
+       unshift @INC, 't';
+       push @INC, "../../t";
+    }
+    require Config;
+    if (($Config::Config{'extensions'} !~ /\bB\b/) ){
+        print "1..0 # Skip -- Perl configured without B module\n";
+        exit 0;
+    }
+    require 'test.pl';
 }
 
-plan tests => 13;
+plan tests => 16; # adjust also number of skipped tests !
 
 # Runs a separate perl interpreter with the appropriate lint options
 # turned on
@@ -37,11 +47,20 @@ runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
 Implicit substitution on $_ at -e line 1
 RESULT
 
+{
+    my $res = runperl(
+        switches => [ "-MB::Lint" ],
+        prog => 'BEGIN{B::Lint->register_plugin(X=>[q[x]])};use O(qw[Lint x]);sub X::match{warn qq[X ok.\n]};dummy()',
+       stderr => 1,
+    );
+    like( $res, qr/X ok\./, 'Lint plugin' );
+}
+
 SKIP : {
 
     use Config;
-    skip("Doesn't work with threaded perls",9)
-       if $Config{useithreads} || $Config{use5005threads};
+    skip("Doesn't work with threaded perls",11)
+       if $Config{useithreads} || ($] < 5.009 && $Config{use5005threads});
 
     runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach';
 Implicit use of $_ in foreach at -e line 1
@@ -63,13 +82,10 @@ RESULT
 Illegal reference to private name _x at -e line 1
 RESULT
 
-    {
-       local $TODO = q/doesn't catch methods/;
-       runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
+    runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT',
 Illegal reference to private method name _f at -e line 1
 RESULT
-       'private-names';
-    }
+    'private-names (method)';
 
     runlint 'undefined-subs', 'foo()', <<'RESULT';
 Undefined subroutine foo called at -e line 1
@@ -83,4 +99,11 @@ RESULT
 Use of regexp variable $& at -e line 1
 RESULT
 
+    runlint 'bare-subs', 'sub bare(){1};$x=bare', '';
+
+    runlint 'bare-subs', 'sub bare(){1}; $x=[bare=>0]; $x=$y{bare}', <<'RESULT';
+Bare sub name 'bare' interpreted as string at -e line 1
+Bare sub name 'bare' interpreted as string at -e line 1
+RESULT
+
 }