testrail-tests 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env perl
  2. # ABSTRACT: List tests in a TestRail run matching the provided filters
  3. # PODNAME: testrail-tests
  4. =head1 SYNOPSIS
  5. testrail-tests [OPTIONS] | xargs prove -PTestrail=...
  6. =head1 DESCRIPTION
  7. testrail-tests - list tests in a run matching the provided filters.
  8. =head1 PARAMETERS:
  9. =head2 MANDATORY PARAMETERS
  10. =over 4
  11. --apiurl : full URL to get to TestRail index document
  12. --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
  13. --user : Your TestRail User Name.
  14. -j --project : desired project name.
  15. -r --run : desired run name.
  16. =back
  17. All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
  18. =head2 SEMI-OPTIONAL PARAMETERS
  19. =over 4
  20. -p --plan : desired plan name. Required if the run passed is a child of a plan.
  21. -m --match : attempt to find filenames matching the test names in the provided directory.
  22. --no-match : attempt to find filenames that do not match test names in the provided directory.
  23. -n --no-recurse : if match (or no-match) passed, do not recurse subdirectories.
  24. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  25. =back
  26. =head2 OPTIONAL PARAMETERS
  27. =over 4
  28. -c --config : configuration name to filter plans in run. Can be passed multiple times.
  29. -s --status : only list tests marked as [status] in testrail. Can be passed multiple times.
  30. -a --assignedto : only list tests assigned to user. Can be passed multiple times.
  31. --extension : only list files ending in the provided string (e.g. .pl, .pm, .t, .test)
  32. =back
  33. =head1 CONFIGURATION FILE
  34. 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.
  35. Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
  36. All options specified thereby are overridden by passing the command-line switches above.
  37. =head1 MISCELLANEOUS OPTIONS:
  38. =over 4
  39. --help : show this output
  40. =back
  41. =cut
  42. use strict;
  43. use warnings;
  44. use utf8;
  45. use TestRail::API;
  46. use TestRail::Utils;
  47. use TestRail::Utils::Find;
  48. use Getopt::Long;
  49. use File::HomeDir qw{my_home};
  50. my $opts ={};
  51. #Parse config file if we are missing api url/key or user
  52. my $homedir = my_home() || '.';
  53. if (-e $homedir . '/.testrailrc') {
  54. $opts = TestRail::Utils::parseConfig($homedir);
  55. }
  56. GetOptions(
  57. 'apiurl=s' => \$opts->{'apiurl'},
  58. 'password=s' => \$opts->{'password'},
  59. 'user=s' => \$opts->{'user'},
  60. 'j|project=s' => \$opts->{'project'},
  61. 'p|plan=s' => \$opts->{'plan'},
  62. 'r|run=s' => \$opts->{'run'},
  63. 'c|config=s@' => \$opts->{'configs'},
  64. 's|status=s@' => \$opts->{'statuses'},
  65. 'a|assignedto=s@' => \$opts->{'users'},
  66. 'm|match=s' => \$opts->{'match'},
  67. 'no-match=s' => \$opts->{'no-match'},
  68. 'n|no-recurse' => \$opts->{'no-recurse'},
  69. 'e|encoding=s' => \$opts->{'encoding'},
  70. 'extension=s' => \$opts->{'extension'},
  71. 'h|help' => \$opts->{'help'},
  72. 'mock' => \$opts->{'mock'}
  73. );
  74. if ($opts->{help}) { TestRail::Utils::help(); }
  75. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});
  76. my $tr = TestRail::Utils::getHandle($opts);
  77. my ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  78. die "No cases in TestRail!\n" unless $cases;
  79. $opts->{'names-only'} = 1;
  80. my @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  81. print join("\n",@tests)."\n" if scalar(@tests);
  82. exit 0;
  83. __END__
  84. L<TestRail::API>
  85. L<File::HomeDir> for the finding of .testrailrc
  86. =head1 SPECIAL THANKS
  87. Thanks to cPanel Inc, for graciously funding the creation of this distribution.