Non-functional perl code testing - automated code review

I saw a very ugly Perl code, and I think that is possible because no code review exist in project. But always we have a very little time for human code review. I search CPAN modules for basic level code review by machine. I hope that these modules help Perl people to avoid writing ugly code and help team leaders minimize time to code review. I try to collect founded modules in github repository and now want to describe what we know if all these test passed:

  1. Module have valid syntax and have strict and warnings pragmas - thanks to Test::Strict
  2. Module have only unix line endings and not have whitespaces in the end of line - thanks to Test::EOL
  3. Module have no FIXME notes - thanks to Test::Fixme
  4. Module have no soft breakpoints for perl debugger - thanks to Test::NoBreakpoints
  5. Module have no tabs - thanks to Test::NoTabs
  6. Module distribution looks good to upload to cpan - thanks to Test::Kwalitee
  7. Code units in module have required cyclomatic complexity and required lines of code - thanks to Perl::Metrics::Simple. I try to use Test::Perl::Metrics::Simple, but got problem with installing and write my own test.
  8. Module code is conform to Perl Best Practice recommendation from Perl::Critic - thanks to Test::Perl::Critic
  9. Module has POD and it is valid - thanks to Test::Pod
  10. POD cover all methods - thanks to Test::Pod::Coverage
  11. POD is written on valid human language - thanks Test::Spelling
  12. The tests written for module cover needed percent of code - thanks to Test::Strict and Devel::Cover
  13. Module has no memory leaks - thanks to Test::Weaken - this test is non functional, but because it is not universal (if we add method we must add test) I move it to 't' directory with functional tests

That I not found:

  1. Test for depth of conditional nesting code metric
  2. Test for code style - I found Test::PerlTidy, but it have some bugs, I wrote to author, he said than plan fix it

I try to collect maximum non-functional test collection - you can use that you need only. I hope that it post will be useful for somebody and I will be glad any comments.

Sorry, if my English is not good.


This is excellent, are you planning on creating a module that will aggregate all this testing goodness into a cohesive code review script?

@Erez: you should be able to use Test::Kit to handle this (untested).

package Test::Code::Review;

use Test::Kit qw(
); # add modules as needed

# and in your code:
use Test::Code::Review tests => $num_tests;
# ...

With Test::Kit, you can easily create a custom testing module to suit your individual needs.

  1. Test for depth of conditional nesting code metric

You can use and/or cannibalize parts of Code::Statistics for that. Specifically: Code::Statistics::Metric::ccomp

It also has some other metrics and lets you for example, measure nesting depth itself, so it warns when you have 14 blocks nested inside each other.

You might be interested in which has a similar catalog, and adds them all to your distribution for you.

My pluginbundle only collects testing regimes for which there is already a Dist::Zilla testing plugin. It is probably worth writing new plugins for some of what's mentioned here and including them. Patches welcome :D

Leave a comment

About Alexey Shrub

user-pic I blog about Perl.