bin/testrail-results

filter: Statementstmt 96.4% 217 / 225 Branchbran 78.8% 41 / 52 Conditioncond 66.6% 38 / 57 MC/DCmcdc 33.3% 10 / 30 Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 84.6% 320 / 378 CC 68 SCAR 40.4
CC
68
Cov
89%
run
71.7
_elapsed2secs
5.0
BEGIN
1.0
CRAP 57.1
« blib/lib/TestRail/Utils/Find.pm ↑ Summary blib/lib/Test/Rail/Parser.pm »
1 #!/usr/bin/perl
2 # ABSTRACT: List results for specified test(s).
3 # PODNAME: TestRail::Bin::Results
4  
5 package TestRail::Bin::Results;
6 1 $TestRail::Bin::Results::VERSION = '0.052';
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use TestRail::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use TestRail::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use TestRail::Utils::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Getopt::Long qw{GetOptionsFromArray};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::HomeDir qw{my_home};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Statistics::Descriptive;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use List::MoreUtils qw{uniq};
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Basename qw{basename};
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶if ( !caller() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller()) 0 1 1
23 0 my ( $out, $code ) = run( 'args' => \@ARGV );
24 0 print "$out\n";
25 0 exit $code;
26 }
27  
28 14 ▶sub run {
Subroutine run: called CC=64 SCAR=42.7
29 14 my %params = @_;
30 14 my $opts = {};
31  
32 #Parse config file if we are missing api url/key or user
33 14 ▶ my $homedir = my_home() || '.';
Condition50%1/2
my_home() || '.'
l!l
140
MC/DC0%0/1
my_home() || '.'
my_home()
Truth table50%1/2
A
A= my_home()
Aresult
11
00
34 14 ▶ if ( -e $homedir . '/.testrailrc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $homedir . '/.testrailrc') 0 14 14
35 0 $opts = TestRail::Utils::parseConfig($homedir);
36 }
37  
38 GetOptionsFromArray(
39 $params{'args'},
40 'apiurl=s' => \$opts->{'apiurl'},
41 'password=s' => \$opts->{'password'},
42 'user=s' => \$opts->{'user'},
43 'j|project=s@' => \$opts->{'projects'},
44 'p|plan=s@' => \$opts->{'plans'},
45 'r|run=s@' => \$opts->{'runs'},
46 'e|encoding=s' => \$opts->{'encoding'},
47 'g|grep=s' => \$opts->{'pattern'},
48 'd|defect=s@' => \$opts->{'defects'},
49 'v|version=s@' => \$opts->{'versions'},
50 'c|cachefile=s@' => \$opts->{'cachefile'},
51 'f|fast' => \$opts->{'fast'},
52 'json' => \$opts->{'json'},
53 'perfile=s' => \$opts->{'perfile'},
54 'm|merged' => \$opts->{'merged'},
55 14 'h|help' => \$opts->{'help'},
56 );
57  
58 14 ▶ if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"help"}) 1 13 14
59  
60 13 ▶ die("No tests passed") unless scalar( @{ $params{'args'} } );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$params{"args"};} 0 13 13
61  
62 13 $opts->{'browser'} = $params{'browser'};
63  
64 13 TestRail::Utils::interrogateUser( $opts, qw{apiurl user password} );
65  
66 13 my $tr = TestRail::Utils::getHandle($opts);
67 13 my $prior_search;
68 13 my $prior_runs = [];
69 13 my $prior_plans = [];
70 13 my $prior_hash = {};
71 13 my @prior_versions;
72 13 ▶ if ( $opts->{'cachefile'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"cachefile"}) 2 11 13
73 2 foreach my $cf ( @{ $opts->{cachefile} } ) {
74 2 ▶ die("Prior search file '$cf' passed does not exist")
Branch: 1 branch
BranchTrueFalseTotal
if $cf and not -e $cf 0 2 2
Condition33%1/3
$cf and not -e $cf
!ll&&!rl&&r
020
MC/DC0%0/2
$cf and not -e $cf
$cf not -e $cf
Truth table33%1/3
A and not(B)
A= $cfB= not -e $cf
ABresult
0X0
100
111
75 if $cf && !( -e $cf );
76 2 my $raw_text = '';
77 2 ▶ open( my $fh, '<', $cf ) or die "Could not open $cf";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $cf or die "Could not open $cf" 2 0 2
78 2 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 2 2 4
79 2 $raw_text .= $_;
80 }
81 2 close($fh);
82 2 $prior_search = JSON::MaybeXS::decode_json($raw_text);
83 2 foreach my $key ( keys(%$prior_search) ) {
84 2 ▶ my $str_str = $prior_search->{search_string} // '';
Condition50%1/2
$prior_search->{"search_string"} // ""
l!l
02
MC/DC0%0/1
$prior_search->{"search_string"} // ""
$prior_search->{"search_string"}
Truth table50%1/2
A
A= $prior_search->{"search_string"}
Aresult
11
00
85 2 ▶ my $str_pat = $opts->{pattern} // '';
Condition50%1/2
$opts->{"pattern"} // ""
l!l
02
MC/DC0%0/1
$opts->{"pattern"} // ""
$opts->{"pattern"}
Truth table50%1/2
A
A= $opts->{"pattern"}
Aresult
11
00
86 2 ▶ if ( $str_str ne $str_pat ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str_str ne $str_pat) 0 2 2
87 0 print
88 "Cached data in $cf has search pattern mismatch, skipping...\n";
89 0 next;
90 }
91 2 ▶ $prior_hash->{$key} = $prior_search->{$key} if $opts->{merged};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"merged"} 1 1 2
92  
93 #Ensure that we have all versions represented for every test watched in case we add platforms
94 2 ▶ if ( exists $prior_hash->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $prior_hash->{$key}) 1 1 2
95 1 foreach my $plt (
96 1 keys( %{ $prior_hash->{$key}->{versions_by_status} } ) )
97 {
98 1 ▶ delete $prior_hash->{$key}->{versions_by_status}->{$plt}
Branch: 1 branch
BranchTrueFalseTotal
unless $plt 0 1 1
99 if !$plt;
100 1 foreach my $v (
101 keys(
102 %{
103 $prior_hash->{$key}->{versions_by_status}
104 1 ->{$plt}
105 }
106 )
107 )
108 {
109 0 push( @prior_versions, $v );
110 }
111 }
112 }
113  
114 2 push( @$prior_runs, @{ $prior_search->{$key}->{'seen_runs'} } );
115 push( @$prior_plans,
116 2 @{ $prior_search->{$key}->{'seen_plans'} } );
117 }
118 2 @$prior_plans = uniq(@$prior_plans);
119 2 @$prior_runs = uniq(@$prior_runs);
120 2 $opts->{'plan_ids'} = $prior_plans;
121 2 $opts->{'run_ids'} = $prior_runs;
122 }
123 }
124  
125 my ( $res, $seen_plans, $seen_runs ) =
126 13 TestRail::Utils::Find::getResults( $tr, $opts, @{ $params{'args'} } );
127  
128 #Make sure subsequent runs keep ignoring the prior plans
129 13 push( @$seen_plans, @$prior_plans );
130  
131 13 my $statuses = $tr->getPossibleTestStatuses();
132 13 my %status_map;
133 117 @status_map{ map { $_->{'id'} } @$statuses } =
134 13 map { $_->{'label'} } @$statuses;
135  
136 13 my $out = '';
137 13 my $out_json = $prior_hash;
138  
139 13 foreach my $case ( keys(%$res) ) {
140 11 $out .= "#############################\n";
141 11 my $num_runs = 0;
142 11 my $casetotals = {};
143 11 my $versions_by_status = {};
144 11 my $defects = [];
145 11 my $seen_versions = [];
146 11 my $total_elapsed = 0;
147 11 my $avg_elapsed = 0;
148 11 my $median_runtime = 0;
149 11 my $elapsetotals = [];
150 11 ▶ $out_json->{$case} //= {};
Condition50%1/2
$out_json->{$case} //= {}
l!l
011
MC/DC0%0/1
$out_json->{$case} //= {}
$out_json->{$case}
Truth table50%1/2
A
A= $out_json->{$case}
Aresult
11
00
151  
152 11 foreach my $casedef ( @{ $res->{$case} } ) {
153 4336 $num_runs++;
154 4336 my $cplatform = 'default';
155 0 $cplatform = join( ',', sort @{ $casedef->{config_ids} } )
156 if ref( $casedef->{config_ids} ) eq 'ARRAY'
157 4336 ▶ && scalar( @{ $casedef->{config_ids} } );
Branch: 1 branch
BranchTrueFalseTotal
if ref $casedef->{"config_ids"} eq "ARRAY" and scalar @{$casedef->{"config_ids"};} 0 4336 4336
Condition50%1/2
ref $casedef->{"config_ids"} eq "ARRAY" and scalar @{$casedef->{"config_ids"};}
!ll
04336
MC/DC0%0/1
ref $casedef->{"config_ids"} eq "ARRAY" and scalar @{$casedef->{"config_ids"};}
ref $casedef->{"config_ids"} eq "ARRAY"
Truth table50%1/2
A
A= ref $casedef->{"config_ids"} eq "ARRAY"
Aresult
00
11
158 4336 ▶ $cplatform ||= 'default'
Condition50%1/2
$cplatform ||= "default"
l!l
43360
MC/DC0%0/1
$cplatform ||= "default"
$cplatform
Truth table50%1/2
A
A= $cplatform
Aresult
11
00
159 ; #XXX catch blank platform info, this can happen in some plans apparently
160 #$out .= "Found case '$case' in run $casedef->{run_id}\n";
161 4336 foreach my $result ( @{ $casedef->{results} } ) {
162 6636 ▶ if ( defined $result->{status_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result->{"status_id"}) 6636 0 6636
163  
164 #Assignment is handled as creating a new result with an undef status id
165 6636 $casetotals->{ $result->{status_id} }++;
166 6636 ▶ $versions_by_status->{$cplatform} //= {};
Condition100%2/2
$versions_by_status->{$cplatform} //= {}
l!l
662511
MC/DC100%1/1
$versions_by_status->{$cplatform} //= {}
$versions_by_status->{$cplatform}
Truth table100%2/2
A
A= $versions_by_status->{$cplatform}
Aresult
11
00
167 6636 ▶ if ( $result->{version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"version"}) 1527 5109 6636
168 1527 push( @$seen_versions, $result->{version} );
169 $versions_by_status->{$cplatform}
170 1527 ▶ ->{ $result->{version} } //= [];
Condition100%2/2
$versions_by_status->{$cplatform}{$result->{"version"}} //= []
l!l
15243
MC/DC100%1/1
$versions_by_status->{$cplatform}{$result->{"version"}} //= []
$versions_by_status->{$cplatform}{$result->{"version"}}
Truth table100%2/2
A
A= $versions_by_status->{$cplatform}{$result->{"version"}}
Aresult
11
00
171 push(
172 @{
173 $versions_by_status->{$cplatform}
174 ->{ $result->{version} }
175 1527 },
176 {
177 $status_map{ $result->{status_id} } =>
178 1527 "$tr->{apiurl}/index.php?/tests/view/$casedef->{id}"
179 }
180 );
181 }
182 }
183 push( @$defects, $result->{defects} )
184 6636 ▶ if $result->{defects} && ref( $result->{defects} ) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"defects"} and ref $result->{"defects"} ne "ARRAY" 0 6636 6636
Condition66%2/3
$result->{"defects"} and ref $result->{"defects"} ne "ARRAY"
!ll&&!rl&&r
561810180
MC/DC0%0/2
$result->{"defects"} and ref $result->{"defects"} ne "ARRAY"
$result->{"defects"} ref $result->{"defects"} ne "ARRAY"
Truth table66%2/3
A and B
A= $result->{"defects"}B= ref $result->{"defects"} ne "ARRAY"
ABresult
0X0
100
111
185 1018 push( @$defects, @{ $result->{defects} } )
186 6636 ▶ if $result->{defects} && ref( $result->{defects} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"defects"} and ref $result->{"defects"} eq "ARRAY" 1018 5618 6636
Condition66%2/3
$result->{"defects"} and ref $result->{"defects"} eq "ARRAY"
!ll&&!rl&&r
561801018
MC/DC50%1/2
$result->{"defects"} and ref $result->{"defects"} eq "ARRAY"
$result->{"defects"} ref $result->{"defects"} eq "ARRAY"
Truth table66%2/3
A and B
A= $result->{"defects"}B= ref $result->{"defects"} eq "ARRAY"
ABresult
0X0
100
111
187 6636 push( @$elapsetotals, _elapsed2secs( $result->{'elapsed'} ) );
188 }
189 }
190  
191 #Ensure versions_by_status has an entry per platform for every single version seen
192 11 @$seen_versions = uniq( ( @$seen_versions, @prior_versions ) );
193  
194 11 my @all_platforms = grep { $_ } uniq(
195 (
196 11 keys( %{ $out_json->{$case}->{versions_by_status} } ),
197 keys(%$versions_by_status)
198 )
199 );
200  
201 11 @$defects = uniq(@$defects);
202 11 foreach my $plt (@all_platforms) {
203 11 ▶ $out_json->{$case}->{versions_by_status}->{$plt} //= {};
Condition50%1/2
$out_json->{$case}{"versions_by_status"}{$plt} //= {}
l!l
011
MC/DC0%0/1
$out_json->{$case}{"versions_by_status"}{$plt} //= {}
$out_json->{$case}{"versions_by_status"}{$plt}
Truth table50%1/2
A
A= $out_json->{$case}{"versions_by_status"}{$plt}
Aresult
11
00
204 11 foreach my $ver ( keys( %{ $versions_by_status->{$plt} } ) ) {
205 3 @{ $versions_by_status->{$plt}->{$ver} } =
206 1524 sort { ( keys(%$a) )[0] cmp( keys(%$b) )[0] }
207 3 @{ $versions_by_status->{$plt}->{$ver} };
208 }
209 11 foreach my $v (@$seen_versions) {
210 3 ▶ $out_json->{$case}->{versions_by_status}->{$plt}->{$v} //= [];
Condition50%1/2
$out_json->{$case}{"versions_by_status"}{$plt}{$v} //= []
l!l
03
MC/DC0%0/1
$out_json->{$case}{"versions_by_status"}{$plt}{$v} //= []
$out_json->{$case}{"versions_by_status"}{$plt}{$v}
Truth table50%1/2
A
A= $out_json->{$case}{"versions_by_status"}{$plt}{$v}
Aresult
11
00
211 }
212 }
213  
214 #Initialize out_json correctly
215 11 ▶ $out_json->{$case}->{num_runs} //= 0;
Condition50%1/2
$out_json->{$case}{"num_runs"} //= 0
l!l
011
MC/DC0%0/1
$out_json->{$case}{"num_runs"} //= 0
$out_json->{$case}{"num_runs"}
Truth table50%1/2
A
A= $out_json->{$case}{"num_runs"}
Aresult
11
00
216 11 ▶ $out_json->{$case}->{seen_runs} //= [];
Condition50%1/2
$out_json->{$case}{"seen_runs"} //= []
l!l
011
MC/DC0%0/1
$out_json->{$case}{"seen_runs"} //= []
$out_json->{$case}{"seen_runs"}
Truth table50%1/2
A
A= $out_json->{$case}{"seen_runs"}
Aresult
11
00
217 11 ▶ $out_json->{$case}->{seen_plans} //= [];
Condition50%1/2
$out_json->{$case}{"seen_plans"} //= []
l!l
011
MC/DC0%0/1
$out_json->{$case}{"seen_plans"} //= []
$out_json->{$case}{"seen_plans"}
Truth table50%1/2
A
A= $out_json->{$case}{"seen_plans"}
Aresult
11
00
218 11 ▶ $out_json->{$case}->{elapsetotals} //= [];
Condition50%1/2
$out_json->{$case}{"elapsetotals"} //= []
l!l
011
MC/DC0%0/1
$out_json->{$case}{"elapsetotals"} //= []
$out_json->{$case}{"elapsetotals"}
Truth table50%1/2
A
A= $out_json->{$case}{"elapsetotals"}
Aresult
11
00
219 11 ▶ $out_json->{$case}->{defects} //= [];
Condition50%1/2
$out_json->{$case}{"defects"} //= []
l!l
011
MC/DC0%0/1
$out_json->{$case}{"defects"} //= []
$out_json->{$case}{"defects"}
Truth table50%1/2
A
A= $out_json->{$case}{"defects"}
Aresult
11
00
220 11 foreach my $status ( keys(%status_map) ) {
221 99 ▶ $out_json->{$case}->{ $status_map{$status} } //= 0;
Condition50%1/2
$out_json->{$case}{$status_map{$status}} //= 0
l!l
099
MC/DC0%0/1
$out_json->{$case}{$status_map{$status}} //= 0
$out_json->{$case}{$status_map{$status}}
Truth table50%1/2
A
A= $out_json->{$case}{$status_map{$status}}
Aresult
11
00
222 }
223  
224 11 my $pattern_output = '';
225 11 $out_json->{$case}->{search_string} = $opts->{'pattern'};
226 $pattern_output = " using search string '$opts->{pattern}'"
227 11 ▶ if $opts->{'pattern'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"pattern"} 1 10 11
228  
229 11 $out .= "$case was present in $num_runs runs$pattern_output.\n";
230 11 $out_json->{$case}->{'num_runs'} += $num_runs;
231 11 push( @{ $out_json->{$case}->{'seen_runs'} }, @$seen_runs );
232 11 push( @{ $out_json->{$case}->{'seen_plans'} }, @$seen_plans );
233  
234 #Collect time statistics
235 11 push( @{ $out_json->{$case}->{elapsetotals} }, @$elapsetotals );
236 11 my $timestats = Statistics::Descriptive::Full->new();
237 11 $timestats->add_data( @{ $out_json->{$case}->{elapsetotals} } );
238  
239 11 ▶ $out_json->{$case}->{total_elapsed} = $timestats->sum() || 0;
Condition100%2/2
$timestats->sum || 0
l!l
83
MC/DC100%1/1
$timestats->sum || 0
$timestats->sum
Truth table100%2/2
A
A= $timestats->sum
Aresult
11
00
240 11 $out .=
241 "Total time spent running this test: $out_json->{$case}->{total_elapsed} seconds\n";
242 11 ▶ $out_json->{$case}->{median_elapsed} = $timestats->median() || 0;
Condition100%2/2
$timestats->median || 0
l!l
83
MC/DC100%1/1
$timestats->median || 0
$timestats->median
Truth table100%2/2
A
A= $timestats->median
Aresult
11
00
243 11 $out .=
244 "Median time spent running this test: $out_json->{$case}->{median_elapsed} seconds\n";
245 11 ▶ $out_json->{$case}->{average_elapsed} = $timestats->mean() || 0;
Condition100%2/2
$timestats->mean || 0
l!l
83
MC/DC100%1/1
$timestats->mean || 0
$timestats->mean
Truth table100%2/2
A
A= $timestats->mean
Aresult
11
00
246 11 $out .=
247 "Mean time spent running this test: $out_json->{$case}->{average_elapsed} seconds\n";
248 $out_json->{$case}->{stdev_elapsed} =
249 11 ▶ $timestats->standard_deviation() || 0;
Condition100%2/2
$timestats->standard_deviation || 0
l!l
74
MC/DC100%1/1
$timestats->standard_deviation || 0
$timestats->standard_deviation
Truth table100%2/2
A
A= $timestats->standard_deviation
Aresult
11
00
250 11 $out .=
251 "Standard deviations of runtime in test: $out_json->{$case}->{stdev_elapsed}\n";
252 11 ▶ $out_json->{$case}->{max_elapsed} = $timestats->max() || 0;
Condition100%2/2
$timestats->max || 0
l!l
83
MC/DC100%1/1
$timestats->max || 0
$timestats->max
Truth table100%2/2
A
A= $timestats->max
Aresult
11
00
253 11 $out .=
254 "Maximum time spent running this test: $out_json->{$case}->{max_elapsed} seconds\n";
255 11 ▶ $out_json->{$case}->{min_elapsed} = $timestats->min() || 0;
Condition100%2/2
$timestats->min || 0
l!l
83
MC/DC100%1/1
$timestats->min || 0
$timestats->min
Truth table100%2/2
A
A= $timestats->min
Aresult
11
00
256 11 $out .=
257 "Minimum time spent running this test: $out_json->{$case}->{min_elapsed} seconds\n";
258 11 ▶ $out_json->{$case}->{times_executed} = $timestats->count() || 0;
Condition50%1/2
$timestats->count || 0
l!l
110
MC/DC0%0/1
$timestats->count || 0
$timestats->count
Truth table50%1/2
A
A= $timestats->count
Aresult
11
00
259 11 $out .=
260 "Num times this test has been executed: $out_json->{$case}->{times_executed}\n";
261  
262 11 foreach my $status ( keys(%$casetotals) ) {
263 18 $out .= "$status_map{$status}: $casetotals->{$status}\n";
264 $out_json->{$case}->{ $status_map{$status} } +=
265 18 $casetotals->{$status};
266 }
267  
268 11 foreach my $platform ( keys(%$versions_by_status) ) {
269 11 foreach
270 11 my $version ( keys( %{ $versions_by_status->{$platform} } ) )
271 {
272 $out .=
273 "Version $version in platform IDs ($platform) had statuses :\n"
274 . join( ',',
275 3 @{ $versions_by_status->{$platform}->{$version} } )
276 . "\n";
277 push(
278 @{
279 $out_json->{$case}->{versions_by_status}->{$platform}
280 3 ->{$version}
281 },
282 3 @{ $versions_by_status->{$platform}->{$version} }
283 );
284 @{ $out_json->{$case}->{versions_by_status}->{$platform}
285 3 ->{$version} } = uniq(
286 @{
287 3 $out_json->{$case}->{versions_by_status}->{$platform}
288 3 ->{$version}
289 }
290 );
291 }
292 }
293  
294 11 ▶ $out .= "\nDefects related to case:\n" . join( ',', @$defects ) . "\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$defects 2 9 11
295 if @$defects;
296 11 push( @{ $out_json->{$case}->{defects} }, @$defects );
297 11 @{ $out_json->{$case}->{defects} } =
298 11 uniq( @{ $out_json->{$case}->{defects} } );
299  
300 }
301  
302 13 ▶ if ( $opts->{'json'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"json"}) 5 8 13
303 5 my $coder = JSON::MaybeXS->new;
304 5 $coder->canonical(1);
305 5 ▶ return ( $coder->encode($out_json), 0 ) unless $opts->{'perfile'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"perfile"} 3 2 5
306  
307 2 ▶ die("no such directory $opts->{perfile}") unless -d $opts->{perfile};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $opts->{"perfile"} 1 1 2
308  
309 1 foreach my $test ( keys(%$out_json) ) {
310 1 my $tn = basename($test);
311 1 ▶ open( my $fh, '>', "$opts->{perfile}/$tn.json" )
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$opts->{"perfile"}/$tn.json] or die qq[could not open $opts->{"perfile"}/$tn.json] 1 0 1
312 or die "could not open $opts->{perfile}/$tn.json";
313 1 print $fh $coder->encode( { $test => $out_json->{$test} } );
314 1 close $fh;
315 }
316 1 return ( '', 0 );
317 }
318  
319 8 $out .= "#############################";
320 8 return ( $out, 0 );
321 }
322  
323 6640 ▶sub _elapsed2secs {
Subroutine _elapsed2secs: called CC=5 SCAR=16.1
324 6640 my $stamp = shift;
325 6640 ▶ return 0 if !$stamp;
Branch: 1 branch
BranchTrueFalseTotal
unless $stamp 1527 5113 6640
326 5113 my ($seconds) = $stamp =~ m/(\d*)s/;
327 5113 my ($seconds_minutes) = $stamp =~ m/(\d*)m/;
328 5113 my ($seconds_hours) = $stamp =~ m/(\d*)h/;
329 5113 ▶ return ( $seconds || 0 ) +
Branch: 2 branches
BranchTrueFalseTotal
$seconds_minutes ? : 2 5111 5113
$seconds_hours ? : 2 5111 5113
Condition100%2/2
$seconds || 0
l!l
51112
MC/DC100%1/1
$seconds || 0
$seconds
Truth table100%2/2
A
A= $seconds
Aresult
11
00
330 ( $seconds_minutes ? $seconds_minutes * 60 : 0 ) +
331 ( $seconds_hours ? $seconds_hours * 3600 : 0 );
332 }
333  
334 1 1;
335  
336 =pod
337  
338 =encoding UTF-8
339  
340 =head1 NAME
341  
342 TestRail::Bin::Results - List results for specified test(s).
343  
344 =head1 VERSION
345  
346 version 0.052
347  
348 =head1 SYNOPSIS
349  
350 testrail-results [OPTIONS] test1 test2 ...
351  
352 require `which testrail-results`;
353 TestRail::Bin::Results::run('args' => \@args);
354  
355 =head1 DESCRIPTION
356  
357 testrail-results - List results for specified test(s).
358  
359 Searches across multiple runs (and projects) for results for broad-based metrics; especially useful for diagnosing unreliable tests, and establishing defect density for certain features.
360  
361 Can be used as the modulino TestRail::Bin::Tests.
362 Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
363  
364 =head1 WARNING
365  
366 Searching across all projects can take a very long time for highly active TestRail Installations.
367 However, cross project metrics are also very useful.
368  
369 As such, the results from prior searches in json mode may be provided, and the runs previously analyzed therein will not be investigated again.
370  
371 It is up to the caller to integrate this data into their analysis as may be appropriate.
372  
373 =head1 PARAMETERS:
374  
375 =head2 MANDATORY PARAMETERS
376  
377 =over 4
378  
379 --apiurl : full URL to get to TestRail index document
380  
381 --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
382  
383 --user : Your TestRail User Name.
384  
385 =back
386  
387 All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
388  
389 =head2 SEMI-OPTIONAL PARAMETERS
390  
391 =over 4
392  
393 -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
394  
395 =back
396  
397 =head2 OPTIONAL PARAMETERS
398  
399 =over 4
400  
401 -j --project : Restrict search to provided project name. May be passed multiple times.
402  
403 -r --run : Restrict search to runs with the provided name. May be passed multiple times.
404  
405 -p --plan : Restrict search to plans with the provided name. May be passed multiple times.
406  
407 -g --grep : Restrict results printed to those matching the provided pattern. Great for looking for specific failure conditions.
408  
409 -v --version : Restrict results printed to those tested on the provided version(s). May be passed multiple times.
410  
411 -d --defect : Restrict results printed to those related to the provided defect(s). May be passed multiple times.
412  
413 -c --cachefile : Load the provided file as a place to pick up your search from. May be passed multiple times.
414  
415 -f --fast : Reduce the number of required HTTP requests at the cost of historical data (previous statuses in runs). Speeds up gathering a great deal when checking many tests.
416  
417 --json : Print results as a JSON serialization.
418  
419 -m --merged : In merge the output with the cached data provided (if any).
420  
421 --perfile : Output JSON summary data per file to the provided directory when in json mode
422  
423 =back
424  
425 =head1 CONFIGURATION FILE
426  
427 In your \$HOME, (or the current directory, if your system has no concept of a home directory) put a file called .testrailrc with key=value syntax separated by newlines.
428 Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
429 All options specified thereby are overridden by passing the command-line switches above.
430  
431 =head1 MISCELLANEOUS OPTIONS:
432  
433 =over 4
434  
435 --help : show this output
436  
437 =back
438  
439 =head1 NOTES
440  
441 One of the primary purposes of this script is to create CPANTesters style matrices per version/platform.
442 In --json mode, the 'versions_by_status' attribute will return a data structure looking like so:
443  
444 =over 4
445  
446 =item platform_ids: a comma separated value of the platform IDs the test was run on (sorted to prevent order oddities). This value is a hash key.
447  
448 =over 4
449  
450 =item versions: the direct version string reported. This key corresponds to an array value holding hashrefs with status IDs pointing towards result links, sorted by ID.
451  
452 =back
453  
454 =back
455  
456 The consumer of this should be able to render a color-coded table, much like CPANTesters does.
457  
458 =head1 SPECIAL THANKS
459  
460 Thanks to cPanel Inc, for graciously funding the creation of this distribution.
461  
462 =head1 AUTHOR
463  
464 George S. Baugh <teodesian@cpan.org>
465  
466 =head1 SOURCE
467  
468 The development version is on github at L<https://github.com/teodesian/TestRail-Perl>
469 and may be cloned from L<git://github.com/teodesian/TestRail-Perl.git>
470  
471 =head1 COPYRIGHT AND LICENSE
472  
473 This software is copyright (c) 2022 by George S. Baugh.
474  
475 This is free software; you can redistribute it and/or modify it under
476 the same terms as the Perl 5 programming language system itself.
477  
478 =cut
479  
480 __END__
« blib/lib/TestRail/Utils/Find.pm ↑ Summary blib/lib/Test/Rail/Parser.pm »