Last year I wrote a
short note about nonfunctional testing - i.e. about tests trying to identify an ugly and difficult to maintain code. Of course, such tests do not guarantee an ideal code, but they will provide some minimum quality level. despite the obviousness of the requirements of these tests, many ignore them and then have to understand the procedures for 5,000 lines.
The note in LiveJournal did not cause the expected feedback from me (I would like to know what I missed), so despite the resistance of Habr I decided to post a sequel here (thanks to the people who added karmas).
Since the publication of the first note, the following changes have occurred:
- added a test for cyclomatic complexity and the number of lines of a block of code (04_complexity.t); for cyclomatic complexity, the maximum was set to 20 (some suggest 30, but this each corrects - an increase in the probability of an erroneous fix, see
here ), the maximum number of lines in a block is set at random - 50, edit by yourself, but remember - if there are nested branches in the block and it needs to be scrolled on the screen, then it is already inefficient.
- added test for use warnings (05_warnings.t)
- the varnings in 08-code-coverage.t only appear on FreeBSD for me, on Ubuntu the test works fine, but I had to reduce the amount of coverage
- the result was posted on
githubgit clone git@github.com:worldmind/perl-test-code-quality-template.git
What do we know if all tests passed successfully?
We know that:
- the code is compiled without errors
- strict pragmas are included
- no FIXME left
-
Perl :: Critic believes that our code complies with Perl Best Practice
- cyclomatic complexity and the number of lines of the function (or code outside the function) do not exceed the threshold values
- there is POD in the code, it is correct and covers all functions
- a certain percentage of code is covered by tests
- distribution kit complies with CPAN formal requirements
It would be necessary to check the maximum nesting of conditions (5) and cycles (2) and maybe some more
code metrics , but I haven’t yet found the finished module, you may need to write.
upd. there is already a patch from
cub.uanic , tomorrow I'll take a look - kind of useful