| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::ape::test; |
|
2
|
|
|
|
|
|
|
$App::ape::test::VERSION = '0.001'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Run a test manually and upload the results to Elasticsearch |
|
5
|
|
|
|
|
|
|
# PODNAME: App::Ape::test |
|
6
|
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
119398
|
use strict; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
70
|
|
|
8
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
83
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1666
|
use Getopt::Long qw{GetOptionsFromArray}; |
|
|
3
|
|
|
|
|
22479
|
|
|
|
3
|
|
|
|
|
12
|
|
|
11
|
3
|
|
|
3
|
|
1475
|
use App::Prove::Elasticsearch::Utils; |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
102
|
|
|
12
|
3
|
|
|
3
|
|
408
|
use Pod::Usage; |
|
|
3
|
|
|
|
|
35871
|
|
|
|
3
|
|
|
|
|
292
|
|
|
13
|
3
|
|
|
3
|
|
1139
|
use File::Temp; |
|
|
3
|
|
|
|
|
27586
|
|
|
|
3
|
|
|
|
|
214
|
|
|
14
|
3
|
|
|
3
|
|
21
|
use POSIX qw{strftime}; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
24
|
|
|
15
|
3
|
|
|
3
|
|
4011
|
use File::Basename qw{basename dirname}; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
2277
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
4
|
|
|
4
|
1
|
1790
|
my ($class, @args) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
9
|
my (%options, @conf, $help); |
|
21
|
|
|
|
|
|
|
GetOptionsFromArray( |
|
22
|
|
|
|
|
|
|
\@args, |
|
23
|
|
|
|
|
|
|
'defect=s@' => \$options{defects}, |
|
24
|
|
|
|
|
|
|
'configure=s@' => \@conf, |
|
25
|
|
|
|
|
|
|
'status=s' => \$options{status}, |
|
26
|
|
|
|
|
|
|
'elapsed=s' => \$options{elapsed}, |
|
27
|
|
|
|
|
|
|
'body=s' => \$options{body}, |
|
28
|
4
|
|
|
|
|
22
|
'help' => \$help |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#Deliberately exiting here, as I "unit" test this as the binary |
|
32
|
4
|
50
|
|
|
|
1601
|
pod2usage(0) if $help; |
|
33
|
|
|
|
|
|
|
|
|
34
|
4
|
100
|
|
|
|
9
|
if (!$options{status}) { |
|
35
|
1
|
|
|
|
|
7
|
pod2usage( |
|
36
|
|
|
|
|
|
|
-exitval => "NOEXIT", |
|
37
|
|
|
|
|
|
|
-msg => "Insufficient arguments. You must pass a status.", |
|
38
|
|
|
|
|
|
|
); |
|
39
|
1
|
|
|
|
|
2681
|
return 1; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
3
|
100
|
|
|
|
6
|
if (!scalar(@args)) { |
|
43
|
1
|
|
|
|
|
5
|
pod2usage( |
|
44
|
|
|
|
|
|
|
-exitval => "NOEXIT", |
|
45
|
|
|
|
|
|
|
-msg => "Insufficient arguments. You must pass at least one test.", |
|
46
|
|
|
|
|
|
|
); |
|
47
|
1
|
|
|
|
|
2242
|
return 2; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
5
|
my $conf = App::Prove::Elasticsearch::Utils::process_configuration(@conf); |
|
51
|
|
|
|
|
|
|
|
|
52
|
2
|
100
|
|
|
|
11
|
if ( |
|
53
|
|
|
|
|
|
|
scalar( |
|
54
|
|
|
|
|
|
|
grep { |
|
55
|
2
|
|
|
|
|
3
|
my $subj = $_; |
|
56
|
2
|
|
|
|
|
3
|
grep { $subj eq $_ } qw{server.host server.port} |
|
|
4
|
|
|
|
|
8
|
|
|
57
|
|
|
|
|
|
|
} keys(%$conf) |
|
58
|
|
|
|
|
|
|
) != 2 |
|
59
|
|
|
|
|
|
|
) { |
|
60
|
1
|
|
|
|
|
4
|
pod2usage( |
|
61
|
|
|
|
|
|
|
-exitval => "NOEXIT", |
|
62
|
|
|
|
|
|
|
-msg => |
|
63
|
|
|
|
|
|
|
"Insufficient information provided to associate defect with test results to elasticsearch", |
|
64
|
|
|
|
|
|
|
); |
|
65
|
1
|
|
|
|
|
2223
|
return 3; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
19
|
$0 = "ape test: starting up"; |
|
69
|
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
4
|
my $self = {options => \%options}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
4
|
$self->{indexer} = App::Prove::Elasticsearch::Utils::require_indexer($conf); |
|
73
|
1
|
|
|
|
|
4
|
&{\&{$self->{indexer} . "::check_index"}}($conf); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
4
|
my $searcher = App::Prove::Elasticsearch::Utils::require_searcher($conf); |
|
76
|
1
|
|
|
|
|
7
|
$self->{searcher} = $searcher->new($conf, $self->{indexer}); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$self->{versioner} = |
|
79
|
1
|
|
|
|
|
5
|
App::Prove::Elasticsearch::Utils::require_versioner($conf); |
|
80
|
1
|
|
|
|
|
4
|
$self->{version} = &{\&{$self->{versioner} . "::get_version"}}(); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
81
|
|
|
|
|
|
|
my @cases = map { |
|
82
|
1
|
|
|
|
|
3
|
{ |
|
83
|
|
|
|
|
|
|
name => $_, |
|
84
|
1
|
|
|
|
|
3
|
version => &{\&{$self->{versioner} . "::get_file_version"}}($_) |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
} @args; |
|
87
|
1
|
|
|
|
|
7
|
$self->{cases} = \@cases; |
|
88
|
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
2
|
$self->{blamer} = App::Prove::Elasticsearch::Utils::require_blamer($conf); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$self->{platformer} = |
|
92
|
1
|
|
|
|
|
4
|
App::Prove::Elasticsearch::Utils::require_platformer($conf); |
|
93
|
1
|
|
|
|
|
5
|
$self->{platforms} = &{\&{$self->{platformer} . "::get_platforms"}}(); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
9
|
return bless($self, $class); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub run { |
|
99
|
1
|
|
|
1
|
1
|
1009
|
my ($self) = @_; |
|
100
|
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
1
|
foreach my $case (@{$self->{cases}}) { |
|
|
1
|
|
|
|
|
5
|
|
|
102
|
2
|
|
|
|
|
16
|
$0 = "ape test : $case->{name}"; |
|
103
|
|
|
|
|
|
|
|
|
104
|
2
|
50
|
|
|
|
38
|
if (!-f $case->{name}) { |
|
105
|
2
|
|
|
|
|
34
|
print "No such case $case->{name} on filesystem, skipping.\n"; |
|
106
|
2
|
|
|
|
|
5
|
next; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
my $executor = |
|
109
|
0
|
|
|
|
|
0
|
&{\&{$self->{blamer} . "::get_responsible_party"}}($case->{name}); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
my $occurred = time(); |
|
112
|
0
|
|
|
|
|
0
|
my $output = $self->get_test_commentary(); |
|
113
|
0
|
|
|
|
|
0
|
my $elapsed = time() - $occurred; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $upload = { |
|
116
|
|
|
|
|
|
|
body => $output, |
|
117
|
|
|
|
|
|
|
elapsed => $elapsed, |
|
118
|
|
|
|
|
|
|
occurred => strftime("%Y-%m-%d %H:%M:%S", localtime($occurred)), |
|
119
|
|
|
|
|
|
|
status => $self->{options}{status}, |
|
120
|
|
|
|
|
|
|
platform => $self->{platforms}, |
|
121
|
|
|
|
|
|
|
executor => $executor, |
|
122
|
|
|
|
|
|
|
version => $self->{version}, |
|
123
|
|
|
|
|
|
|
test_version => $case->{version}, |
|
124
|
|
|
|
|
|
|
name => basename($case->{name}), |
|
125
|
0
|
|
|
|
|
0
|
path => dirname($case->{name}), |
|
126
|
|
|
|
|
|
|
}; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
eval { &{\&{$self->{indexer} . "::index_results"}}($upload) }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
129
|
0
|
0
|
|
|
|
0
|
print "$@\n" if $@; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
1
|
|
|
|
|
8
|
$0 = "ape test: shutting down"; |
|
132
|
1
|
|
|
|
|
5
|
return 0; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub get_test_commentary { |
|
136
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my ($fh, $filename); |
|
139
|
0
|
0
|
|
|
|
|
if ($self->{options}->{body}) { |
|
140
|
0
|
|
|
|
|
|
$filename = $self->{options}->{body}; |
|
141
|
|
|
|
|
|
|
} else { |
|
142
|
0
|
|
0
|
|
|
|
my $editor = $ENV{EDITOR} || $ENV{VISUAL}; |
|
143
|
0
|
0
|
|
|
|
|
die |
|
144
|
|
|
|
|
|
|
"Either pass --body or have EDITOR or VISUAL set to edit your test result body." |
|
145
|
|
|
|
|
|
|
unless $editor; |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
(undef, $filename) = File::Temp::tempfile(); |
|
148
|
0
|
|
|
|
|
|
my $pid = fork(); |
|
149
|
0
|
0
|
|
|
|
|
if (!$pid) { |
|
150
|
0
|
|
|
|
|
|
exec($editor, $filename); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
0
|
|
|
|
|
|
waitpid($pid, 0); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
die "No such file $filename!" unless -f $filename; |
|
156
|
0
|
|
|
|
|
|
my $out; |
|
157
|
0
|
|
|
|
|
|
open($fh, '<', $filename); |
|
158
|
0
|
|
|
|
|
|
while (<$fh>) { $out .= $_ } |
|
|
0
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
close $fh; |
|
160
|
0
|
0
|
|
|
|
|
die "Empty test update inside of $filename!" unless $out; |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return $out; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |