Parcourir la source

Fix #80: Report bad plan in case per test mode better

George S. Baugh il y a 9 ans
Parent
commit
26d47a535a
3 fichiers modifiés avec 41 ajouts et 1 suppressions
  1. 1 0
      Changes
  2. 13 0
      lib/Test/Rail/Parser.pm
  3. 27 1
      t/Test-Rail-Parser.t

+ 1 - 0
Changes

@@ -5,6 +5,7 @@ Revision history for Perl module TestRail::API
     - Allow users to signal Test::Rail::Parser to set a custom status
     - Fix issue where todo_pass would be marked even when a bad plan occurred
     - Add functions for TestRail 5.2 add/update/remove configurations & groups
+    - Add bad plan step_result and a comment when not in case_per_ok & bad plan detected
 
 0.033 2016-01-06 TEODESIAN
     - Fix issue where running TestRail::Parser with multiple -j in prove corrupted results

+ 13 - 0
lib/Test/Rail/Parser.pm

@@ -517,6 +517,19 @@ sub EOFCallback {
     #Global status override
     $status = $self->{'global_status'} if $self->{'global_status'};
 
+    #Notify user about bad plan a bit better
+    if (!$self->is_good_plan()) {
+        $self->{'raw_output'} .= "\n# ERROR: Bad plan.  You ran ".$self->tests_run." tests, but planned ".$self->tests_planned.".";
+        if ($self->{'tr_opts'}->{'step_results'}) {
+            #Handle the case where we die right off
+            $self->{'tr_opts'}->{'result_custom_options'}->{'step_results'} //= [];
+            push(
+                @{$self->{'tr_opts'}->{'result_custom_options'}->{'step_results'}},
+                TestRail::API::buildStepResults("Bad Plan.",$self->tests_planned." Tests",$self->tests_run." Tests",$status)
+            );
+        }
+    }
+
     #Optional args
     my $notes          = $self->{'tr_opts'}->{'test_notes'};
     $notes = $self->{'raw_output'};

+ 27 - 1
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' => 93;
+use Test::More 'tests' => 99;
 use Test::Fatal qw{exception};
 
 #Same song and dance as in TestRail-API.t
@@ -340,6 +340,7 @@ ok 1 - STORAGE TANKS SEARED #TODO todo pass
 ";
 undef $opts->{'source'};
 $opts->{'tap'} = $fcontents;
+$opts->{'step_results'} = 'step_results';
 $res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
@@ -348,7 +349,32 @@ if (!$res) {
     $tap->run();
     is($tap->{'errors'},0,"No errors encountered uploading case results");
     is($tap->{'global_status'},5, "Test global result is FAIL on todo pass test w/ bad plan");
+    my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
+    is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
+}
+undef $opts->{'step_results'};
+
+#Check instant pizza
+$fcontents = "
+todo_pass.test ..
+1..2
+";
+undef $opts->{'source'};
+$opts->{'tap'} = $fcontents;
+$opts->{'step_results'} = 'step_results';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
+is($res,undef,"TR Parser doesn't explode on instantiation");
+isa_ok($tap,"Test::Rail::Parser");
+
+if (!$res) {
+    $tap->run();
+    is($tap->{'errors'},0,"No errors encountered uploading case results");
+    is($tap->{'global_status'},4, "Test global result is FAIL on todo pass test w/ bad plan");
+    my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
+    is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
 }
+undef $opts->{'step_results'};
+
 
 undef $tap;
 #Check bad plan w/ todo pass logic