Csistck/Test.pm

filter: Statementstmt 86.4% 51 / 59 Branchbran 50.0% 7 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 8 totaltotal 72.3% 76 / 105 SCAR 22.9
CC
9
Cov
78%
execute
11.5
on_repair
2.1
__ANON__
2.0
CRAP 9.9
« Csistck/Term.pm ↑ Summary Csistck/Oper.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 sub new {
14 35 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
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 sub on_repair {
29 4 ▶ my $func = shift->{on_repair};
Subroutine on_repair: called CC=2 SCAR=7.2
Pod undocumented
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 sub execute {
35 25 ▶ my ($self, $mode) = @_;
Subroutine execute: called CC=8 SCAR=24.5
Pod undocumented
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 Csistck::Oper::info($ret->msg);
65 23 return $ret;
66 }
67 else {
68 0 return $self->ret($ret, "Test response");
69 }
70 }
71  
72 # Return test response
73 sub ret {
74 29 ▶ my ($self, $resp, $msg) = @_;
Subroutine ret: called CC=1 SCAR=0.0
Pod undocumented
75 29 return Csistck::Test::Return->new(
76 desc => $self->desc,
77 resp => $resp,
78 msg => $msg
79 );
80 }
81 13 ▶sub fail { shift->ret(0, @_); }
Subroutine fail: called CC=1 SCAR=0.0
Pod undocumented
82 16 ▶sub pass { shift->ret(1, @_); }
Subroutine pass: called CC=1 SCAR=0.0
Pod undocumented
83  
84 17 1;
« Csistck/Term.pm ↑ Summary Csistck/Oper.pm »