summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2002-03-08 15:47:19 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2002-03-08 13:42:24 +0000
commit1f01d15689eebf8cac0437bd6198b0ee0e3a2c33 (patch)
tree62a25a88b0ccd4ae6df4d32f9b22d83d571cfc51 /ext
parent92d0bc234510f4edc8fc26296133a8d387183cff (diff)
downloadperl-1f01d15689eebf8cac0437bd6198b0ee0e3a2c33.tar.gz
B::Lint tests
Message-ID: <20020308144719.A2663@rafael> p4raw-id: //depot/perl@15104
Diffstat (limited to 'ext')
-rw-r--r--ext/B/B/Lint.pm4
-rw-r--r--ext/B/t/lint.t81
2 files changed, 83 insertions, 2 deletions
diff --git a/ext/B/B/Lint.pm b/ext/B/B/Lint.pm
index 81e0f0eaa4..1510d365cd 100644
--- a/ext/B/B/Lint.pm
+++ b/ext/B/B/Lint.pm
@@ -1,6 +1,6 @@
package B::Lint;
-our $VERSION = '1.00';
+our $VERSION = '1.01';
=head1 NAME
@@ -164,7 +164,7 @@ sub gimme {
my $op = shift;
my $flags = $op->flags;
if ($flags & OPf_WANT) {
- return(($flags & OPf_WANT_LIST) ? 1 : 0);
+ return(($flags & OPf_WANT == OPf_WANT_LIST) ? 1 : 0);
}
return undef;
}
diff --git a/ext/B/t/lint.t b/ext/B/t/lint.t
new file mode 100644
index 0000000000..f4209def33
--- /dev/null
+++ b/ext/B/t/lint.t
@@ -0,0 +1,81 @@
+#!./perl -w
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = qw(../lib);
+ require './test.pl';
+}
+
+plan tests => 13;
+
+# Runs a separate perl interpreter with the appropriate lint options
+# turned on
+sub runlint ($$$;$) {
+ my ($opts,$prog,$result,$testname) = @_;
+ my $res = runperl(
+ switches => [ "-MO=Lint,$opts" ],
+ prog => $prog,
+ stderr => 1,
+ );
+ $res =~ s/-e syntax OK\n$//;
+ is( $res, $result, $testname || $opts );
+}
+
+runlint 'context', '$foo = @bar', <<'RESULT';
+Implicit scalar context for array in scalar assignment at -e line 1
+RESULT
+
+runlint 'context', '$foo = length @bar', <<'RESULT';
+Implicit scalar context for array in length at -e line 1
+RESULT
+
+runlint 'implicit-read', '/foo/', <<'RESULT';
+Implicit match on $_ at -e line 1
+RESULT
+
+runlint 'implicit-write', 's/foo/bar/', <<'RESULT';
+Implicit substitution on $_ at -e line 1
+RESULT
+
+runlint 'implicit-read', '1 for @ARGV', <<'RESULT', 'implicit-read in foreach';
+Implicit use of $_ in foreach at -e line 1
+RESULT
+
+runlint 'dollar-underscore', '$_ = 1', <<'RESULT';
+Use of $_ at -e line 1
+RESULT
+
+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
+RESULT
+
+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
+RESULT
+ 'private-names';
+}
+
+runlint 'undefined-subs', 'foo()', <<'RESULT';
+Undefined subroutine foo called at -e line 1
+RESULT
+
+runlint 'regexp-variables', 'print $&', <<'RESULT';
+Use of regexp variable $& at -e line 1
+RESULT
+
+{
+ local $TODO = 'bug';
+ runlint 'regexp-variables', 's/./$&/', <<'RESULT';
+Use of regexp variable $& at -e line 1
+RESULT
+}