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