| 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 | 1 | $TestRail::Bin::Tests::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
| |||||||||||||
| 19 | 1 | my ( $out, $code ) = run( 'args' => \@ARGV ); | |||||||||||
| 20 | 1 | print $out; | |||||||||||
| 21 | 1 | exit $code; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | 15 | ▶ | sub run { | ||||||||||
|
Subroutine
run: called CC=6 SCAR=18.1
| |||||||||||||
| 25 | 15 | my %params = @_; | |||||||||||
| 26 | 15 | my $opts = {}; | |||||||||||
| 27 | |||||||||||||
| 28 | #Parse config file if we are missing api url/key or user | ||||||||||||
| 29 | 15 | ▶ | my $homedir = my_home() || '.'; | ||||||||||
|
Condition50%1/2
my_home() || '.'
MC/DC0%0/1
my_home() || '.'
my_home()
Truth table50%1/2
A
A= my_home()
| |||||||||||||
| 30 | 15 | ▶ | if ( -e $homedir . '/.testrailrc' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | '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 | 15 | 'h|help' => \$opts->{'help'}, | |||||||||||
| 52 | ); | ||||||||||||
| 53 | |||||||||||||
| 54 | 15 | ▶ | if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 13 | $opts->{'browser'} = $params{'browser'}; | |||||||||||
| 57 | |||||||||||||
| 58 | 13 | TestRail::Utils::interrogateUser( $opts, | |||||||||||
| 59 | qw{apiurl user password project run} ); | ||||||||||||
| 60 | |||||||||||||
| 61 | 13 | my $tr = TestRail::Utils::getHandle($opts); | |||||||||||
| 62 | |||||||||||||
| 63 | 13 | my ($cases) = TestRail::Utils::Find::getTests( $opts, $tr ); | |||||||||||
| 64 | 12 | ▶ | die "No cases in TestRail!\n" unless $cases; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | |||||||||||||
| 66 | 12 | $opts->{'names-only'} = 1; | |||||||||||
| 67 | 12 | my @tests = TestRail::Utils::Find::findTests( $opts, @$cases ); | |||||||||||
| 68 | |||||||||||||
| 69 | 12 | ▶ | return ( join( "\n", @tests ) . "\n", 0 ) if scalar(@tests); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 2 | 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<Encode::Supported> 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<App::Prove::Plugin::TestRail>. | ||||||||||||
| 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 <teodesian@cpan.org> | ||||||||||||
| 176 | |||||||||||||
| 177 | =head1 SOURCE | ||||||||||||
| 178 | |||||||||||||
| 179 | The development version is on github at L<https://github.com/teodesian/TestRail-Perl> | ||||||||||||
| 180 | and may be cloned from L<git://github.com/teodesian/TestRail-Perl.git> | ||||||||||||
| 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__ | ||||||||||||