bin/testrail-cases

filter: Statementstmt 98.3% 61 / 62 Branchbran 75.0% 12 / 16 Conditioncond 75.0% 6 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 90.0% 90 / 100 CC 11 SCAR 19.3
CC
11
Cov
92%
run
11.2
BEGIN
1.0
BEGIN
1.0
CRAP 6.9
« blib/lib/TestRail/API.pm ↑ Summary blib/lib/Test/Rail/Harness.pm »
1 #!/usr/bin/perl
2 # ABSTRACT: get information about cases inside various testsuites/sections.
3 # PODNAME: TestRail::Bin::Cases
4  
5 package TestRail::Bin::Cases;
6 1 $TestRail::Bin::Cases::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 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use TestRail::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use TestRail::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use TestRail::Utils::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Getopt::Long qw{GetOptionsFromArray};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use File::HomeDir qw{my_home};
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶if ( !caller() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller()) 1 0 1
19 1 my ( $out, $code ) = run( 'args' => \@ARGV );
20 1 print $out;
21 1 exit $code;
22 }
23  
24 5 ▶sub run {
Subroutine run: called CC=11 SCAR=24.1
25 5 my %params = @_;
26 5 my $opts = {};
27  
28 #Parse config file if we are missing api url/key or user
29 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
30 5 ▶ if ( -e $homedir . '/.testrailrc' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $homedir . '/.testrailrc') 0 5 5
31 0 $opts = TestRail::Utils::parseConfig($homedir);
32 }
33  
34 GetOptionsFromArray(
35 $params{'args'},
36 'apiurl=s' => \$opts->{'apiurl'},
37 'password=s' => \$opts->{'password'},
38 'user=s' => \$opts->{'user'},
39 'j|project=s' => \$opts->{'project'},
40 't|testsuite=s' => \$opts->{'testsuite'},
41 'd|directory=s' => \$opts->{'directory'},
42 'm|missing' => \$opts->{'missing'},
43 'o|orphans' => \$opts->{'orphans'},
44 'n|no-recurse' => \$opts->{'no-recurse'},
45 'e|encoding=s' => \$opts->{'encoding'},
46 'section=s' => \$opts->{'section'},
47 'type=s@' => \$opts->{'types'},
48 'extension=s' => \$opts->{'extension'},
49 'h|help' => \$opts->{'help'},
50 5 'test' => \$opts->{'test'},
51 );
52  
53 5 ▶ if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"help"}) 2 3 5
54  
55 3 $opts->{'browser'} = $params{'browser'};
56  
57 #Mutual exclusivity
58 3 $opts->{'no-missing'} = !$opts->{'missing'};
59 3 ▶ $opts->{'update'} = !( $opts->{'orphans'} || $opts->{'missing'} );
Condition100%3/3
$opts->{'orphans'} || $opts->{'missing'}
l!l&&r!l&&!r
111
MC/DC100%2/2
$opts->{'orphans'} || $opts->{'missing'}
$opts->{'orphans'} $opts->{'missing'}
Truth table100%3/3
A || B
A= $opts->{'orphans'}B= $opts->{'missing'}
ABresult
1X1
011
000
60 die("orphans and mising options are mutually exclusive.")
61 3 ▶ if $opts->{'orphans'} && $opts->{'missing'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"orphans"} and $opts->{"missing"} 0 3 3
Condition66%2/3
$opts->{"orphans"} and $opts->{"missing"}
!ll&&!rl&&r
210
MC/DC0%0/2
$opts->{"orphans"} and $opts->{"missing"}
$opts->{"orphans"} $opts->{"missing"}
Truth table66%2/3
A and B
A= $opts->{"orphans"}B= $opts->{"missing"}
ABresult
0X0
100
111
62 3 delete $opts->{'missing'};
63  
64 3 TestRail::Utils::interrogateUser( $opts,
65 qw{apiurl user password project testsuite directory} );
66  
67 3 my $tr = TestRail::Utils::getHandle($opts);
68  
69 3 my $cases = TestRail::Utils::Find::getCases( $opts, $tr );
70 3 ▶ die "No cases in TestRail!\n" unless $cases;
Branch: 1 branch
BranchTrueFalseTotal
unless $cases 0 3 3
71  
72 3 my $tests = TestRail::Utils::Find::findCases( $opts, @$cases );
73  
74 3 my ( @update, @add, @orphan );
75 1 @update = map { $_->{'title'} } @{ $tests->{'update'} }
76 3 ▶ if ref $tests->{'update'} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tests->{"update"} eq "ARRAY" 1 2 3
77 1 @add = map { $_->{'title'} } @{ $tests->{'orphans'} }
78 3 ▶ if ref $tests->{'orphans'} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tests->{"orphans"} eq "ARRAY" 1 2 3
79 3 ▶ @orphan = @{ $tests->{'missing'} } if ref $tests->{'missing'} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tests->{"missing"} eq "ARRAY" 1 2 3
80  
81 3 my $out = '';
82 3 $out .= join( "\n", @update );
83 3 $out .= join( "\n", @add );
84 3 $out .= join( "\n", @orphan );
85 3 $out .= "\n";
86  
87 3 return ( $out, 0 );
88 }
89  
90 1;
91  
92 =pod
93  
94 =encoding UTF-8
95  
96 =head1 NAME
97  
98 TestRail::Bin::Cases - get information about cases inside various testsuites/sections.
99  
100 =head1 VERSION
101  
102 version 0.052
103  
104 =head1 SYNOPSIS
105  
106 testrail-cases [OPTIONS]
107  
108 require `which testrail-cases`;
109 TestRail::Bin::Cases::run('args' => @args);
110  
111 =head1 DESCRIPTION
112  
113 testrail-cases - get information about cases inside various testsuites/sections.
114  
115 By default will tell you which cases are in both the testsuite and directory passed.
116  
117 Can be used as the modulino TestRail::Bin::Cases.
118 Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
119  
120 =head1 PARAMETERS:
121  
122 =head2 MANDATORY PARAMETERS
123  
124 =over 4
125  
126 --apiurl : full URL to get to TestRail index document
127  
128 --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
129  
130 --user : Your TestRail User Name.
131  
132 -j --project : desired project name.
133  
134 -t --testsuite : desired testsuite name to search for cases within. May be passed multiple times.
135  
136 -d --directory : directory to search for tests to correlate with TestRail cases. May be passed multiple times.
137  
138 =back
139  
140 All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
141  
142 =head2 SEMI-OPTIONAL PARAMETERS
143  
144 =over 4
145  
146 -m --missing : Only show cases which are in the directory passed, but not TestRail. Mutually exclusive with orphans.
147  
148 -o --orphans : Only show cases which are in TestRail, but not the directory passed. Mutually exclusive with missing.
149  
150 -n --no-recurse : do not recurse subdirectories when considering what tests need adding/updating/pruning.
151  
152 -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
153  
154 =back
155  
156 =head2 OPTIONAL PARAMETERS
157  
158 =over 4
159  
160 --type : Filter cases to make syncing judgements against type(s). May be passed multiple times.
161  
162 --section : Filter cases to make syncing judgements against a specific section.
163  
164 --extension : only list files ending in the provided string (e.g. .pl, .pm, .t, .test)
165  
166 =back
167  
168 =head1 CONFIGURATION FILE
169  
170 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.
171 Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
172 All options specified thereby are overridden by passing the command-line switches above.
173  
174 =head1 MISCELLANEOUS OPTIONS:
175  
176 =over 4
177  
178 --help : show this output
179  
180 --test : print which tests would be added/updated/removed, but don't actually do anything
181  
182 =back
183  
184 =head1 SPECIAL THANKS
185  
186 Thanks to cPanel Inc, for graciously funding the creation of this distribution.
187  
188 =head1 AUTHOR
189  
190 George S. Baugh <teodesian@cpan.org>
191  
192 =head1 SOURCE
193  
194 The development version is on github at L<https://github.com/teodesian/TestRail-Perl>
195 and may be cloned from L<git://github.com/teodesian/TestRail-Perl.git>
196  
197 =head1 COPYRIGHT AND LICENSE
198  
199 This software is copyright (c) 2022 by George S. Baugh.
200  
201 This is free software; you can redistribute it and/or modify it under
202 the same terms as the Perl 5 programming language system itself.
203  
204 =cut
205  
206 __END__
« blib/lib/TestRail/API.pm ↑ Summary blib/lib/Test/Rail/Harness.pm »