line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Csistck::Test; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
350
|
use 5.010; |
|
17
|
|
|
|
|
52
|
|
4
|
17
|
|
|
17
|
|
81
|
use strict; |
|
17
|
|
|
|
|
25
|
|
|
17
|
|
|
|
|
390
|
|
5
|
17
|
|
|
17
|
|
74
|
use warnings; |
|
17
|
|
|
|
|
23
|
|
|
17
|
|
|
|
|
511
|
|
6
|
|
|
|
|
|
|
|
7
|
17
|
|
|
17
|
|
78
|
use base 'Exporter'; |
|
17
|
|
|
|
|
23
|
|
|
17
|
|
|
|
|
1393
|
|
8
|
17
|
|
|
17
|
|
6865
|
use Csistck::Oper; |
|
17
|
|
|
|
|
48
|
|
|
17
|
|
|
|
|
1231
|
|
9
|
17
|
|
|
17
|
|
8663
|
use Csistck::Test::Return; |
|
17
|
|
|
|
|
49
|
|
|
17
|
|
|
|
|
622
|
|
10
|
|
|
|
|
|
|
|
11
|
17
|
|
|
17
|
|
94
|
use Scalar::Util qw/blessed/; |
|
17
|
|
|
|
|
19
|
|
|
17
|
|
|
|
|
13955
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
35
|
|
|
35
|
0
|
1989
|
my $class = shift; |
15
|
35
|
|
|
|
|
48
|
my $target = shift; |
16
|
|
|
|
|
|
|
|
17
|
35
|
|
|
|
|
280
|
bless { |
18
|
|
|
|
|
|
|
desc => "Unidentified test", |
19
|
|
|
|
|
|
|
target => $target, |
20
|
|
|
|
|
|
|
on_repair => undef, |
21
|
|
|
|
|
|
|
@_ |
22
|
|
|
|
|
|
|
}, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
10
|
|
|
10
|
0
|
38
|
sub desc { shift->{desc}; } |
26
|
16
|
|
|
16
|
0
|
52
|
sub target { shift->{target}; } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub on_repair { |
29
|
4
|
|
|
4
|
0
|
70
|
my $func = shift->{on_repair}; |
30
|
4
|
50
|
|
|
|
39
|
return $func if (ref $func eq 'CODE'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# This is used to wrap processes |
34
|
|
|
|
|
|
|
sub execute { |
35
|
25
|
|
|
25
|
0
|
266
|
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
|
|
|
0
|
|
122
|
my $func = sub {}; |
40
|
25
|
100
|
|
|
|
164
|
unless ($self->can($mode)) { |
41
|
2
|
|
|
|
|
16
|
return $self->fail('Test missing mode'); |
42
|
|
|
|
|
|
|
# TODO make this better error |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
23
|
|
|
|
|
157
|
given ($mode) { |
46
|
23
|
50
|
|
17
|
|
66
|
when ("check") { $func = sub { $self->check } if ($self->can('check')); } |
|
17
|
|
|
|
|
191
|
|
|
17
|
|
|
|
|
62
|
|
47
|
6
|
50
|
|
6
|
|
20
|
when ("repair") { $func = sub { $self->repair } if ($self->can('repair')); } |
|
6
|
|
|
|
|
105
|
|
|
6
|
|
|
|
|
40
|
|
48
|
0
|
0
|
|
0
|
|
0
|
when ("diff") { $func = sub { $self->diff } if ($self->can('diff')); } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
23
|
|
|
|
|
81
|
Csistck::Oper::info($self->desc); |
52
|
23
|
|
|
|
|
206
|
my $ret = eval { &{$func}; }; |
|
23
|
|
|
|
|
33
|
|
|
23
|
|
|
|
|
42
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Catch errors |
55
|
23
|
50
|
|
|
|
95
|
if ($@) { |
56
|
0
|
|
|
|
|
0
|
my $error = $@; |
57
|
0
|
|
|
|
|
0
|
$error =~ s/ at [A-Za-z0-9\/\_\-\.]+ line [0-9]+.\n//; |
58
|
0
|
|
|
|
|
0
|
Csistck::Oper::error(sprintf("%s: %s", $self->desc, $error)); |
59
|
0
|
|
|
|
|
0
|
return $self->fail($error); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Return should be an object from now on. If not blessed, assume ret value |
63
|
23
|
50
|
33
|
|
|
293
|
if (blessed($ret) and $ret->isa('Csistck::Test::Return')) { |
64
|
23
|
|
|
|
|
96
|
Csistck::Oper::info($ret->msg); |
65
|
23
|
|
|
|
|
184
|
return $ret; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
0
|
|
|
|
|
0
|
return $self->ret($ret, "Test response"); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Return test response |
73
|
|
|
|
|
|
|
sub ret { |
74
|
29
|
|
|
29
|
0
|
111
|
my ($self, $resp, $msg) = @_; |
75
|
29
|
|
|
|
|
230
|
return Csistck::Test::Return->new( |
76
|
|
|
|
|
|
|
desc => $self->desc, |
77
|
|
|
|
|
|
|
resp => $resp, |
78
|
|
|
|
|
|
|
msg => $msg |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
} |
81
|
13
|
|
|
13
|
0
|
88
|
sub fail { shift->ret(0, @_); } |
82
|
16
|
|
|
16
|
0
|
94
|
sub pass { shift->ret(1, @_); } |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |