Ver código fonte

Fixes #5 - parses skip messages correctly

Also does the same for TODO and TODOSKIP.
Also set the result type of skip_all correctly.
George S. Baugh 11 anos atrás
pai
commit
8a6f38eebc

+ 2 - 1
lib/Test/LWP/UserAgent/TestRailMock.pm

@@ -907,6 +907,7 @@ $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4,
 
 }
 
+
 {
 
 $VAR1 = 'index.php?/api/v2/get_tests/2';
@@ -956,7 +957,7 @@ $VAR4 = bless( {
                  'content-type' => 'application/json; charset=utf-8',
                  'server' => 'Apache/2.4.7 (Ubuntu)'
                }, 'HTTP::Headers' );
-$VAR5 = '[{"id":15,"case_id":8,"status_id":3,"assignedto_id":null,"run_id":22,"title":"STORAGE TANKS SEARED","type_id":6,"priority_id":4,"estimate":null,"estimate_forecast":null,"refs":null,"milestone_id":null,"custom_preconds":null,"custom_steps":null,"custom_expected":null},{"id":15,"case_id":8,"status_id":3,"assignedto_id":null,"run_id":22,"title":"NOT SO SEARED AFTER ARR"}]';
+$VAR5 = '[{"id":15,"case_id":8,"status_id":3,"assignedto_id":null,"run_id":22,"title":"STORAGE TANKS SEARED","type_id":6,"priority_id":4,"estimate":null,"estimate_forecast":null,"refs":null,"milestone_id":null,"custom_preconds":null,"custom_steps":null,"custom_expected":null},{"id":15,"case_id":8,"status_id":3,"assignedto_id":null,"run_id":22,"title":"NOT SO SEARED AFTER ARR"},{"id":15,"case_id":8,"status_id":3,"assignedto_id":null,"run_id":22,"title":"skipall.test"} ]';
 $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
 
 }

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

@@ -262,16 +262,36 @@ sub testCallback {
 
     print "Assuming test name is '$test_name'...\n" if $self->{'tr_opts'}->{'debug'} && !$self->{'tr_opts'}->{'step_results'};
 
+    my $todo_reason;
     #Setup args to pass to function
     my $status = $self->{'tr_opts'}->{'not_ok'}->{'id'};
     if ($test->is_actual_ok()) {
         $status = $self->{'tr_opts'}->{'ok'}->{'id'};
-        $status = $self->{'tr_opts'}->{'skip'}->{'id'} if $test->has_skip();
-        $status = $self->{'tr_opts'}->{'todo_pass'}->{'id'} if $test->has_todo();
+        if ($test->has_skip()) {
+            $status = $self->{'tr_opts'}->{'skip'}->{'id'};
+            $test_name =~ s/^(ok|not ok)\s[0-9]*\s//g;
+            $test_name =~ s/^# skip //gi;
+        }
+        if ($test->has_todo()) {
+            $status = $self->{'tr_opts'}->{'todo_pass'}->{'id'};
+            $test_name =~ s/^(ok|not ok)\s[0-9]*\s//g;
+            $test_name =~ s/(^# todo & skip )//gi; #handle todo_skip
+            $test_name =~ s/ # todo\s(.*)$//gi;
+            $todo_reason = $1;
+        }
     } else {
-        $status = $self->{'tr_opts'}->{'todo_fail'}->{'id'} if $test->has_todo();
+        if ($test->has_todo()) {
+            $status = $self->{'tr_opts'}->{'todo_pass'}->{'id'};
+            $test_name =~ s/^(ok|not ok)\s[0-9]*\s//g;
+            $test_name =~ s/^# todo & skip //gi; #handle todo_skip
+            $test_name =~ s/# todo\s(.*)$//gi;
+            $todo_reason = $1;
+        }
     }
 
+    #If this is a TODO, set the reason in the notes
+    $self->{'tr_opts'}->{'test_notes'} .= "\nTODO reason: $todo_reason\n" if $todo_reason;
+
     #Setup step options and exit if that's the mode we be rollin'
     if ($self->{'tr_opts'}->{'step_results'}) {
         $self->{'tr_opts'}->{'result_custom_options'} = {} if !defined $self->{'tr_opts'}->{'result_custom_options'};
@@ -327,6 +347,7 @@ sub EOFCallback {
 
     my $status = $self->{'tr_opts'}->{'ok'}->{'id'};
     $status = $self->{'tr_opts'}->{'not_ok'}->{'id'} if $self->has_problems();
+    $status = $self->{'tr_opts'}->{'skip'}->{'id'} if $self->skip_all();
 
     #Optional args
     my $notes          = $self->{'tr_opts'}->{'test_notes'};
@@ -377,6 +398,10 @@ sub _set_result {
 
 __END__
 
+=head1 NOTES
+
+When using SKIP: {} (or TODO skip) blocks, you may want to consider naming your skip reasons the same as your test names when running in test_per_ok mode.
+
 =head1 SEE ALSO
 
 L<TestRail::API>

+ 47 - 1
t/Test-Rail-Parser.t

@@ -6,7 +6,7 @@ use warnings;
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 use Test::Rail::Parser;
-use Test::More 'tests' => 15;
+use Test::More 'tests' => 21;
 use Test::Fatal qw{exception};
 
 #Same song and dance as in TestRail-API.t
@@ -163,5 +163,51 @@ if (!$res) {
     is($tap->{'errors'},0,"No errors encountered uploading case results");
 }
 
+#skip/todo in case_per_ok
+undef $tap;
+$res = exception {
+    $tap = Test::Rail::Parser->new({
+        'source'              => 't/skip.test',
+        'apiurl'              => $apiurl,
+        'user'                => $login,
+        'pass'                => $pw,
+        'debug'               => $debug,
+        'browser'             => $browser,
+        'run'                 => 'TestingSuite',
+        'project'             => 'TestProject',
+        'case_per_ok'         => 1,
+        'merge'               => 1
+    });
+};
+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");
+}
+
+#Default mode skip (skip_all)
+undef $tap;
+$res = exception {
+    $tap = Test::Rail::Parser->new({
+        'source'              => 't/skipall.test',
+        'apiurl'              => $apiurl,
+        'user'                => $login,
+        'pass'                => $pw,
+        'debug'               => $debug,
+        'browser'             => $browser,
+        'run'                 => 'TestingSuite',
+        'project'             => 'TestProject',
+        'merge'               => 1
+    });
+};
+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");
+}
 
 0;

+ 17 - 0
t/skip.test

@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+
+use Test::More 'tests' => 3;
+
+SKIP: {
+    skip 'STORAGE TANKS SEARED', 1;
+    fail('STROGGIFY POPULATION CENTERS');
+};
+TODO: {
+    todo_skip 'NOT SO SEARED AFTER ARR', 1;
+    fail('STROGGIFY POPULATION CENTERS');
+};
+TODO: {
+    local $TODO =  'skippity doo dah';
+    pass('STORAGE TANKS SEARED');
+};

+ 1 - 0
t/skipall.test

@@ -0,0 +1 @@
+use Test::More 'skip_all' => 'cause I can';