X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FB%2Ft%2Flint.t;h=f62adc2f38ecba45ec98c177de80c83ed46e7283;hb=fdecdb95df591262b9afbfa09e74e71f92af065a;hp=f20d04d83749bb25c51f95cd342b2b6bed0a84d0;hpb=94011a57d204cc8b19a9e33fa13d66d74bd9ca88;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/B/t/lint.t b/ext/B/t/lint.t index f20d04d..f62adc2 100644 --- a/ext/B/t/lint.t +++ b/ext/B/t/lint.t @@ -1,26 +1,48 @@ #!./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 => 29; # Runs a separate perl interpreter with the appropriate lint options # turned on sub runlint ($$$;$) { - my ($opts,$prog,$result,$testname) = @_; + my ( $opts, $prog, $result, $testname ) = @_; my $res = runperl( - switches => [ "-MO=Lint,$opts" ], - prog => $prog, - stderr => 1, + switches => ["-MO=Lint,$opts"], + prog => $prog, + stderr => 1, ); $res =~ s/-e syntax OK\n$//; is( $res, $result, $testname || $opts ); } +runlint 'magic-diamond', 'while(<>){}', <<'RESULT'; +Use of <> at -e line 1 +RESULT + +runlint 'magic-diamond', 'while(){}', <<'RESULT'; +Use of <> at -e line 1 +RESULT + +runlint 'magic-diamond', 'while(){}', <<'RESULT'; +RESULT + runlint 'context', '$foo = @bar', <<'RESULT'; Implicit scalar context for array in scalar assignment at -e line 1 RESULT @@ -29,60 +51,98 @@ runlint 'context', '$foo = length @bar', <<'RESULT'; Implicit scalar context for array in length at -e line 1 RESULT +runlint 'context', 'our @bar', ''; + +runlint 'context', 'exists $BAR{BAZ}', ''; + runlint 'implicit-read', '/foo/', <<'RESULT'; Implicit match on $_ at -e line 1 RESULT +runlint 'implicit-read', 'grep /foo/, ()', ''; + +runlint 'implicit-read', 'grep { /foo/ } ()', ''; + runlint 'implicit-write', 's/foo/bar/', <<'RESULT'; Implicit substitution on $_ at -e line 1 RESULT -SKIP : { - - use Config; - skip("Doesn't work with threaded perls",9) if $Config{useithreads}; - - runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach'; +runlint 'implicit-read', 'for ( @ARGV ) { 1 }', + <<'RESULT', 'implicit-read in foreach'; Implicit use of $_ in foreach at -e line 1 RESULT - runlint 'dollar-underscore', '$_ = 1', <<'RESULT'; +runlint 'implicit-read', '1 for @ARGV', '', 'implicit-read in foreach'; + +runlint 'dollar-underscore', '$_ = 1', <<'RESULT'; Use of $_ at -e line 1 RESULT - runlint 'dollar-underscore', 'print', <<'RESULT', 'dollar-underscore in print'; +runlint 'dollar-underscore', 'sub foo {}; foo( $_ ) for @A', ''; +runlint 'dollar-underscore', 'sub foo {}; map { foo( $_ ) } @A', ''; +runlint 'dollar-underscore', 'sub foo {}; grep { foo( $_ ) } @A', ''; + +runlint 'dollar-underscore', 'print', + <<'RESULT', 'dollar-underscore in print'; Use of $_ at -e line 1 RESULT - runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT'; -Illegal reference to private name _f at -e line 1 +runlint 'private-names', 'sub A::_f{};A::_f()', <<'RESULT'; +Illegal reference to private name '_f' at -e line 1 RESULT - runlint 'private-names', '$A::_x', <<'RESULT'; -Illegal reference to private name _x at -e line 1 +runlint 'private-names', '$A::_x', <<'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', -Illegal reference to private method name _f at -e line 1 +runlint 'private-names', 'sub A::_f{};A->_f()', <<'RESULT', +Illegal reference to private method name '_f' at -e line 1 +RESULT + 'private-names (method)'; + +runlint 'undefined-subs', 'foo()', <<'RESULT'; +Nonexistant subroutine 'foo' called at -e line 1 RESULT - 'private-names'; - } - runlint 'undefined-subs', 'foo()', <<'RESULT'; -Undefined subroutine foo called at -e line 1 +runlint 'undefined-subs', 'foo();sub foo;', <<'RESULT'; +Undefined subroutine 'foo' called at -e line 1 RESULT - runlint 'regexp-variables', 'print $&', <<'RESULT'; +runlint 'regexp-variables', 'print $&', <<'RESULT'; Use of regexp variable $& at -e line 1 RESULT - { - local $TODO = 'bug'; - runlint 'regexp-variables', 's/./$&/', <<'RESULT'; +runlint 'regexp-variables', 's/./$&/', <<'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 + +{ + + # Check for backwards-compatible plugin support. This was where + # preloaded mdoules would register themselves with B::Lint. + 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 legacy plugin' ); +} + +{ + + # Check for Module::Plugin support + my $res = runperl( + switches => [ '-I../ext/B/t/pluglib', '-MO=Lint,none' ], + prog => 1, + stderr => 1, + ); + like( $res, qr/Module::Pluggable ok\./, 'Lint uses Module::Pluggable' ); }