bin/testrail-replay

filter: Statementstmt 91.3% 74 / 81 Branchbran 52.7% 19 / 36 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 73.4% 105 / 143 CC 23 SCAR 33.6
CC
23
Cov
76%
run
37.3
BEGIN
1.0
BEGIN
1.0
CRAP 28.8
« blib/lib/Test/Rail/Parser.pm ↑ Summary bin/testrail-report »
1 #!/usr/bin/perl
2 # ABSTRACT: List runs in a TestRail project matching the provided filters
3 # PODNAME: TestRail::Bin::Replay
4  
5 package TestRail::Bin::Replay;
6 1 $TestRail::Bin::Replay::VERSION = '0.052';
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use TestRail::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use TestRail::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use TestRail::Utils::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Getopt::Long qw{GetOptionsFromArray};
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use File::HomeDir qw{my_home};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶if ( !caller() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller()) 1 0 1
18 1 my ( $out, $code ) = run( 'args' => \@ARGV );
19 1 print $out;
20 1 exit $code;
21 }
22  
23 5 ▶sub run {
Subroutine run: called CC=23 SCAR=36.2
24 5 my %params = @_;
25 5 my $opts = {};
26  
27 # Parse config file
28 5 ▶ my $homedir = my_home() || '.';
Condition50%1/2
my_home() || '.'
l!l
50
MC/DC0%0/1
my_home() || '.'
my_home()
Truth table50%1/2
A
A= my_home()
Aresult
11
00
29 5 ▶ if ( -e $homedir . '/.testrailrc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $homedir . '/.testrailrc') 0 5 5
30 0 $opts = TestRail::Utils::parseConfig($homedir);
31 }
32  
33 GetOptionsFromArray(
34 $params{'args'},
35 'apiurl=s' => \$opts->{'apiurl'},
36 'password=s' => \$opts->{'password'},
37 'user=s' => \$opts->{'user'},
38 'j|project=s' => \$opts->{'project'},
39 'e|encoding=s' => \$opts->{'encoding'},
40 'p|plan' => \$opts->{'plan'},
41 'v|verbose' => \$opts->{'verbose'},
42 'w|watch' => \$opts->{'watch'},
43 5 'h|help' => \$opts->{'help'},
44 );
45  
46 5 ▶ if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"help"}) 2 3 5
47  
48 3 $opts->{'browser'} = $params{'browser'};
49 3 TestRail::Utils::interrogateUser( $opts, qw{apiurl user password project} );
50  
51 3 my $tr = TestRail::Utils::getHandle($opts);
52 3 my $project = $tr->getProjectByName( $opts->{'project'} );
53 3 ▶ return ( "No such project '$opts->{project}'", 2 ) unless $project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 3 3
54  
55 3 my $subject = $ARGV[0];
56 3 my ( $runs, $plan );
57  
58 3 ▶ if ( $opts->{'plan'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'plan'}) { } 2 1 3
59 2 $plan = $tr->getPlanByName( $project->{'id'}, $subject );
60 2 ▶ $runs = $tr->getChildRuns($plan) if $plan;
Branch: 1 branch
BranchTrueFalseTotal
if $plan 2 0 2
61 }
62 else {
63 1 my $run = $tr->getRunByName( $project->{'id'}, $subject );
64 1 ▶ push( @$runs, $run ) if $run;
Branch: 1 branch
BranchTrueFalseTotal
if $run 1 0 1
65 }
66  
67 3 ▶ return ( "No runs found matching your criterion.\n", 1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $runs eq "ARRAY" and @$runs 0 3 3
Condition33%1/3
ref $runs eq "ARRAY" and @$runs
!ll&&!rl&&r
003
MC/DC0%0/2
ref $runs eq "ARRAY" and @$runs
ref $runs eq "ARRAY" @$runs
Truth table33%1/3
A and B
A= ref $runs eq "ARRAY"B= @$runs
ABresult
0X0
100
111
68 unless ref $runs eq 'ARRAY' && @$runs;
69  
70 3 my @tests;
71 3 foreach my $run (@$runs) {
72 3 my $tests = $tr->getTests( $run->{id} );
73 3 @$tests = map { $_->{config} = $run->{config}; $_ } @$tests;
74 3 ▶ push( @tests, @{$tests} ) if ref $tests eq 'ARRAY' && @$tests;
Branch: 1 branch
BranchTrueFalseTotal
if ref $tests eq "ARRAY" and @$tests 3 0 3
Condition33%1/3
ref $tests eq "ARRAY" and @$tests
!ll&&!rl&&r
003
MC/DC0%0/2
ref $tests eq "ARRAY" and @$tests
ref $tests eq "ARRAY" @$tests
Truth table33%1/3
A and B
A= ref $tests eq "ARRAY"B= @$tests
ABresult
0X0
100
111
75 }
76  
77 #TODO get status ids for untested/retest, check em
78 3 my @retry_status_ids = $tr->statusNamesToIds(qw{untested retest});
79 3 my @bad_status_ids = $tr->statusNamesToIds(qw{failed todo_pass});
80  
81 3 my $rc = 0;
82 3 ▶ while ( my $test = shift @tests ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $test = shift @tests) 3 3 6
83 3 my $results = $tr->getTestResults( $test->{id}, 1 );
84 3 ▶ if ( !( ref $results eq 'ARRAY' ) || !@$results ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $results eq "ARRAY" and @$results) 0 3 3
Condition33%1/3
ref $results eq "ARRAY" and @$results
!ll&&!rl&&r
003
MC/DC0%0/2
ref $results eq "ARRAY" and @$results
ref $results eq "ARRAY" @$results
Truth table33%1/3
A and B
A= ref $results eq "ARRAY"B= @$results
ABresult
0X0
100
111
85 0 ▶ push( @tests, $test ) if $opts->{watch};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"watch"} 0 0 0
86 0 next;
87 }
88 3 my $result = $results->[0];
89 3 ▶ next unless ref $result eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result eq "HASH" 0 3 3
90 3 ▶ if ( !grep { $result->{status_id} eq $_ } @retry_status_ids ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$result->{"status_id"} eq $_;} @retry_status_ids) 3 0 3
91 3 ▶ print $result->{comment} . "\n" if $opts->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"verbose"} 0 3 3
92 3 my $line = $test->{title};
93 3 ▶ $line .= " ($test->{config})" if $test->{config};
Branch: 1 branch
BranchTrueFalseTotal
if $test->{"config"} 0 3 3
94 3 $line .= " ...";
95 3 ▶ if ( grep { $result->{status_id} eq $_ } @bad_status_ids ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$result->{"status_id"} eq $_;} @bad_status_ids) 0 3 3
96 0 $rc = 3;
97 0 $line .= ' not';
98 }
99 3 print "# $opts->{apiurl}/index.php?/tests/view/$test->{id}\n";
100 3 print "$line ok\n";
101 3 next;
102 }
103 0 ▶ push( @tests, $test ) if $opts->{watch};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"watch"} 0 0 0
104  
105 # If we have to wait, back off a little to not slam the server
106 0 sleep 1;
107 }
108  
109 3 return ( "Done", $rc );
110 }
111  
112 1;
113  
114 =pod
115  
116 =encoding UTF-8
117  
118 =head1 NAME
119  
120 TestRail::Bin::Replay - List runs in a TestRail project matching the provided filters
121  
122 =head1 VERSION
123  
124 version 0.052
125  
126 =head1 SYNOPSIS
127  
128 testrail-replay [OPTIONS] NAME
129  
130 require `which testrail-runs`;
131 TestRail::Bin::Replay::run('args' => \@args);
132  
133 =head1 DESCRIPTION
134  
135 testrail-replay - Re-play the results of a test run or plan as though executed by prove.
136 Optionally wait for results to come in.
137  
138 Can be used as the modulino TestRail::Bin::Replay.
139 Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
140  
141 =head1 PARAMETERS:
142  
143 =head2 MANDATORY PARAMETERS
144  
145 =over 4
146  
147 --apiurl : full URL to get to TestRail index document
148  
149 --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
150  
151 --user : Your TestRail User Name.
152  
153 -j --project : desired project name.
154  
155 =back
156  
157 All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
158  
159 =head2 OPTIONAL PARAMETERS
160  
161 =over 4
162  
163 -p --plan : Instead of a run to look for, look for a plan with the provided NAME.
164  
165 -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
166  
167 -v --verbose : Print full test output rather than summaries with links to the testrail result.
168  
169 -w --watch : Watch tests until all report results other than untested or re-test.
170  
171 =back
172  
173 =head1 CONFIGURATION FILE
174  
175 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.
176 Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
177 All options specified thereby are overridden by passing the command-line switches above.
178  
179 =head1 MISCELLANEOUS OPTIONS:
180  
181 =over 4
182  
183 --help : show this output
184  
185 =back
186  
187 =head1 SPECIAL THANKS
188  
189 Thanks to cPanel Inc, for graciously funding the creation of this distribution.
190  
191 =head1 AUTHOR
192  
193 George S. Baugh <teodesian@cpan.org>
194  
195 =head1 SOURCE
196  
197 The development version is on github at L<https://github.com/teodesian/TestRail-Perl>
198 and may be cloned from L<git://github.com/teodesian/TestRail-Perl.git>
199  
200 =head1 COPYRIGHT AND LICENSE
201  
202 This software is copyright (c) 2022 by George S. Baugh.
203  
204 This is free software; you can redistribute it and/or modify it under
205 the same terms as the Perl 5 programming language system itself.
206  
207 =cut
208  
209 __END__
« blib/lib/Test/Rail/Parser.pm ↑ Summary bin/testrail-report »