| 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.052'; | 
| 7 | 1 |  |  | 1 |  | 501 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 8 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 9 | 1 |  |  | 1 |  | 473 | use utf8; | 
|  | 1 |  |  |  |  | 13 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 1 |  |  | 1 |  | 680 | use TestRail::API; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 51 |  | 
| 12 | 1 |  |  | 1 |  | 453 | use TestRail::Utils; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 13 | 1 |  |  | 1 |  | 519 | use TestRail::Utils::Find; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 43 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 |  |  | 1 |  | 612 | use Getopt::Long  qw{GetOptionsFromArray}; | 
|  | 1 |  |  |  |  | 8758 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 16 | 1 |  |  | 1 |  | 532 | use File::HomeDir qw{my_home}; | 
|  | 1 |  |  |  |  | 4624 |  | 
|  | 1 |  |  |  |  | 362 |  | 
| 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 |  | 20858 | my %params = @_; | 
| 26 | 14 |  |  |  |  | 29 | my $opts   = {}; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | #Parse config file if we are missing api url/key or user | 
| 29 | 14 |  | 50 |  |  | 41 | my $homedir = my_home() || '.'; | 
| 30 | 14 | 50 |  |  |  | 577 | 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 |  |  |  |  | 193 | 'h|help'          => \$opts->{'help'}, | 
| 52 |  |  |  |  |  |  | ); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 14 | 100 |  |  |  | 22453 | if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); } | 
|  | 1 |  |  |  |  | 6 |  | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 13 |  |  |  |  | 29 | $opts->{'browser'} = $params{'browser'}; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 13 |  |  |  |  | 42 | TestRail::Utils::interrogateUser( $opts, | 
| 59 |  |  |  |  |  |  | qw{apiurl user password project run} ); | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 13 |  |  |  |  | 29 | my $tr = TestRail::Utils::getHandle($opts); | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 13 |  |  |  |  | 35 | my ($cases) = TestRail::Utils::Find::getTests( $opts, $tr ); | 
| 64 | 12 | 50 |  |  |  | 65 | die "No cases in TestRail!\n" unless $cases; | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 12 |  |  |  |  | 23 | $opts->{'names-only'} = 1; | 
| 67 | 12 |  |  |  |  | 28 | my @tests = TestRail::Utils::Find::findTests( $opts, @$cases ); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 12 | 100 |  |  |  | 252 | return ( join( "\n", @tests ) . "\n", 0 ) if scalar(@tests); | 
| 70 | 2 |  |  |  |  | 33 | 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.052 | 
| 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) 2022 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__ |