Kaynağa Gözat

Fix #77 : Add hooks for processing bailouts

George S. Baugh 10 yıl önce
ebeveyn
işleme
02393f812f
2 değiştirilmiş dosya ile 52 ekleme ve 5 silme
  1. 27 2
      lib/Test/Rail/Parser.pm
  2. 25 3
      t/Test-Rail-Parser.t

+ 27 - 2
lib/Test/Rail/Parser.pm

@@ -132,6 +132,7 @@ sub new {
         'test'    => \&testCallback,
         'comment' => \&commentCallback,
         'unknown' => \&unknownCallback,
+        'bailout' => \&bailoutCallback,
         'EOF'     => \&EOFCallback
     };
 
@@ -475,6 +476,30 @@ sub testCallback {
     $self->{'tr_opts'}->{'test_desc'} = undef;
 }
 
+=head2 bailoutCallback
+
+If bail_out is called, note it and add step results.
+
+=cut
+
+sub bailoutCallback {
+    my ($test) = @_;
+    my $self = $test->{'parser'};
+    my $line = $test->as_string;
+    $self->{'raw_output'} .= "$line\n";
+
+    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("Bail Out!.","Continued testing",$test->explanation,$self->{'tr_opts'}->{'not_ok'}->{'id'})
+        );
+    }
+    $self->{'is_bailout'} = 1;
+    return;
+}
+
 =head2 EOFCallback
 
 If we are running in step_results mode, send over all the step results to TestRail.
@@ -517,8 +542,8 @@ 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()) {
+    #Notify user about bad plan a bit better, supposing we haven't bailed
+    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'}) {
             #Handle the case where we die right off

+ 25 - 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' => 99;
+use Test::More 'tests' => 103;
 use Test::Fatal qw{exception};
 
 #Same song and dance as in TestRail-API.t
@@ -369,7 +369,7 @@ 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");
+    is($tap->{'global_status'},4, "Test global result is retest when insta-bombout occurs");
     my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
     is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
 }
@@ -394,7 +394,7 @@ isa_ok($tap,"Test::Rail::Parser");
 if (!$res) {
     $tap->run();
     is($tap->{'errors'},0,"No errors encountered uploading case results");
-    is($tap->{'global_status'},7, "Test global result is FAIL on todo pass test w/ bad plan");
+    is($tap->{'global_status'},7, "Test global result is respected when using global status override");
 }
 undef $opts->{'tap'};
 
@@ -491,3 +491,25 @@ like($res,qr/run provided is completed/i,"TR Parser explodes on instantiation du
 $opts->{'testsuite_id'} = 9;
 $res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser runs all the way through on completed run when spawning");
+
+$fcontents = "
+todo_pass.test ..
+1..2
+ok 1 - STORAGE TANKS SEARED #TODO todo pass
+# goo
+Bail out!  #YOLO
+";
+undef $opts->{'source'};
+$opts->{'tap'} = $fcontents;
+$opts->{'step_results'} = 'step_results';
+undef $opts->{'case_per_ok'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
+is($res,undef,"TR Parser runs all the way through on bailout");
+
+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/ bailout");
+    my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
+    is($srs->[-1]->{'content'},"Bail Out!.","Bailout noted in step results");
+}