Explorar o código

Fix #16 - Use File::HomeDir rather than $ENV{HOME}

George S. Baugh %!s(int64=11) %!d(string=hai) anos
pai
achega
420644228b
Modificáronse 4 ficheiros con 27 adicións e 10 borrados
  1. 3 0
      Changes
  2. 13 6
      bin/testrail-report
  3. 1 1
      dist.ini
  4. 10 3
      lib/App/Prove/Plugin/TestRail.pm

+ 3 - 0
Changes

@@ -1,5 +1,8 @@
 Revision history for Perl module TestRail::API
 
+0.018 2015-01-29 TEODESIAN
+    - Better finding of $HOME in testrail-report and the prove plugin for cross-platform usage
+
 0.017 2015-01-29 TEODESIAN
     - Explicitly import List::Util in TestRail::API, this causes issues on some perls
     - Require minimum version of Term::ANSIColor

+ 13 - 6
bin/testrail-report

@@ -44,7 +44,7 @@ This should provide sufficient uniqueness to get to any run using names.
 
 =head3 CONFIG OVERRIDES
 
-In your $HOME, put a file called .testrailrc with key=value
+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.  Valid Keys are: apiurl,user,password
 
 =head3 CONFIG OPTIONS
@@ -97,6 +97,7 @@ use Getopt::Long;
 use Term::ANSIColor 2.01 qw(colorstrip);
 use Test::Rail::Parser;
 use IO::Interactive::Tiny ();
+use File::HomeDir qw{my_home};
 
 print "testrail-report\n----------------------\n";
 
@@ -145,8 +146,10 @@ PARAMETERS:
   uniqueness to get to any run using words.
 
   [CONFIG OVERRIDES]
-  In your \$HOME, put a file called .testrailrc with key=value
-  syntax separated by newlines.  Valid Keys are: apiurl,user,password
+  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.
+  Valid Keys are: apiurl,user,password
 
   [CONFIG OPTIONS] - These override the config, if present.
                      If neither are used, you will be prompted.
@@ -198,10 +201,11 @@ sub userInput {
 }
 
 sub parseConfig {
+    my $homedir = shift;
     my $results = {};
     my $arr =[];
 
-    open(my $fh, '<', $ENV{"HOME"} . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
+    open(my $fh, '<', $homedir . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
     while (<$fh>) {
         chomp;
         @$arr = split(/=/,$_);
@@ -238,8 +242,9 @@ GetOptions(
 if ($help) { help(); }
 
 #Parse config file if we are missing api url/key or user
-if (-e $ENV{"HOME"} . '/.testrailrc' && (!$apiurl || !$password || !$user) ) {
-    ($apiurl,$password,$user) = parseConfig();
+my $homedir = my_home() || '.';
+if (-e $homedir . '/.testrailrc' && (!$apiurl || !$password || !$user) ) {
+    ($apiurl,$password,$user) = parseConfig($homedir);
 }
 
 #XXX not even close to optimized, don't slurp in the future
@@ -371,6 +376,8 @@ L<App::Prove::Plugin::TestRail>
 
 L<TAP::Parser>
 
+L<File::HomeDir> for the finding of .testrailrc
+
 =head1 SPECIAL THANKS
 
 Thanks to cPanel Inc, for graciously funding the creation of this module.

+ 1 - 1
dist.ini

@@ -1,6 +1,6 @@
 name = TestRail-API
 main_module = lib/TestRail/API.pm
-version = 0.017
+version = 0.018
 author = George S. Baugh <teodesian@cpan.org>
 license = Perl_5
 copyright_holder = George S. Baugh

+ 10 - 3
lib/App/Prove/Plugin/TestRail.pm

@@ -7,6 +7,8 @@ use strict;
 use warnings;
 use utf8;
 
+use File::HomeDir qw{my_home};
+
 =head1 SYNOPSIS
 
 `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`
@@ -20,7 +22,7 @@ Prove plugin to upload test results to TestRail installations.
 Accepts input in the standard Prove plugin fashion (-Ppluginname='key=value,key=value,key=value...'), but will also parse a config file.
 When fed in prove plugin style, key=value input is expected.
 
-If ~/.testrailrc exists, it will be parsed for any of these values in a newline separated key=value list.  Example:
+If \$HOME/.testrailrc exists, it will be parsed for any of these values in a newline separated key=value list.  Example:
 
     apiurl=http://some.testrail.install
     user=someGuy
@@ -34,7 +36,8 @@ If ~/.testrailrc exists, it will be parsed for any of these values in a newline
     step_results=sr_sys_name
 
 Note that passing configurations as filters for runs inside of plans are separated by colons.
-Values passed in via query string will override values in ~/.testrailrc.
+Values passed in via query string will override values in \$HOME/.testrailrc.
+If your system has no concept of user homes, it will look in the current directory for .testrailrc.
 
 =head1 OVERRIDDEN METHODS
 
@@ -86,7 +89,9 @@ sub _parseConfig {
     my $results = {};
     my $arr =[];
 
-    open(my $fh, '<', $ENV{"HOME"} . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
+    my $homedir = my_home() || '.';
+
+    open(my $fh, '<', $homedir . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
     while (<$fh>) {
         chomp;
         @$arr = split(/=/,$_);
@@ -112,6 +117,8 @@ L<Test::Rail::Parser>
 
 L<App::Prove>
 
+L<File::HomeDir> for the finding of .testrailrc
+
 =head1 SPECIAL THANKS
 
 Thanks to cPanel Inc, for graciously funding the creation of this module.