File: 50-complexity.t

package info (click to toggle)
libterm-extendedcolor-perl 0.504-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 1,036; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
# test sources by Perl Code Metrics System

use strict;
use warnings;
use Test::More;

unless(exists($ENV{RELEASE_TESTING})) {
  plan skip_all => 'these tests are for release candidate testing';
}

{
    ## no critic
    eval '
        use Perl::Metrics::Simple;
        use File::Find::Rule       ();
        use File::Find::Rule::Perl ();
    ';
}
plan skip_all => 'Perl::Metrics::Simple, File::Find::Rule and File::Find::Rule::Perl required' if $@;

# configure this to match your needs
my $max_complexity = 40;
my $max_lines      = 80;

my @files    = File::Find::Rule->perl_file->in(qw/ lib t /);
my $analzyer = Perl::Metrics::Simple->new;
my @subs;

foreach (@files) {
    my $analysis = $analzyer->analyze_files($_);
    push( @subs, $_ ) foreach ( @{ $analysis->subs } );
}

plan tests => ( scalar @subs ) * 2;

foreach my $sub (@subs) {
    my $name       = $sub->{name} . ' in ' . $sub->{path};
    my $complexity = $sub->{mccabe_complexity};
    my $lines      = $sub->{lines};

    ok( $complexity <= $max_complexity, "Cyclomatic comlexity for $name is too big ($complexity > $max_complexity)" );
    ok( $lines <= $max_lines,           "Lines count for $name is too big ($lines > $max_lines)" );
}