100_critic.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/perl
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use warnings;
  17. use Test::More;
  18. unless (defined $ENV{DPKG_DEVEL_MODE}) {
  19. plan skip_all => 'not running in development mode';
  20. }
  21. if (defined $ENV{srcdir}) {
  22. chdir $ENV{srcdir} or die "cannot chdir to source directory: $!";
  23. }
  24. if (not eval { require Test::Perl::Critic }) {
  25. plan skip_all => 'Test::Perl::Critic required to criticize code';
  26. }
  27. if (not eval { require Perl::Critic::Utils }) {
  28. plan skik_all => 'Perl::Critic::Utils required to criticize code';
  29. }
  30. my @policies = qw(
  31. BuiltinFunctions::ProhibitLvalueSubstr
  32. BuiltinFunctions::ProhibitReverseSortBlock
  33. BuiltinFunctions::ProhibitSleepViaSelect
  34. BuiltinFunctions::ProhibitStringySplit
  35. BuiltinFunctions::ProhibitUniversalCan
  36. BuiltinFunctions::ProhibitUniversalIsa
  37. BuiltinFunctions::RequireGlobFunction
  38. BuiltinFunctions::RequireSimpleSortBlock
  39. ClassHierarchies::ProhibitAutoloading
  40. ClassHierarchies::ProhibitExplicitISA
  41. ClassHierarchies::ProhibitOneArgBless
  42. CodeLayout::ProhibitQuotedWordLists
  43. CodeLayout::ProhibitTrailingWhitespace
  44. CodeLayout::RequireConsistentNewlines
  45. ControlStructures::ProhibitCStyleForLoops
  46. ControlStructures::ProhibitLabelsWithSpecialBlockNames
  47. ControlStructures::ProhibitUntilBlocks
  48. Documentation::RequirePackageMatchesPodName
  49. InputOutput::ProhibitBarewordFileHandles
  50. InputOutput::ProhibitInteractiveTest
  51. InputOutput::ProhibitJoinedReadline
  52. InputOutput::ProhibitOneArgSelect
  53. InputOutput::ProhibitReadlineInForLoop
  54. InputOutput::ProhibitTwoArgOpen
  55. InputOutput::RequireEncodingWithUTF8Layer
  56. Miscellanea::ProhibitFormats
  57. Miscellanea::ProhibitUnrestrictedNoCritic
  58. Miscellanea::ProhibitUselessNoCritic
  59. Modules::ProhibitEvilModules
  60. Modules::RequireBarewordIncludes
  61. Modules::RequireEndWithOne
  62. Modules::RequireExplicitPackage
  63. Modules::RequireFilenameMatchesPackage
  64. Objects::ProhibitIndirectSyntax
  65. RegularExpressions::RequireBracesForMultiline
  66. Subroutines::ProhibitExplicitReturnUndef
  67. Subroutines::ProhibitNestedSubs
  68. Subroutines::ProhibitReturnSort
  69. TestingAndDebugging::ProhibitNoStrict
  70. TestingAndDebugging::ProhibitNoWarnings
  71. TestingAndDebugging::RequireUseStrict
  72. TestingAndDebugging::RequireUseWarnings
  73. ValuesAndExpressions::ProhibitCommaSeparatedStatements
  74. ValuesAndExpressions::ProhibitComplexVersion
  75. ValuesAndExpressions::ProhibitInterpolationOfLiterals
  76. ValuesAndExpressions::ProhibitLongChainsOfMethodCalls
  77. ValuesAndExpressions::ProhibitMismatchedOperators
  78. ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters
  79. ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator
  80. ValuesAndExpressions::ProhibitVersionStrings
  81. ValuesAndExpressions::RequireConstantVersion
  82. ValuesAndExpressions::RequireQuotedHeredocTerminator
  83. ValuesAndExpressions::RequireUpperCaseHeredocTerminator
  84. Variables::ProhibitAugmentedAssignmentInDeclaration
  85. Variables::ProhibitPerl4PackageNames
  86. Variables::ProhibitUnusedVariables
  87. Variables::ProtectPrivateVars
  88. Variables::RequireNegativeIndices
  89. );
  90. Test::Perl::Critic->import(
  91. -profile => 'test/100_critic/perlcriticrc',
  92. -verbose => 8,
  93. -include => \@policies,
  94. -only => 1,
  95. );
  96. my @dirs = qw(test src/t utils/t scripts/t dselect scripts/Dpkg);
  97. my @files = glob 'scripts/Dpkg.pm scripts/*.pl scripts/changelog/*.pl';
  98. push @files, Perl::Critic::Utils::all_perl_files(@dirs);
  99. plan tests => scalar @files;
  100. for my $file (@files) {
  101. critic_ok($file);
  102. }