Browse Source

Fix #140 by adding prophylaxis against undef steps/plan

This is only an issue on older perls where this value can be undef
George S. Baugh 7 years ago
parent
commit
9b24ce19a4
2 changed files with 12 additions and 2 deletions
  1. 1 1
      lib/Test/Rail/Parser.pm
  2. 11 1
      t/Test-Rail-Parser.t

+ 1 - 1
lib/Test/Rail/Parser.pm

@@ -550,7 +550,7 @@ sub EOFCallback {
     $status = $self->{'global_status'} if $self->{'global_status'};
 
     #Notify user about bad plan a bit better, supposing we haven't bailed
-    if (!$self->is_good_plan()  && !$self->{'is_bailout'}) {
+    if (!$self->is_good_plan()  && !$self->{'is_bailout'} && defined $self->tests_run && defined $self->tests_planned ) {
         $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'};

+ 11 - 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' => 125;
+use Test::More 'tests' => 126;
 use Test::Fatal qw{exception};
 use Test::Deep qw{cmp_deeply};
 use Capture::Tiny qw{capture capture_stderr};
@@ -604,3 +604,13 @@ $opts->{'tap'} = $fcontents;
 #Issue 143
 my $warns = capture_stderr { $tap = Test::Rail::Parser->new($opts) };
 is($warns, '', "No warnings parsing TAP with undef plans");
+
+#Issue 140
+$fcontents = "
+todo_pass.test ..
+";
+undef $opts->{'source'};
+$opts->{'tap'} = $fcontents;
+
+$warns = capture_stderr { $tap = Test::Rail::Parser->new($opts) };
+is($warns, '', "No warnings parsing TAP with NOTESTS");