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:
- Module have valid syntax and have strict and warnings pragmas - thanks to Test::Strict
- Module have only unix line endings and not have whitespaces in the end of line - thanks to Test::EOL
- Module have no FIXME notes - thanks to Test::Fixme
- Module have no soft breakpoints for perl debugger - thanks to Test::NoBreakpoints
- Module have no tabs - thanks to Test::NoTabs
- Module distribution looks good to upload to cpan - thanks to Test::Kwalitee
- 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.
- Module code is conform to Perl Best Practice recommendation from Perl::Critic - thanks to Test::Perl::Critic
- Module has POD and it is valid - thanks to Test::Pod
- POD cover all methods - thanks to Test::Pod::Coverage
- POD is written on valid human language - thanks Test::Spelling
- The tests written for module cover needed percent of code - thanks to Test::Strict and Devel::Cover
- 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:
- Test for depth of conditional nesting code metric
- 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).
With Test::Kit, you can easily create a custom testing module to suit your individual needs.
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 http://search.cpan.org/dist/Dist-Zilla-PluginBundle-TestingMania 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
@Mithaldu Thanks, I saw this module, but now don't remember why I don't use it.
@ rjbs: Thanks, I found a couple interesting test modules in Dist::Zilla::PluginBundle::TestingMania
I experiment with Code::Statistics - if I rigth undestand ccomp it is cyclomatic complexity, but cyclomatic complexity is not depend of nesting, for this metric those codes is equal:
1. if(1){if(1){if(1){if(1){if(1){if(1){}}}}}};
2. if(1){};if(1){};if(1){};if(1){};if(1){};if(1){};
But now I need test for nesting level.
I don't understand that is sdepth metric - in my experiment sdepth already 0 or 1
I experiment with Code::Statistics - if I rigth undestand ccomp it is cyclomatic complexity, but cyclomatic complexity is not depend of nesting, for this metric those codes is equal:
1. if(1){if(1){if(1){if(1){if(1){if(1){}}}}}};
2. if(1){};if(1){};if(1){};if(1){};if(1){};if(1){};
But now I need test for nesting level.
I don't understand that is sdepth metric - in my experiment sdepth already 0 or 1