testrail-tests 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. --orphans : attempt to find tests in TestRail which aren't in the provided directory.
  24. The three above options are mutually exclusive.
  25. -n --no-recurse : if match (or no-match) passed, do not recurse subdirectories.
  26. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  27. =back
  28. =head2 OPTIONAL PARAMETERS
  29. =over 4
  30. -c --config : configuration name to filter plans in run. Can be passed multiple times.
  31. -s --status : only list tests marked as [status] in testrail. Can be passed multiple times.
  32. -a --assignedto : only list tests assigned to user. Can be passed multiple times.
  33. --extension : only list files ending in the provided string (e.g. .pl, .pm, .t, .test)
  34. =back
  35. =head1 CONFIGURATION FILE
  36. 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.
  37. Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
  38. All options specified thereby are overridden by passing the command-line switches above.
  39. =head1 MISCELLANEOUS OPTIONS:
  40. =over 4
  41. --help : show this output
  42. =back
  43. =cut
  44. use strict;
  45. use warnings;
  46. use utf8;
  47. use TestRail::API;
  48. use TestRail::Utils;
  49. use TestRail::Utils::Find;
  50. use Getopt::Long;
  51. use File::HomeDir qw{my_home};
  52. my $opts ={};
  53. #Parse config file if we are missing api url/key or user
  54. my $homedir = my_home() || '.';
  55. if (-e $homedir . '/.testrailrc') {
  56. $opts = TestRail::Utils::parseConfig($homedir);
  57. }
  58. GetOptions(
  59. 'apiurl=s' => \$opts->{'apiurl'},
  60. 'password=s' => \$opts->{'password'},
  61. 'user=s' => \$opts->{'user'},
  62. 'j|project=s' => \$opts->{'project'},
  63. 'p|plan=s' => \$opts->{'plan'},
  64. 'r|run=s' => \$opts->{'run'},
  65. 'c|config=s@' => \$opts->{'configs'},
  66. 's|status=s@' => \$opts->{'statuses'},
  67. 'a|assignedto=s@' => \$opts->{'users'},
  68. 'm|match=s' => \$opts->{'match'},
  69. 'no-match=s' => \$opts->{'no-match'},
  70. 'orphans=s' => \$opts->{'orphans'},
  71. 'n|no-recurse' => \$opts->{'no-recurse'},
  72. 'e|encoding=s' => \$opts->{'encoding'},
  73. 'extension=s' => \$opts->{'extension'},
  74. 'h|help' => \$opts->{'help'},
  75. 'mock' => \$opts->{'mock'}
  76. );
  77. if ($opts->{help}) { TestRail::Utils::help(); }
  78. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});
  79. my $tr = TestRail::Utils::getHandle($opts);
  80. my ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  81. die "No cases in TestRail!\n" unless $cases;
  82. $opts->{'names-only'} = 1;
  83. my @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  84. print join("\n",@tests)."\n" if scalar(@tests);
  85. exit 0;
  86. __END__
  87. L<TestRail::API>
  88. L<File::HomeDir> for the finding of .testrailrc
  89. =head1 SPECIAL THANKS
  90. Thanks to cPanel Inc, for graciously funding the creation of this distribution.