Csistck/Test.pm

filter: Statementstmt 86.8% 53 / 61 Branchbran 56.2% 9 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 8 totaltotal 73.3% 80 / 109 CC 10 SCAR 15.6
CC
10
Cov
79%
execute
12.4
on_repair
2.1
__ANON__
2.0
CRAP 4.8
« Csistck/Test/FileBase.pm ↑ Summary Csistck/Test/Pkg.pm »
1 package Csistck::Test;
2  
3 17 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 17 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use Csistck::Oper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use Csistck::Test::Return;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 35 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 35 my $class = shift;
15 35 my $target = shift;
16  
17 35 bless {
18 desc => "Unidentified test",
19 target => $target,
20 on_repair => undef,
21 @_
22 }, $class;
23 }
24  
25 10 ▶sub desc { shift->{desc}; }
Subroutine desc: called CC=1 SCAR=0.0
Pod undocumented
26 16 ▶sub target { shift->{target}; }
Subroutine target: called CC=1 SCAR=0.0
Pod undocumented
27  
28 4 ▶sub on_repair {
Subroutine on_repair: called CC=2 SCAR=7.2
Pod undocumented
29 4 my $func = shift->{on_repair};
30 4 ▶ return $func if (ref $func eq 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if ref $func eq "CODE" 4 0 4
31 }
32  
33 # This is used to wrap processes
34 25 ▶sub execute {
Subroutine execute: called CC=9 SCAR=25.2
Pod undocumented
35 25 my ($self, $mode) = @_;
36
37 # We will exit with pass here, as to not throw an error. It is not the fault
38 # of the user if the test has no check or repair operation
39 25 ▶ my $func = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
40 25 ▶ unless ($self->can($mode)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can($mode)) 2 23 25
41 2 return $self->fail('Test missing mode');
42 # TODO make this better error
43 };
44  
45 23 given ($mode) {
46 23 ▶ when ("check") { $func = sub { $self->check } if ($self->can('check')); }
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("check") 17 0 17
47 6 ▶ when ("repair") { $func = sub { $self->repair } if ($self->can('repair')); }
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("repair") 6 0 6
48 0 ▶ when ("diff") { $func = sub { $self->diff } if ($self->can('diff')); }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("diff") 0 0 0
49 }
50  
51 23 Csistck::Oper::info($self->desc);
52 23 my $ret = eval { &{$func}; };
53
54 # Catch errors
55 23 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 23 23
56 0 my $error = $@;
57 0 $error =~ s/ at [A-Za-z0-9\/\_\-\.]+ line [0-9]+.\n//;
58 0 Csistck::Oper::error(sprintf("%s: %s", $self->desc, $error));
59 0 return $self->fail($error);
60 }
61
62 # Return should be an object from now on. If not blessed, assume ret value
63 23 ▶ if (blessed($ret) and $ret->isa('Csistck::Test::Return')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ret) and $ret->isa('Csistck::Test::Return')) { } 23 0 23
Condition33%1/3
builtin::blessed($ret) and $ret->isa("Csistck::Test::Return")
!ll&&!rl&&r
0023
MC/DC0%0/2
builtin::blessed($ret) and $ret->isa("Csistck::Test::Return")
builtin::blessed($ret) $ret->isa("Csistck::Test::Return")
Truth table33%1/3
A and B
A= builtin::blessed($ret)B= $ret->isa("Csistck::Test::Return")
ABresult
0X0
100
111
64 23 ▶ if ($ret->resp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret->resp) { } 15 8 23
65 15 Csistck::Oper::info($ret->msg);
66 }
67 else {
68 8 Csistck::Oper::error($ret->msg);
69 }
70 23 return $ret;
71 }
72 else {
73 0 return $self->ret($ret, "Test response");
74 }
75 }
76  
77 # Return test response
78 29 ▶sub ret {
Subroutine ret: called CC=1 SCAR=0.0
Pod undocumented
79 29 my ($self, $resp, $msg) = @_;
80 29 return Csistck::Test::Return->new(
81 desc => $self->desc,
82 resp => $resp,
83 msg => $msg
84 );
85 }
86 13 ▶sub fail { shift->ret(0, @_); }
Subroutine fail: called CC=1 SCAR=0.0
Pod undocumented
87 16 ▶sub pass { shift->ret(1, @_); }
Subroutine pass: called CC=1 SCAR=0.0
Pod undocumented
88  
89 17 1;
« Csistck/Test/FileBase.pm ↑ Summary Csistck/Test/Pkg.pm »