Author: turnstep
Date: Sat Jan 12 20:15:04 2008
New Revision: 10532

Added:
   DBD-Pg/trunk/.perlcriticrc
   DBD-Pg/trunk/t/99_perlcritic.t
Modified:
   DBD-Pg/trunk/MANIFEST

Log:
Perl::Critic helpers. Works great for t/*.t, Pg.pm still needs work.


Added: DBD-Pg/trunk/.perlcriticrc
==============================================================================
--- (empty file)
+++ DBD-Pg/trunk/.perlcriticrc  Sat Jan 12 20:15:04 2008
@@ -0,0 +1,62 @@
+verbose = 9
+
+[-Tics::ProhibitLongLines]
+[-ValuesAndExpressions::ProhibitMagicNumbers]
+[-Variables::RequireLocalizedPunctuationVars]
+[-InputOutput::ProhibitOneArgSelect]
+[-Variables::ProhibitPunctuationVars]
+[-Editor::RequireEmacsFileVariables]
+[-Miscellanea::RequireRcsKeywords]
+[-CodeLayout::RequireTidyCode]
+[-CodeLayout::RequireUseUTF8]
+[-ValuesAndExpressions::RestrictLongStrings]
+[-RegularExpressions::RequireLineBoundaryMatching]
+[-RegularExpressions::RequireExtendedFormatting]
+[-RegularExpressions::ProhibitFixedStringMatches]
+[-ControlStructures::ProhibitCascadingIfElse]
+
+
+[-CodeLayout::ProhibitParensWithBuiltins]
+[-ValuesAndExpressions::ProhibitNoisyQuotes]
+[-ValuesAndExpressions::ProhibitNoisyQuotes]
+[-Lax::ProhibitEmptyQuotes::ExceptAsFallback]
+[-ValuesAndExpressions::ProhibitEmptyQuotes]
+[-ValuesAndExpressions::RequireInterpolationOfMetachars]
+[-Bangs::ProhibitNumberedNames]
+[-Variables::ProhibitPackageVars]
+[-ValuesAndExpressions::ProhibitAccessOfPrivateData]
+[-RegularExpressions::ProhibitCaptureWithoutTest]
+[-Bangs::ProhibitVagueNames]
+[-ControlStructures::ProhibitPostfixControls]
+[-Modules::RequireBarewordIncludes]
+[-ValuesAndExpressions::RequireNumberSeparators]
+[-Bangs::ProhibitFlagComments]
+[-References::ProhibitDoubleSigils]
+[-Bangs::ProhibitCommentedOutCode]
+[-Modules::ProhibitExcessMainComplexity]
+[-BuiltinFunctions::RequireBlockGrep]
+[-Variables::ProhibitLocalVars]
+[-ValuesAndExpressions::ProhibitImplicitNewlines]
+[-BuiltinFunctions::ProhibitStringyEval]
+[-Lax::ProhibitStringyEval::ExceptForRequire]
+[-Modules::ProhibitMultiplePackages]
+[-Subroutines::ProhibitExplicitReturnUndef]
+[-ValuesAndExpressions::ProhibitMixedBooleanOperators]
+[-Subroutines::RequireArgUnpacking]
+[-Subroutines::ProhibitExportingUndeclaredSubs]
+[-Modules::ProhibitAutomaticExportation] 
+[-Subroutines::ProtectPrivateSubs]
+[-Documentation::RequirePODUseEncodingUTF8]
+[-Subroutines::ProhibitExcessComplexity]
+
+## Fails to be excluded for Pg.pm:
+[-Subroutines::ProhibitCallsToUndeclaredSubs]
+
+## Mostly needed for the test files
+[-Modules::RequireVersionVar]
+[-Modules::RequirePerlVersion]
+[-Modules::PerlMinimumVersion]
+[-ErrorHandling::RequireUseOfExceptions]
+[-ValuesAndExpressions::ProhibitEscapedCharacters]
+[-BuiltinFunctions::ProhibitSleepViaSelect]
+

Modified: DBD-Pg/trunk/MANIFEST
==============================================================================
--- DBD-Pg/trunk/MANIFEST       (original)
+++ DBD-Pg/trunk/MANIFEST       Sat Jan 12 20:15:04 2008
@@ -14,6 +14,7 @@
 README.win32
 README.dev
 win32.mak
+.perlcriticrc
 t/dbdpg_test_setup.pl
 t/00-signature.t
 t/00basic.t

Added: DBD-Pg/trunk/t/99_perlcritic.t
==============================================================================
--- (empty file)
+++ DBD-Pg/trunk/t/99_perlcritic.t      Sat Jan 12 20:15:04 2008
@@ -0,0 +1,124 @@
+#!perl
+
+## Run Perl::Critic against the source code and the tests
+## This is highly customized, so take with a grain of salt
+## Mostly useful for the core developer(s)
+## Requires TEST_CRITIC to be set
+
+use strict;
+use warnings;
+use Test::More;
+use Data::Dumper;
+select(($|=1,select(STDERR),$|=1)[1]);
+
+if (!$ENV{TEST_CRITIC}) {
+       plan skip_all => 'Set the environment variable TEST_CRITIC to enable 
this test';
+}
+elsif (!eval { require Perl::Critic; 1 }) {
+       plan skip_all => 'Could not find Perl::Critic';
+}
+elsif ($Perl::Critic::VERSION < 0.23) {
+       plan skip_all => 'Perl::Critic must be version 0.23 or higher';
+}
+else {
+       plan tests => 1;
+}
+
+## Specific exclusions:
+my %ok =
+       (yaml => {
+                         sub => 'meta_spec_ok',
+                         },
+        pod => {
+                        sub => 'pod_file_ok pod_coverage_ok',
+                        },
+        signature => {
+                        sub => 'verify SIGNATURE_OK',
+                        },
+        Pg => {
+                       sub => 'foo',
+                       }
+);
+
+
+for my $f (keys %ok) {
+       for my $ex (keys %{$ok{$f}}) {
+               if ($ex eq 'sub') {
+                       for my $foo (split /\s+/ => $ok{$f}{sub}) {
+                               push @{$ok{$f}{OK}} => qr{Subroutine "$foo" 
(?:is neither|not exported)};
+                       }
+               }
+               else {
+                       die "Unknown exception '$ex'\n";
+               }
+       }
+}
+
+## Check the non-test files
+my $critic = Perl::Critic->new(-severity => 4, '-profile-strictness', 'quiet');
+
+for my $filename (qw/Pg.pm/) {
+       -e $filename or die qq{Could not find $filename\n};
+       diag "Running Perl::Critic on $filename...\n";
+       my @bad = $critic->critique($filename);
+       my $baditems = 0;
+  VIO: for my $v (@bad) {
+               my $d = $v->description();
+               my $f = $v->filename();
+               next if $d =~ /Subroutine "SQL_\w+" (?:not exported|is 
neither)/;
+               next if $d =~ /Subroutine "pg_\w+" not exported/;
+               next if $d =~ /Subroutine "looks_like_number" not exported/;
+               for my $k (sort keys %ok) {
+                       next unless $f =~ /$k/;
+                       for (@{$ok{$k}{OK}}) {
+                               next VIO if $d =~ $_;
+                       }
+               }
+               $baditems++;
+               my $l = $v->location();
+               my $line = $l->[0];
+               my $policy = $v->policy();
+               my $source = $v->source();
+               diag "$d ($f: $line)\n";
+               diag "[-$policy]\n";
+               diag "S=$source\n\n";
+       }
+}
+
+$critic = Perl::Critic->new(-severity => 1, -theme => 'core');
+
+## Allow Test::More subroutines
+my $tm = join '|' => (qw/skip plan pass fail is ok diag BAIL_OUT/);
+my $testmoreok = qr{Subroutine "$tm" is neither};
+
+opendir my $dir, 't' or die qq{Could not open directory 't': $!\n};
+my @files = map { "t/$_" } grep { /\.t$/ } readdir $dir;
+closedir $dir;
+
+for my $filename (@files) {
+       diag "Running Perl::Critic on $filename...\n";
+       my @bad = $critic->critique($filename);
+       my $baditems = 0;
+  VIO: for my $v (@bad) {
+               my $d = $v->description();
+               my $f = $v->filename();
+               next if $d =~ $testmoreok;
+               for my $k (sort keys %ok) {
+                       next unless $f =~ /$k/;
+                       for (@{$ok{$k}{OK}}) {
+                               next VIO if $d =~ $_;
+                       }
+               }
+               $baditems++;
+               my $l = $v->location();
+               my $line = $l->[0];
+               my $policy = $v->policy();
+               my $source = $v->source();
+               diag "$d ($f: $line)\n";
+               diag "[-$policy]\n";
+               diag "S=$source\n\n";
+       }
+}
+
+pass('Finished Perl::Critic testing');
+

Reply via email to