瀏覽代碼

Fix #50: ignore ~/.testrailrc when TESTRAIL_MOCKED

George S. Baugh 10 年之前
父節點
當前提交
67d76031e6
共有 9 個文件被更改,包括 35 次插入31 次删除
  1. 2 0
      Changes
  2. 1 1
      bin/testrail-report
  3. 1 1
      bin/testrail-runs
  4. 1 1
      bin/testrail-tests
  5. 6 21
      lib/App/Prove/Plugin/TestRail.pm
  6. 4 3
      lib/TestRail/Utils.pm
  7. 9 0
      t/.testrailrc
  8. 0 2
      t/App-Prove-Plugin-Testrail.t
  9. 11 2
      t/TestRail-Utils.t

+ 2 - 0
Changes

@@ -2,6 +2,8 @@ Revision history for Perl module TestRail::API
 
 0.027 2015-06-?? TEODESIAN
     - If no tests are run (environment fail), set test status to 'retest' on non case-per-ok tests
+    - Fix issue where having a ~/.testrailrc would prevent make test from allowing install by cpan client
+    - Add Plan Summarizer function
 
 0.026 2015-06-06 TEODESIAN
     - Add --no-match option to testrail-tests to find orphan tests in a tree

+ 1 - 1
bin/testrail-report

@@ -252,7 +252,7 @@ if ($help) { help(); }
 #Parse config file if we are missing api url/key or user
 my $homedir = my_home() || '.';
 if (-e $homedir . '/.testrailrc' && (!$apiurl || !$password || !$user) ) {
-    ($apiurl,$password,$user) = TestRail::Utils::parseConfig($homedir);
+    ($apiurl,$password,$user) = TestRail::Utils::parseConfig($homedir,1);
 }
 
 #XXX not even close to optimized, don't slurp in the future

+ 1 - 1
bin/testrail-runs

@@ -116,7 +116,7 @@ if ($opts{help}) { help(); }
 #Parse config file if we are missing api url/key or user
 my $homedir = my_home() || '.';
 if (-e $homedir . '/.testrailrc' && (!$opts{apiurl} || !$opts{pass} || !$opts{user}) ) {
-    ($opts{apiurl},$opts{pass},$opts{user}) = TestRail::Utils::parseConfig($homedir);
+    ($opts{apiurl},$opts{pass},$opts{user}) = TestRail::Utils::parseConfig($homedir,1);
 }
 
 #Interrogate user if they didn't provide info

+ 1 - 1
bin/testrail-tests

@@ -146,7 +146,7 @@ if ($opts{'match'} && $opts{'no-match'}) {
 #Parse config file if we are missing api url/key or user
 my $homedir = my_home() || '.';
 if (-e $homedir . '/.testrailrc' && (!$opts{apiurl} || !$opts{pass} || !$opts{user}) ) {
-    ($opts{apiurl},$opts{pass},$opts{user}) = TestRail::Utils::parseConfig($homedir);
+    ($opts{apiurl},$opts{pass},$opts{user}) = TestRail::Utils::parseConfig($homedir,1);
 }
 
 #Interrogate user if they didn't provide info

+ 6 - 21
lib/App/Prove/Plugin/TestRail.pm

@@ -57,7 +57,12 @@ sub load {
 
     my $app = $p->{app_prove};
     my $args = $p->{'args'};
-    my $params = _parseConfig();
+
+    my $params = {};
+
+    #Only attempt parse if we aren't mocking and the homedir exists
+    my $homedir = my_home() || '.';
+    $params = TestRail::Utils::parseConfig($homedir) if -e $homedir && !$ENV{'TESTRAIL_MOCKED'};
 
     my @kvp = ();
     my ($key,$value);
@@ -91,26 +96,6 @@ sub load {
     return $class;
 }
 
-sub _parseConfig {
-    my $results = {};
-    my $arr =[];
-
-    my $homedir = my_home() || '.';
-
-    open(my $fh, '<', $homedir . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
-    while (<$fh>) {
-        chomp;
-        @$arr = split(/=/,$_);
-        if (scalar(@$arr) != 2) {
-            warn("Could not parse $_ in tlreport config\n");
-            next;
-        }
-        $results->{lc($arr->[0])} = $arr->[1];
-    }
-    close($fh);
-    return $results;
-}
-
 1;
 
 __END__

+ 4 - 3
lib/TestRail/Utils.pm

@@ -38,7 +38,7 @@ ARRAY - (apiurl,password,user)
 =cut
 
 sub parseConfig {
-    my $homedir = shift;
+    my ($homedir,$login_only) = @_;
     my $results = {};
     my $arr =[];
 
@@ -47,13 +47,14 @@ sub parseConfig {
         chomp;
         @$arr = split(/=/,$_);
         if (scalar(@$arr) != 2) {
-            warn("Could not parse $_ in tlreport config\n");
+            warn("Could not parse $_ in '$homedir/.testrailrc'!\n");
             next;
         }
         $results->{lc($arr->[0])} = $arr->[1];
     }
     close($fh);
-    return ($results->{'apiurl'},$results->{'password'},$results->{'user'});
+    return ($results->{'apiurl'},$results->{'password'},$results->{'user'}) if $login_only;
+    return $results;
 }
 
 1;

+ 9 - 0
t/.testrailrc

@@ -6,3 +6,12 @@ password=happy
 nugs=gravy
 slkdjf;lanl.vnjnrohtowhjtoil4j423t90ujlkf;/z;nxfl`1`~@$%^^&*()_+?<:"{}
 =====================================
+project=TestProject66
+run=TestRun666
+plan=GosPlan666
+configs=config1:config2:config3: ... :configN
+version=xx.xx.xx.xx
+case_per_ok=0
+step_results=sr_sys_name
+spawn=123
+sections=section1:section2:section3:sectionN

+ 0 - 2
t/App-Prove-Plugin-Testrail.t

@@ -39,5 +39,3 @@ $prove = App::Prove->new();
 $prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=bogoRun,version=0.014,case_per_ok=1,spawn=9,sections=fake.test:CARBON LIQUEFACTION",'t/fake.test');
 
 is (exception {$prove->run()},undef,"Running TR parser can discriminate by sections correctly");
-
-

+ 11 - 2
t/TestRail-Utils.t

@@ -1,15 +1,24 @@
 use strict;
 use warnings;
 
-use Test::More 'tests' => 4;
+use Test::More 'tests' => 8;
 use Test::Fatal;
 use TestRail::Utils;
 use File::Basename qw{dirname};
 
 my ($apiurl,$user,$password);
-is(exception {($apiurl,$password,$user) = TestRail::Utils::parseConfig(dirname(__FILE__))}, undef, "No exceptions thrown by parseConfig");
+
+#check the binary output mode
+is(exception {($apiurl,$password,$user) = TestRail::Utils::parseConfig(dirname(__FILE__),1)}, undef, "No exceptions thrown by parseConfig in array mode");
 is($apiurl,'http://hokum.bogus',"APIURL parse OK");
 is($user,'zippy',"USER parse OK");
 is($password, 'happy', 'PASSWORD parse OK');
 
+my $out;
+is(exception {$out = TestRail::Utils::parseConfig(dirname(__FILE__))}, undef, "No exceptions thrown by parseConfig default mode");
+is($out->{apiurl},'http://hokum.bogus',"APIURL parse OK");
+is($out->{user},'zippy',"USER parse OK");
+is($out->{password}, 'happy', 'PASSWORD parse OK');
+
+
 #Regrettably, I have yet to find a way to print to stdin without eval, so userInput will remain untested.