File Coverage

bin/testrail-bulk-mark-results
Criterion Covered Total %
statement 41 43 95.3
branch 5 8 62.5
condition 1 2 50.0
subroutine 9 9 100.0
pod n/a
total 56 62 90.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2             # ABSTRACT: Bulk mark entire runs/plans (or groups of tests therein) as the provided status.
3             # PODNAME: TestRail::Bin::BulkMarkResults
4              
5             package TestRail::Bin::BulkMarkResults;
6             $TestRail::Bin::BulkMarkResults::VERSION = '0.051';
7 1     1   568 use strict;
  1         3  
  1         32  
8 1     1   4 use warnings;
  1         2  
  1         24  
9 1     1   649 use utf8;
  1         15  
  1         8  
10              
11 1     1   829 use TestRail::API;
  1         4  
  1         63  
12 1     1   514 use TestRail::Utils;
  1         5  
  1         41  
13 1     1   522 use TestRail::Utils::Results;
  1         4  
  1         41  
14              
15 1     1   785 use Getopt::Long qw{GetOptionsFromArray};
  1         10947  
  1         4  
16             Getopt::Long::Configure('pass_through');
17              
18 1     1   697 use File::HomeDir qw{my_home};
  1         5755  
  1         518  
19              
20             if ( !caller() ) {
21             my ( $out, $code ) = run( 'args' => \@ARGV );
22             print $out;
23             exit $code;
24             }
25              
26             sub run {
27 2     2   3848 my %params = @_;
28 2         5 my $opts = {};
29              
30             # Parse config file
31 2   50     10 my $homedir = my_home() || '.';
32 2 50       175 if ( -e $homedir . '/.testrailrc' ) {
33 0         0 $opts = TestRail::Utils::parseConfig($homedir);
34             }
35              
36             # Override configuration with switches
37             GetOptionsFromArray(
38             $params{'args'},
39             'apiurl=s' => \$opts->{'apiurl'},
40             'password=s' => \$opts->{'password'},
41             'user=s' => \$opts->{'user'},
42             'status=s@' => \$opts->{'statuses'},
43             'j|project=s' => \$opts->{'project'},
44             'p|plan=s' => \$opts->{'plan'},
45             'r|run=s' => \$opts->{'run'},
46             'c|config=s@' => \$opts->{'configs'},
47             'a|assignedto=s@' => \$opts->{'users'},
48             'e|encoding=s' => \$opts->{'encoding'},
49 2         35 'h|help' => \$opts->{'help'},
50             );
51              
52 2 100       2458 if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); }
  1         6  
53              
54 1         3 $opts->{'browser'} = $params{'browser'};
55              
56 1         2 my $status = $params{'args'}->[0];
57 1         3 my $reason = $params{'args'}->[1];
58              
59 1 50       3 die("No status to set provided.") unless $status;
60 1         6 TestRail::Utils::interrogateUser( $opts,
61             qw{apiurl user password project run} );
62              
63 1         4 my $tr = TestRail::Utils::getHandle($opts);
64              
65 1         2 $opts->{'set_status_to'} = $status;
66 1         4 $opts->{'reason'} = $reason;
67 1         3 my $results = TestRail::Utils::Results::bulkMarkResults( $opts, $tr );
68              
69             return (
70 1 50       93 "Successfully set the status of "
71             . scalar(@$results)
72             . " cases to $status.\n",
73             0
74             ) if $results;
75 0           return ( "Could find no cases to set results for.\n", 255 );
76             }
77              
78             1;
79              
80             =pod
81              
82             =encoding UTF-8
83              
84             =head1 NAME
85              
86             TestRail::Bin::BulkMarkResults - Bulk mark entire runs/plans (or groups of tests therein) as the provided status.
87              
88             =head1 VERSION
89              
90             version 0.051
91              
92             =head1 DESCRIPTION
93              
94             Sometimes it is useful to mark entire runs of tests when, for example, a prerequisite test in a sequence invalidates all further tests.
95             For example, if a binary produced for test fails to run at all, more detailed testing will be impossible;
96             it would save time to just mark everything as blocked.
97              
98             Can be used as the modulino TestRail::Bin::BulkMarkResults.
99             Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
100              
101             =head1 USAGE
102              
103             testrail-bulk-mark-results [OPTIONS] status [reason]
104              
105             require `which testrail-bulk-mark-results`;
106             TestRail::Bin::BulkMarkResults::run('args' => \@args);
107              
108             =head1 PARAMETERS:
109              
110             =head2 MANDATORY PARAMETERS
111              
112             =over 4
113              
114             --apiurl : full URL to get to TestRail index document
115              
116             --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
117              
118             --user : Your TestRail User Name.
119              
120             -j --project : desired project name.
121              
122             -r --run : desired run name.
123              
124             =back
125              
126             All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
127              
128             =head2 SEMI-OPTIONAL PARAMETERS
129              
130             =over 4
131              
132             -p --plan : desired plan name. Required if the run passed is a child of a plan.
133              
134             -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L for supported encodings.
135              
136             =back
137              
138             =head2 OPTIONAL PARAMETERS
139              
140             =over 4
141              
142             -c --config : configuration name to filter plans in run. Can be passed multiple times.
143              
144             -s --status : only mark tests already marked as [status] in testrail. Can be passed multiple times.
145              
146             -a --assignedto : only mark tests assigned to user. Can be passed multiple times.
147              
148             =back
149              
150             =head1 CONFIGURATION FILE
151              
152             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.
153             Valid Keys are the same as documented by L.
154             All options specified thereby are overridden by passing the command-line switches above.
155              
156             =head1 MISCELLANEOUS OPTIONS:
157              
158             =over 4
159              
160             --help : show this output
161              
162             =back
163              
164             =head1 SPECIAL THANKS
165              
166             Thanks to cPanel Inc, for graciously funding the creation of this distribution.
167              
168             =head1 AUTHOR
169              
170             George S. Baugh
171              
172             =head1 SOURCE
173              
174             The development version is on github at L
175             and may be cloned from L
176              
177             =head1 COPYRIGHT AND LICENSE
178              
179             This software is copyright (c) 2021 by George S. Baugh.
180              
181             This is free software; you can redistribute it and/or modify it under
182             the same terms as the Perl 5 programming language system itself.
183              
184             =cut
185              
186             __END__