TestRail.pm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # ABSTRACT: Upload your TAP results to TestRail in realtime
  2. # PODNAME: App::Prove::Plugin::TestRail
  3. package App::Prove::Plugin::TestRail;
  4. use strict;
  5. use warnings;
  6. use utf8;
  7. use File::HomeDir qw{my_home};
  8. =head1 SYNOPSIS
  9. `prove -PTestRail='apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=TestRun,plan=TestPlan,configs=Config1:Config2:Config3,version=0.014' sometest.t`
  10. =cut
  11. =head1 DESCRIPTION
  12. Prove plugin to upload test results to TestRail installations.
  13. Accepts input in the standard Prove plugin fashion (-Ppluginname='key=value,key=value,key=value...'), but will also parse a config file.
  14. When fed in prove plugin style, key=value input is expected.
  15. If \$HOME/.testrailrc exists, it will be parsed for any of these values in a newline separated key=value list. Example:
  16. apiurl=http://some.testrail.install
  17. user=someGuy
  18. password=superS3cret
  19. project=TestProject
  20. run=TestRun
  21. plan=GosPlan
  22. configs=config1:config2:config3: ... :configN
  23. version=xx.xx.xx.xx
  24. case_per_ok=0
  25. step_results=sr_sys_name
  26. spawn=123
  27. sections=section1:section2:section3: ... :sectionN
  28. autoclose=0
  29. Note that passing configurations as filters for runs inside of plans are separated by colons.
  30. Values passed in via query string will override values in \$HOME/.testrailrc.
  31. If your system has no concept of user homes, it will look in the current directory for .testrailrc.
  32. See the documentation for the constructor of L<Test::Rail::Parser> as to why you might want to pass the aforementioned options.
  33. =head1 OVERRIDDEN METHODS
  34. =head2 load(parser)
  35. Shoves the arguments passed to the prove plugin into $ENV so that Test::Rail::Parser can get at them.
  36. Not the most elegant solution, but I see no other clear path to get those variables downrange to it's constructor.
  37. =cut
  38. sub load {
  39. my ($class, $p) = @_;
  40. my $app = $p->{app_prove};
  41. my $args = $p->{'args'};
  42. my $params = {};
  43. #Only attempt parse if we aren't mocking and the homedir exists
  44. my $homedir = my_home() || '.';
  45. $params = TestRail::Utils::parseConfig($homedir) if -e $homedir && !$ENV{'TESTRAIL_MOCKED'};
  46. my @kvp = ();
  47. my ($key,$value);
  48. foreach my $arg (@$args) {
  49. @kvp = split(/=/,$arg);
  50. if (scalar(@kvp) < 2) {
  51. print "Unrecognized Argument '$arg' to App::Prove::Plugin::Testrail, ignoring\n";
  52. next;
  53. }
  54. $key = shift @kvp;
  55. $value = join('',@kvp);
  56. $params->{$key} = $value;
  57. }
  58. $app->harness('Test::Rail::Harness');
  59. $app->merge(1);
  60. #XXX I can't figure out for the life of me any other way to pass this data. #YOLO
  61. $ENV{'TESTRAIL_APIURL'} = $params->{apiurl};
  62. $ENV{'TESTRAIL_USER'} = $params->{user};
  63. $ENV{'TESTRAIL_PASS'} = $params->{password};
  64. $ENV{'TESTRAIL_PROJ'} = $params->{project};
  65. $ENV{'TESTRAIL_RUN'} = $params->{run};
  66. $ENV{'TESTRAIL_PLAN'} = $params->{plan};
  67. $ENV{'TESTRAIL_CONFIGS'} = $params->{configs};
  68. $ENV{'TESTRAIL_VERSION'} = $params->{version};
  69. $ENV{'TESTRAIL_CASEOK'} = $params->{case_per_ok};
  70. $ENV{'TESTRAIL_STEPS'} = $params->{step_results};
  71. $ENV{'TESTRAIL_SPAWN'} = $params->{spawn};
  72. $ENV{'TESTRAIL_SECTIONS'} = $params->{sections};
  73. $ENV{'TESTRAIL_AUTOCLOSE'} = $params->{autoclose};
  74. return $class;
  75. }
  76. 1;
  77. __END__
  78. =head1 SEE ALSO
  79. L<TestRail::API>
  80. L<Test::Rail::Parser>
  81. L<App::Prove>
  82. L<File::HomeDir> for the finding of .testrailrc
  83. =head1 SPECIAL THANKS
  84. Thanks to cPanel Inc, for graciously funding the creation of this module.