blib/lib/App/TestOnTap/ExecMap.pm

filter: Statementstmt 92.9% 53 / 57 Branchbran 50.0% 9 / 18 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 82.2% 74 / 90 SCAR 27.8
CC
15
Cov
83%
__parseExecMap
8.1
getMapping
6.0
hasMapping
5.6
CRAP 16.1
« blib/lib/App/TestOnTap/Harness.pm ↑ Summary blib/lib/App/TestOnTap/Preprocess.pm »
1 package App::TestOnTap::ExecMap;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use App::TestOnTap::Util qw(trim $IS_WINDOWS ensureArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 ▶use Grep::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # CTOR
11 #
12 sub new
13 {
14 27 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
15 27 my $cfg = shift;
16  
17 27 my $self = bless( {}, $class);
18 27 $self->__parseExecMap($cfg);
19
20 27 return $self;
21 }
22  
23 sub __parseExecMap
24 {
25 27 ▶ my $self = shift;
Subroutine __parseExecMap: called CC=8 SCAR=20.9
26 27 my $cfg = shift;
27  
28 27 my @matcherCmdlinePairs;
29  
30 27 my $emOrder = $cfg->{''}->{execmap};
31 27 ▶ if (!$emOrder)
Branch: 1 branch
BranchTrueFalseTotal
unless ($emOrder) 25 2 27
32 {
33 25 warn("WARNING: No execmap found, using internal default!\n");
34 25 $cfg = __defaultCfg();
35 25 $emOrder = $cfg->{''}->{execmap};
36 }
37 27 $emOrder = ensureArray($emOrder);
38
39 27 foreach my $em (@$emOrder)
40 {
41 202 my $emSec = $cfg->{"EXECMAP $em"};
42 202 ▶ die("Missing execmap section for '$em'\n") unless $emSec;
Branch: 1 branch
BranchTrueFalseTotal
unless $emSec 0 202 202
43  
44 # trip any unknown keys
45 #
46 202 warn("WARNING: Unknown key '$_' in execmap section '$em'\n") foreach (grep(!/^(match|cmd)$/, keys(%$emSec)));
47
48 # extract the ones we want
49 #
50 202 my $match = $emSec->{match};
51 202 ▶ my $cmd = $emSec->{cmd} || '';
Condition100%2/2
$emSec->{'cmd'} || ''
l!l
17725
MC/DC100%1/1
$emSec->{'cmd'} || ''
$emSec->{'cmd'}
Truth table100%2/2
A
A= $emSec->{'cmd'}
Aresult
11
00
52 202 ▶ die("The execmap section '$em' must have at least the 'match' key\n") unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 0 202 202
53  
54 # compile the query
55 #
56 202 my $matcher = Grep::Query->new($match);
57  
58 # we want to store the cmd as an array
59 # Config::Std allows it to be in multiple forms:
60 # a single line (we split it on space)
61 # a ready-made array (take as is)
62 # a string with embedded \n (split on that)
63 #
64 202 my $cmdline = ensureArray($cmd);
65
66 # now store the matcher and cmdline in an array so we can evaluate them
67 # in a defined order when we need to
68 #
69 202 push(@matcherCmdlinePairs, [ $matcher, $cmdline ]);
70 }
71  
72 # not much meaning in continuing if there are no mappings at all...!
73 #
74 27 ▶ die("No entries in the execmap\n") unless @matcherCmdlinePairs;
Branch: 1 branch
BranchTrueFalseTotal
unless @matcherCmdlinePairs 0 27 27
75  
76 27 $self->{mcpairs} = \@matcherCmdlinePairs;
77 }
78  
79 sub __defaultCfg
80 {
81 # TODO: add more useful standard mappings here
82 #
83 25 ▶ my %cfg =
Subroutine __defaultCfg: called CC=1 SCAR=0.0
84 (
85 '' =>
86 {
87 execmap => [qw(perl python java groovy shell autoit3 batch binary)]
88 },
89 'EXECMAP perl' =>
90 {
91 # well, a no-brainer...:-)
92 #
93 'match' => 'regexp[\.(t|pl)$]',
94 'cmd' => 'perl',
95 },
96 'EXECMAP python' =>
97 {
98 # if python is preferred...
99 #
100 'match' => 'regexp[\.py$]',
101 'cmd' => 'python',
102 },
103 'EXECMAP java' =>
104 {
105 # quite possible and important for java shops
106 # (couple with some nice junit and other helpers)
107 #
108 'match' => 'regexp[\.jar$]',
109 'cmd' => [qw(java -jar)],
110 },
111 'EXECMAP groovy' =>
112 {
113 # common variants for groovy scripts, I understand...
114 #
115 'match' => 'regexp[\.(groovy|gsh|gvy|gy)$]',
116 'cmd' => 'groovy',
117 },
118 'EXECMAP shell' =>
119 {
120 # shell scripting is powerful, so why not
121 #
122 'match' => 'regexp[\.sh$]',
123 'cmd' => 'sh',
124 },
125 'EXECMAP autoit3' =>
126 {
127 # For using AutoIt scripts (https://www.autoitscript.com/site/autoit/)
128 # (Windows only)
129 #
130 'match' => 'regexp[\.au3$]',
131 'cmd' => 'autoit3',
132 },
133 'EXECMAP batch' =>
134 {
135 # possible, but perhaps not likely
136 # (Windows only)
137 #
138 'match' => 'regexp[\.(bat|cmd)$]',
139 'cmd' => [qw(cmd.exe /c)],
140 },
141 'EXECMAP binary' =>
142 {
143 # for directly executable binaries, no actual 'cmd' is needed
144 # On Windows: rename 'xyz.exe' => 'xyz.tbin'
145 # On Unix: rename 'xyz' => 'xyz.tbin'
146 #
147 'match' => 'regexp[\.tbin$]',
148 },
149 );
150
151 25 return \%cfg;
152 }
153  
154 # just check if the given test has a mapping
155 #
156 sub hasMapping
157 {
158 56 ▶ my $self = shift;
Subroutine hasMapping: called CC=5 SCAR=17.2
Pod undocumented
159 56 my $testName = shift;
160
161 56 foreach my $matcherCmdlinePair (@{$self->{mcpairs}})
162 {
163 70 ▶ return 1 if $matcherCmdlinePair->[0]->qgrep($testName);
Branch: 1 branch
BranchTrueFalseTotal
if $matcherCmdlinePair->[0]->qgrep($testName) 54 16 70
164 }
165
166 2 ▶ if (defined($self->{delegate}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"delegate"}) 0 2 2
167 {
168 0 ▶ return 1 if $self->{delegate}->hasMapping($testName);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"delegate"}->hasMapping($testName) 0 0 0
169 }
170
171 2 return 0;
172 }
173  
174 # retrieve the cmdline map for the test
175 #
176 sub getMapping
177 {
178 48 ▶ my $self = shift;
Subroutine getMapping: called CC=4 SCAR=17.9
Pod undocumented
179 48 my $testName = shift;
180
181 48 foreach my $matcherCmdlinePair (@{$self->{mcpairs}})
182 {
183 48 ▶ return $matcherCmdlinePair->[1] if $matcherCmdlinePair->[0]->qgrep($testName);
Branch: 1 branch
BranchTrueFalseTotal
if $matcherCmdlinePair->[0]->qgrep($testName) 48 0 48
184 }
185
186 0 ▶ if (defined($self->{delegate}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"delegate"}) 0 0 0
187 {
188 0 return $self->{delegate}->getMapping($testName);
189 }
190
191 0 die("INTERNAL ERROR - should not reach this point!");
192 }
193  
194 19 1;
« blib/lib/App/TestOnTap/Harness.pm ↑ Summary blib/lib/App/TestOnTap/Preprocess.pm »