瀏覽代碼

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

George S. Baugh 11 年之前
父節點
當前提交
420644228b
共有 4 個文件被更改,包括 27 次插入10 次删除
  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
 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
 0.017 2015-01-29 TEODESIAN
     - Explicitly import List::Util in TestRail::API, this causes issues on some perls
     - Explicitly import List::Util in TestRail::API, this causes issues on some perls
     - Require minimum version of Term::ANSIColor
     - 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
 =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
 syntax separated by newlines.  Valid Keys are: apiurl,user,password
 
 
 =head3 CONFIG OPTIONS
 =head3 CONFIG OPTIONS
@@ -97,6 +97,7 @@ use Getopt::Long;
 use Term::ANSIColor 2.01 qw(colorstrip);
 use Term::ANSIColor 2.01 qw(colorstrip);
 use Test::Rail::Parser;
 use Test::Rail::Parser;
 use IO::Interactive::Tiny ();
 use IO::Interactive::Tiny ();
+use File::HomeDir qw{my_home};
 
 
 print "testrail-report\n----------------------\n";
 print "testrail-report\n----------------------\n";
 
 
@@ -145,8 +146,10 @@ PARAMETERS:
   uniqueness to get to any run using words.
   uniqueness to get to any run using words.
 
 
   [CONFIG OVERRIDES]
   [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.
   [CONFIG OPTIONS] - These override the config, if present.
                      If neither are used, you will be prompted.
                      If neither are used, you will be prompted.
@@ -198,10 +201,11 @@ sub userInput {
 }
 }
 
 
 sub parseConfig {
 sub parseConfig {
+    my $homedir = shift;
     my $results = {};
     my $results = {};
     my $arr =[];
     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>) {
     while (<$fh>) {
         chomp;
         chomp;
         @$arr = split(/=/,$_);
         @$arr = split(/=/,$_);
@@ -238,8 +242,9 @@ GetOptions(
 if ($help) { help(); }
 if ($help) { help(); }
 
 
 #Parse config file if we are missing api url/key or user
 #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
 #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<TAP::Parser>
 
 
+L<File::HomeDir> for the finding of .testrailrc
+
 =head1 SPECIAL THANKS
 =head1 SPECIAL THANKS
 
 
 Thanks to cPanel Inc, for graciously funding the creation of this module.
 Thanks to cPanel Inc, for graciously funding the creation of this module.

+ 1 - 1
dist.ini

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

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

@@ -7,6 +7,8 @@ use strict;
 use warnings;
 use warnings;
 use utf8;
 use utf8;
 
 
+use File::HomeDir qw{my_home};
+
 =head1 SYNOPSIS
 =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`
 `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.
 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.
 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
     apiurl=http://some.testrail.install
     user=someGuy
     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
     step_results=sr_sys_name
 
 
 Note that passing configurations as filters for runs inside of plans are separated by colons.
 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
 =head1 OVERRIDDEN METHODS
 
 
@@ -86,7 +89,9 @@ sub _parseConfig {
     my $results = {};
     my $results = {};
     my $arr =[];
     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>) {
     while (<$fh>) {
         chomp;
         chomp;
         @$arr = split(/=/,$_);
         @$arr = split(/=/,$_);
@@ -112,6 +117,8 @@ L<Test::Rail::Parser>
 
 
 L<App::Prove>
 L<App::Prove>
 
 
+L<File::HomeDir> for the finding of .testrailrc
+
 =head1 SPECIAL THANKS
 =head1 SPECIAL THANKS
 
 
 Thanks to cPanel Inc, for graciously funding the creation of this module.
 Thanks to cPanel Inc, for graciously funding the creation of this module.