File Coverage

bin/testrail-tests
Criterion Covered Total %
statement 40 41 97.5
branch 6 8 75.0
condition 1 2 50.0
subroutine 9 9 100.0
pod n/a
total 56 60 93.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2             # ABSTRACT: List tests in a TestRail run matching the provided filters
3             # PODNAME: TestRail::Bin::Tests
4              
5             package TestRail::Bin::Tests;
6             $TestRail::Bin::Tests::VERSION = '0.051';
7 1     1   562 use strict;
  1         3  
  1         31  
8 1     1   5 use warnings;
  1         1  
  1         24  
9 1     1   587 use utf8;
  1         15  
  1         5  
10              
11 1     1   764 use TestRail::API;
  1         4  
  1         60  
12 1     1   561 use TestRail::Utils;
  1         4  
  1         43  
13 1     1   612 use TestRail::Utils::Find;
  1         4  
  1         53  
14              
15 1     1   930 use Getopt::Long qw{GetOptionsFromArray};
  1         10804  
  1         4  
16 1     1   692 use File::HomeDir qw{my_home};
  1         5663  
  1         442  
17              
18             if ( !caller() ) {
19             my ( $out, $code ) = run( 'args' => \@ARGV );
20             print $out;
21             exit $code;
22             }
23              
24             sub run {
25 14     14   22678 my %params = @_;
26 14         56 my $opts = {};
27              
28             #Parse config file if we are missing api url/key or user
29 14   50     56 my $homedir = my_home() || '.';
30 14 50       765 if ( -e $homedir . '/.testrailrc' ) {
31 0         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             'p|plan=s' => \$opts->{'plan'},
41             'r|run=s' => \$opts->{'run'},
42             'c|config=s@' => \$opts->{'configs'},
43             's|status=s@' => \$opts->{'statuses'},
44             'a|assignedto=s@' => \$opts->{'users'},
45             'm|match=s' => \$opts->{'match'},
46             'no-match=s' => \$opts->{'no-match'},
47             'orphans=s' => \$opts->{'orphans'},
48             'n|no-recurse' => \$opts->{'no-recurse'},
49             'e|encoding=s' => \$opts->{'encoding'},
50             'extension=s' => \$opts->{'extension'},
51 14         274 'h|help' => \$opts->{'help'},
52             );
53              
54 14 100       27838 if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); }
  1         6  
55              
56 13         35 $opts->{'browser'} = $params{'browser'};
57              
58 13         67 TestRail::Utils::interrogateUser( $opts,
59             qw{apiurl user password project run} );
60              
61 13         40 my $tr = TestRail::Utils::getHandle($opts);
62              
63 13         53 my ($cases) = TestRail::Utils::Find::getTests( $opts, $tr );
64 12 50       92 die "No cases in TestRail!\n" unless $cases;
65              
66 12         60 $opts->{'names-only'} = 1;
67 12         47 my @tests = TestRail::Utils::Find::findTests( $opts, @$cases );
68              
69 12 100       378 return ( join( "\n", @tests ) . "\n", 0 ) if scalar(@tests);
70 2         45 return ( '', 255 );
71             }
72              
73             1;
74              
75             =pod
76              
77             =encoding UTF-8
78              
79             =head1 NAME
80              
81             TestRail::Bin::Tests - List tests in a TestRail run matching the provided filters
82              
83             =head1 VERSION
84              
85             version 0.051
86              
87             =head1 SYNOPSIS
88              
89             testrail-tests [OPTIONS] | xargs prove -PTestrail=...
90              
91             require `which testrail-tests`;
92             TestRail::Bin::Test::run('args' => \@args);
93              
94             =head1 DESCRIPTION
95              
96             testrail-tests - list tests in a run matching the provided filters.
97              
98             Can be used as the modulino TestRail::Bin::Tests.
99             Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
100              
101             =head1 PARAMETERS:
102              
103             =head2 MANDATORY PARAMETERS
104              
105             =over 4
106              
107             --apiurl : full URL to get to TestRail index document
108              
109             --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
110              
111             --user : Your TestRail User Name.
112              
113             -j --project : desired project name.
114              
115             -r --run : desired run name.
116              
117             =back
118              
119             All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
120              
121             =head2 SEMI-OPTIONAL PARAMETERS
122              
123             =over 4
124              
125             -p --plan : desired plan name. Required if the run passed is a child of a plan.
126              
127             -m --match : attempt to find filenames matching the test names in the provided directory.
128              
129             --no-match : attempt to find filenames that do not match test names in the provided directory.
130              
131             --orphans : attempt to find tests in TestRail which aren't in the provided directory.
132              
133             The three above options are mutually exclusive.
134              
135             -n --no-recurse : if match (or no-match) passed, do not recurse subdirectories.
136              
137             -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L for supported encodings.
138              
139             =back
140              
141             =head2 OPTIONAL PARAMETERS
142              
143             =over 4
144              
145             -c --config : configuration name to filter plans in run. Can be passed multiple times.
146              
147             -s --status : only list tests marked as [status] in testrail. Can be passed multiple times.
148              
149             -a --assignedto : only list tests assigned to user. Can be passed multiple times.
150              
151             --extension : only list files ending in the provided string (e.g. .pl, .pm, .t, .test)
152              
153             =back
154              
155             =head1 CONFIGURATION FILE
156              
157             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.
158             Valid Keys are the same as documented by L.
159             All options specified thereby are overridden by passing the command-line switches above.
160              
161             =head1 MISCELLANEOUS OPTIONS:
162              
163             =over 4
164              
165             --help : show this output
166              
167             =back
168              
169             =head1 SPECIAL THANKS
170              
171             Thanks to cPanel Inc, for graciously funding the creation of this distribution.
172              
173             =head1 AUTHOR
174              
175             George S. Baugh
176              
177             =head1 SOURCE
178              
179             The development version is on github at L
180             and may be cloned from L
181              
182             =head1 COPYRIGHT AND LICENSE
183              
184             This software is copyright (c) 2021 by George S. Baugh.
185              
186             This is free software; you can redistribute it and/or modify it under
187             the same terms as the Perl 5 programming language system itself.
188              
189             =cut
190              
191             __END__