Pārlūkot izejas kodu

Fix #78, add unit tests

George S. Baugh 10 gadi atpakaļ
vecāks
revīzija
c69d30ee27
2 mainītis faili ar 16 papildinājumiem un 5 dzēšanām
  1. 7 3
      lib/Test/Rail/Parser.pm
  2. 9 2
      t/Test-Rail-Parser.t

+ 7 - 3
lib/Test/Rail/Parser.pm

@@ -9,7 +9,7 @@ use utf8;
 
 use parent qw/TAP::Parser/;
 use Carp qw{cluck confess};
-use POSIX qw{floor};
+use POSIX qw{floor strftime};
 use Clone qw{clone};
 
 use TestRail::API;
@@ -357,12 +357,15 @@ sub testCallback {
         #Test done.  Record elapsed time.
         my $tm = time();
         $self->{'tr_opts'}->{'result_options'}->{'elapsed'} = _compute_elapsed($self->{'lasttime'},$tm);
+        $self->{'elapse_display'} = defined($self->{'tr_opts'}->{'result_options'}->{'elapsed'}) ? $self->{'tr_opts'}->{'result_options'}->{'elapsed'} : "0s";
         $self->{'lasttime'} = $tm;
     }
 
     #Default assumption is that case name is step text (case_per_ok), unless...
     my $line = $test->as_string;
-    $self->{'raw_output'} .= "$line\n";
+    my $tline = $line;
+    $tline = "[".strftime("%H:%M:%S %b %e %Y",localtime($self->{'lasttime'}))." ($self->{elapse_display})] $line" if $self->{'track_time'};
+    $self->{'raw_output'} .= "$tline\n";
 
     #Don't do anything if we don't want to map TR case => ok or use step-by-step results
     if ( !($self->{'tr_opts'}->{'step_results'} || $self->{'tr_opts'}->{'case_per_ok'}) ) {
@@ -422,7 +425,8 @@ sub testCallback {
         $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'};
         #TimeStamp every particular step
-        $line = "[".$self->{'tr_opts'}->{'result_options'}->{'elapsed'}."] $line";
+
+        $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'}},

+ 9 - 2
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' => 83;
+use Test::More 'tests' => 85;
 use Test::Fatal qw{exception};
 
 #Same song and dance as in TestRail-API.t
@@ -82,7 +82,7 @@ not ok 2 - NOT SO SEARED AFTER ARR
 #   at t/fake.test line 10.
 # Looks like you failed 1 test of 2.
 ";
-is($tap->{'raw_output'},$fcontents,"Full raw content uploaded in non step results mode");
+like($tap->{'raw_output'},qr/SEARED\n# whee.*\n.*AFTER ARR\n\n.*Failed/msxi,"Full raw content uploaded in non step results mode");
 
 #Check that time run is being uploaded
 my $timeResults = $tap->{'tr_opts'}->{'testrail'}->getTestResults(1);
@@ -113,6 +113,11 @@ if (!$res) {
     $tap->run();
     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 {
+        foreach my $result (@{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}}) {
+            like($result->{'content'}, qr/^\[.*\(.*\)\]/i, "Timestamp printed in step results");
+        }
+    };
 }
 
 #Default mode
@@ -125,6 +130,8 @@ isa_ok($tap,"Test::Rail::Parser");
 if (!$res) {
     $tap->run();
     is($tap->{'errors'},0,"No errors encountered uploading case results");
+    my @matches = $tap->{'raw_output'} =~ m/^(\[.*\(.*\)\])/msgi;
+    ok(scalar(@matches),"Timestamps present in raw TAP");
 }
 
 #Default mode