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