소스 검색

Fix #97 - quit hardcoding step_results as the actual system name

George S. Baugh 9 년 전
부모
커밋
7aca0c8cf8
4개의 변경된 파일22개의 추가작업 그리고 9개의 파일을 삭제
  1. 1 0
      Changes
  2. 11 6
      lib/Test/Rail/Parser.pm
  3. 2 0
      lib/TestRail/API.pm
  4. 8 3
      t/Test-Rail-Parser.t

+ 1 - 0
Changes

@@ -4,6 +4,7 @@ Revision history for Perl module TestRail::API
     - Fix testrail-report and testrail-cases broken binary arg passing
     - Fix issue where TODO PASS was reported in tests with TODO FAILs.
     - Fix issue where TODO FAILED steps were reported as TODO PASS.
+    - Fix issue where the value of the step_results field was ignored by Test::Rail::Parser
 
 0.034 2016-02-18 TEODESIAN
     - Use Capture::Tiny rahter than IO::CaptureOutput in unit tests

+ 11 - 6
lib/Test/Rail/Parser.pm

@@ -299,7 +299,9 @@ sub new {
     }
 
     #Make sure the step results field passed exists on the system
+    my $sr_name = $tropts->{'step_results'};
     $tropts->{'step_results'} = $tr->getTestResultFieldByName($tropts->{'step_results'},$tropts->{'project_id'}) if defined $tropts->{'step_results'};
+    confess("Invalid step results name '$sr_name' passed.") if ref $tropts->{'step_results'} ne 'HASH' && $sr_name;
 
     $self->{'tr_opts'} = $tropts;
     $self->{'errors'}  = 0;
@@ -455,14 +457,15 @@ sub testCallback {
 
     #Setup step options and exit if that's the mode we be rollin'
     if ($self->{'tr_opts'}->{'step_results'}) {
+        my $sr_sys_name = $self->{'tr_opts'}->{'step_results'}->{'name'};
         $self->{'tr_opts'}->{'result_custom_options'} = {} if !defined $self->{'tr_opts'}->{'result_custom_options'};
-        $self->{'tr_opts'}->{'result_custom_options'}->{'step_results'} = [] if !defined $self->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
+        $self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name} = [] if !defined $self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name};
         #TimeStamp every particular step
 
         $line = "[".strftime("%H:%M:%S %b %e %Y",localtime($self->{'lasttime'}))." ($self->{elapse_display})] $line" if $self->{'track_time'};
         #XXX Obviously getting the 'expected' and 'actual' from the tap DIAGs would be ideal
         push(
-            @{$self->{'tr_opts'}->{'result_custom_options'}->{'step_results'}},
+            @{$self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name}},
             TestRail::API::buildStepResults($line,"OK",$status_name,$status)
         );
         print "# Appended step results.\n" if $self->{'tr_opts'}->{'debug'};
@@ -497,10 +500,11 @@ sub bailoutCallback {
     $self->{'raw_output'} .= "$line\n";
 
     if ($self->{'tr_opts'}->{'step_results'}) {
+        my $sr_sys_name = $self->{'tr_opts'}->{'step_results'}->{'name'};
         #Handle the case where we die right off
-        $self->{'tr_opts'}->{'result_custom_options'}->{'step_results'} //= [];
+        $self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name} //= [];
         push(
-            @{$self->{'tr_opts'}->{'result_custom_options'}->{'step_results'}},
+            @{$self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name}},
             TestRail::API::buildStepResults("Bail Out!.","Continued testing",$test->explanation,$self->{'tr_opts'}->{'not_ok'}->{'id'})
         );
     }
@@ -556,10 +560,11 @@ sub EOFCallback {
     if (!$self->is_good_plan()  && !$self->{'is_bailout'}) {
         $self->{'raw_output'} .= "\n# ERROR: Bad plan.  You ran ".$self->tests_run." tests, but planned ".$self->tests_planned.".";
         if ($self->{'tr_opts'}->{'step_results'}) {
+            my $sr_sys_name = $self->{'tr_opts'}->{'step_results'}->{'name'};
             #Handle the case where we die right off
-            $self->{'tr_opts'}->{'result_custom_options'}->{'step_results'} //= [];
+            $self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name} //= [];
             push(
-                @{$self->{'tr_opts'}->{'result_custom_options'}->{'step_results'}},
+                @{$self->{'tr_opts'}->{'result_custom_options'}->{$sr_sys_name}},
                 TestRail::API::buildStepResults("Bad Plan.",$self->tests_planned." Tests",$self->tests_run." Tests",$status)
             );
         }

+ 2 - 0
lib/TestRail/API.pm

@@ -1957,6 +1957,8 @@ Gets a test result field by it's system name.  Optionally filter by project ID.
 
 =back
 
+Returns a value less than 0 if unsuccessful.
+
 =cut
 
 sub getTestResultFieldByName {

+ 8 - 3
t/Test-Rail-Parser.t

@@ -10,7 +10,7 @@ use Scalar::Util qw{reftype};
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 use Test::Rail::Parser;
-use Test::More 'tests' => 111;
+use Test::More 'tests' => 112;
 use Test::Fatal qw{exception};
 use Test::Deep qw{cmp_deeply};
 
@@ -115,6 +115,7 @@ if (!$res) {
     is($tap->{'errors'},0,"No errors encountered uploading case results");
     is($tap->{'global_status'},5, "Test global result is FAIL when one subtest fails even if there are TODO passes");
     subtest 'Timestamp/elapsed printed in step results' => sub {
+        diag explain $tap->{'tr_opts'}->{'result_custom_options'};
         foreach my $result (@{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}}) {
             like($result->{'content'}, qr/^\[.*\(.*\)\]/i, "Timestamp printed in step results");
         }
@@ -256,7 +257,7 @@ if (!$res) {
 #Verify that case_per_ok and step_results are mutually exclusive, and die.
 undef $tap;
 $opts->{'case_per_ok'} = 1;
-$opts->{'step_results'} = 'sr_step_results';
+$opts->{'step_results'} = 'step_results';
 $res = exception { $tap = Test::Rail::Parser->new($opts) };
 isnt($res,undef,"TR Parser explodes on instantiation when mutually exclusive options are passed");
 
@@ -331,6 +332,11 @@ if (!$res) {
     is($tap->{'global_status'},8, "Test global result is TODO PASS on todo pass test");
 }
 
+undef $tap;
+$opts->{'step_results'} = 'bogus_garbage';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
+like($res,qr/invalid step results/i,"Bogus step results name throws");
+
 undef $tap;
 $opts->{'source'} = 't/todo_pass_and_fail.test';
 $opts->{'step_results'} = 'step_results';
@@ -342,7 +348,6 @@ if (!$res) {
     $tap->run();
     is($tap->{'errors'},1,"Errors encountered uploading case results for case that does not exist in TestRail");
     is($tap->{'global_status'},7, "Test global result is TODO FAIL on todo pass & fail test");
-
     my @desired_statuses = qw{1 8 7};
     my @got_statuses = map {$_->{'status_id'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
     my @desired_expected = ('OK', 'OK', 'OK');