Bladeren bron

Fix #69 - Consider completion status of runs when spawning.

George S. Baugh 10 jaren geleden
bovenliggende
commit
f32043d513
6 gewijzigde bestanden met toevoegingen van 172 en 385 verwijderingen
  1. 2 0
      Changes
  2. 23 25
      lib/Test/Rail/Parser.pm
  3. 132 346
      t/Test-Rail-Parser.t
  4. 6 6
      t/TestRail-Utils-Find.t
  5. 6 5
      t/lib/Test/LWP/UserAgent/TestRailMock.pm
  6. 3 3
      t/testrail-runs.t

+ 2 - 0
Changes

@@ -9,6 +9,8 @@ Revision history for Perl module TestRail::API
     - Make above function and TestRail::API::sectionNamesToIds return values in correct order
     - Change the 'spawn' option in Test::Rail::Parser (and it's callers) to be --testsuite_id
     - Add a --testsuite (name) option to Test::Rail::Parser
+    - Spawning runs will now take run/plan completion status into account, spawning new runs/plans when completion is detected.
+    - Removed the run_id option from Test::Rail::Parser and it's callers.  It isn't really useful in practice, and was not tested.
 
 0.030 2015-07-31 TEODESIAN
     - Fix testrail-tests, was calling function in incorrect namespace

+ 23 - 25
lib/Test/Rail/Parser.pm

@@ -10,6 +10,7 @@ use utf8;
 use parent qw/TAP::Parser/;
 use Carp qw{cluck confess};
 use POSIX qw{floor};
+use Clone qw{clone};
 
 use TestRail::API;
 use TestRail::Utils;
@@ -53,11 +54,9 @@ Get the TAP Parser ready to talk to TestRail, and register a bunch of callbacks
 
 =item B<browser> - OBJECT: Something like an LWP::UserAgent.  Useful for mocking.
 
-=item B<run> - STRING (semi-optional): name of desired run. Required if run_id not passed.
+=item B<run> - STRING: name of desired run.
 
-=item B<run_id> - INTEGER (semi-optional): ID of desired run. Required if run not passed.
-
-=item B<plan> - STRING (semi-optional): Name of test plan to use, if your run provided is a child of said plan.  Only relevant when run_id not passed.
+=item B<plan> - STRING (semi-optional): Name of test plan to use, if your run provided is a child of said plan.
 
 =item B<configs> - ARRAYREF (optional): Configurations to filter runs in plan by.  Runs can have the same name, yet with differing configurations in a plan; this handles that odd case.
 
@@ -110,6 +109,7 @@ Step results will always be whatever status is relevant to the particular step.
 sub new {
     my ($class,$opts) = @_;
     our $self;
+    $opts = clone $opts; #Convenience, if we are passing over and over again...
 
     #Load our callbacks
     $opts->{'callbacks'} = {
@@ -126,7 +126,6 @@ sub new {
         'debug'        => delete $opts->{'debug'},
         'browser'      => delete $opts->{'browser'},
         'run'          => delete $opts->{'run'},
-        'run_id'       => delete $opts->{'run_id'},
         'project'      => delete $opts->{'project'},
         'project_id'   => delete $opts->{'project_id'},
         'step_results' => delete $opts->{'step_results'},
@@ -143,6 +142,7 @@ sub new {
         'result_custom_options' => delete $opts->{'result_custom_options'}
     };
 
+    confess("plan passed, but no run passed!") if !$tropts->{'run'} && $tropts->{'plan'};
     confess("case_per_ok and step_results options are mutually exclusive") if ($tropts->{'case_per_ok'} && $tropts->{'step_results'});
 
     #Allow natural confessing from constructor
@@ -195,7 +195,6 @@ sub new {
     }
 
     #Grab run
-    my $run_id = $tropts->{'run_id'};
     my ($run,$plan,$config_ids);
 
     #check if configs passed are defined for project.  If we can't get all the IDs, something's hinky
@@ -205,31 +204,30 @@ sub new {
     my $num_bogus = scalar(@bogus_configs);
     confess("Detected $num_bogus bad config names passed.  Check available configurations for your project.") if $num_bogus;
 
-    if ($tropts->{'run'}) {
-        if ($tropts->{'plan'}) {
-            #Attempt to find run, filtered by configurations
-            $plan = $tr->getPlanByName($tropts->{'project_id'},$tropts->{'plan'});
-            if ($plan) {
-                $tropts->{'plan'} = $plan;
-                $run = $tr->getChildRunByName($plan,$tropts->{'run'},$tropts->{'configs'}); #Find plan filtered by configs
-                if (defined($run) && (reftype($run) || 'undef') eq 'HASH') {
-                    $tropts->{'run'} = $run;
-                    $tropts->{'run_id'} = $run->{'id'};
-                }
-            } else {
-                #Try to make it if spawn is passed
-                $tropts->{'plan'} = $tr->createPlan($tropts->{'project_id'},$tropts->{'plan'},"Test plan created by TestRail::API") if $tropts->{'testsuite_id'};
-                confess("Could not find plan ".$tropts->{'plan'}." in provided project, and spawning failed (or was not indicated)!") if !$tropts->{'plan'};
-            }
-        } else {
-            $run = $tr->getRunByName($tropts->{'project_id'},$tropts->{'run'});
+    if ($tropts->{'plan'}) {
+        #Attempt to find run, filtered by configurations
+        $plan = $tr->getPlanByName($tropts->{'project_id'},$tropts->{'plan'});
+        confess("Test plan provided is completed, and spawning was not indicated") if (ref $plan eq 'HASH') && $plan->{'is_completed'} && (!$tropts->{'testsuite_id'});
+        if ($plan && !$plan->{'is_completed'}) {
+            $tropts->{'plan'} = $plan;
+            $run = $tr->getChildRunByName($plan,$tropts->{'run'},$tropts->{'configs'}); #Find plan filtered by configs
+
             if (defined($run) && (reftype($run) || 'undef') eq 'HASH') {
                 $tropts->{'run'} = $run;
                 $tropts->{'run_id'} = $run->{'id'};
             }
+        } else {
+            #Try to make it if spawn is passed
+            $tropts->{'plan'} = $tr->createPlan($tropts->{'project_id'},$tropts->{'plan'},"Test plan created by TestRail::API") if $tropts->{'testsuite_id'};
+            confess("Could not find plan ".$tropts->{'plan'}." in provided project, and spawning failed (or was not indicated)!") if !$tropts->{'plan'};
         }
     } else {
-        $tropts->{'run'} = $tr->getRunByID($run_id);
+        $run = $tr->getRunByName($tropts->{'project_id'},$tropts->{'run'});
+        confess("Test run provided is completed, and spawning was not indicated") if (ref $run eq 'HASH') && $run->{'is_completed'} && (!$tropts->{'testsuite_id'});
+        if (defined($run) && (reftype($run) || 'undef') eq 'HASH' && !$run->{'is_completed'}) {
+            $tropts->{'run'} = $run;
+            $tropts->{'run_id'} = $run->{'id'};
+        }
     }
 
     #If spawn was passed and we don't have a Run ID yet, go ahead and make it

+ 132 - 346
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' => 78;
+use Test::More 'tests' => 83;
 use Test::Fatal qw{exception};
 
 #Same song and dance as in TestRail-API.t
@@ -31,7 +31,6 @@ if ($is_mock) {
 #TODO
 
 #case_per_ok mode
-
 my $fcontents = "
 fake.test ..
 1..2
@@ -40,20 +39,21 @@ ok 1 - STORAGE TANKS SEARED
 not ok 2 - NOT SO SEARED AFTER ARR
 ";
 my $tap;
-my $res = exception {
-    $tap = Test::Rail::Parser->new({
-        'tap'                 => $fcontents,
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'TestingSuite',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'case_per_ok'         => 1
-    });
+
+my $opts = {
+    'tap'                 => $fcontents,
+    'apiurl'              => $apiurl,
+    'user'                => $login,
+    'pass'                => $pw,
+    'debug'               => $debug,
+    'browser'             => $browser,
+    'run'                 => 'TestingSuite',
+    'project'             => 'TestProject',
+    'merge'               => 1,
+    'case_per_ok'         => 1
 };
+
+my $res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -63,20 +63,9 @@ if (!$res) {
 }
 
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/fake.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'TestingSuite',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'case_per_ok'         => 1
-    });
-};
+delete $opts->{'tap'};
+$opts->{'source'} = 't/fake.test';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -111,20 +100,12 @@ is(Test::Rail::Parser::_compute_elapsed(0,86461),'24h 1m 1s',"Elapsed computatio
 
 #Time for non case_per_ok mode
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/faker.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'OtherOtherSuite',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'step_results'        => 'step_results'
-    });
-};
+$opts->{'source'} = 't/faker.test';
+$opts->{'run'} = 'OtherOtherSuite';
+delete $opts->{'case_per_ok'};
+$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");
 
@@ -136,19 +117,8 @@ if (!$res) {
 
 #Default mode
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/faker.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'OtherOtherSuite',
-        'project'             => 'TestProject',
-        'merge'               => 1
-    });
-};
+delete $opts->{'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");
 
@@ -169,21 +139,12 @@ ok 1 - STORAGE TANKS SEARED
 #goo
 not ok 2 - NOT SO SEARED AFTER ARR
 ";
-
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'tap'         => $fcontents,
-        'apiurl'      => $apiurl,
-        'user'        => $login,
-        'pass'        => $pw,
-        'debug'       => $debug,
-        'browser'     => $browser,
-        'run'         => 'TestingSuite',
-        'project'     => 'TestProject',
-        'case_per_ok' => 1,
-        'merge'       => 1
-    });
-};
+$opts->{'tap'} = $fcontents;
+delete $opts->{'source'};
+delete $opts->{'step_results'};
+$opts->{'run'} = 'TestingSuite';
+$opts->{'case_per_ok'} = 1;
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -194,20 +155,9 @@ if (!$res) {
 
 #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
-    });
-};
+delete $opts->{'tap'};
+$opts->{'source'} = 't/skip.test';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -218,19 +168,9 @@ if (!$res) {
 
 #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
-    });
-};
+$opts->{'source'} = 't/skipall.test';
+delete $opts->{'case_per_ok'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -242,39 +182,16 @@ if (!$res) {
 
 #Ok, let's test the plan, config, and spawn bits.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/skipall.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'hoo hoo I do not exist',
-        'plan'                => 'mah dubz plan',
-        'configs'             => ['testPlatform1'],
-        'project'             => 'TestProject',
-        'merge'               => 1
-    });
-};
+$opts->{'run'} = 'hoo hoo I do not exist';
+$opts->{'plan'} = 'mah dubz plan';
+$opts->{'configs'} = ['testPlatform1'];
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
 
 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',
-        'plan'                => 'mah dubz plan',
-        'configs'             => ['testConfig'],
-        'project'             => 'TestProject',
-        'merge'               => 1
-    });
-};
+$opts->{'run'} = 'TestingSuite';
+$opts->{'configs'} = ['testConfig'];
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -285,22 +202,10 @@ if (!$res) {
 
 #Now, test spawning.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/skipall.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'TestingSuite2',
-        'plan'                => 'mah dubz plan',
-        'configs'             => ['testPlatform1'],
-        'project'             => 'TestProject',
-        'testsuite_id'        => 9,
-        'merge'               => 1
-    });
-};
+$opts->{'run'} = 'TestingSuite2';
+$opts->{'configs'} = ['testPlatform1'];
+$opts->{'testsuite_id'} = 9;
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -312,20 +217,11 @@ if (!$res) {
 #Test spawning of builds not in plans.
 #Now, test spawning.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/skipall.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'TestingSuite2',
-        'project'             => 'TestProject',
-        'testsuite'           => 'HAMBURGER-IZE HUMANITY',
-        'merge'               => 1
-    });
-};
+delete $opts->{'testsuite_id'};
+delete $opts->{'plan'};
+delete $opts->{'configs'};
+$opts->{'testsuite'} = 'HAMBURGER-IZE HUMANITY';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -336,21 +232,11 @@ if (!$res) {
 
 #Test spawning of plans and runs.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/skipall.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'plan'                => 'BogoPlan',
-        'project'             => 'TestProject',
-        'testsuite_id'        => 9,
-        'merge'               => 1
-    });
-};
+$opts->{'run'} = 'BogoRun';
+$opts->{'plan'} = 'BogoPlan';
+$opts->{'testsuite_id'} = 9;
+delete $opts->{'testsuite'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -361,43 +247,18 @@ if (!$res) {
 
 #Verify that case_per_ok and step_results are mutually exclusive, and die.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/skipall.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'plan'                => 'BogoPlan',
-        'project'             => 'TestProject',
-        'testsuite_id'        => 9,
-        'merge'               => 1,
-        'case_per_ok'         => 1,
-        'step_results'        => 'sr_step_results'
-    });
-};
+$opts->{'case_per_ok'} = 1;
+$opts->{'step_results'} = 'sr_step_results';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 isnt($res,undef,"TR Parser explodes on instantiation when mutually exclusive options are passed");
 
 #Check that per-section spawn works
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/fake.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'testsuite_id'        => 9,
-        'sections'            => ['fake.test'],
-        'case_per_ok'         => 1
-    });
-};
+$opts->{'source'} = 't/fake.test';
+delete $opts->{'plan'};
+$opts->{'sections'} = ['fake.test'];
+delete $opts->{'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");
 
@@ -408,23 +269,8 @@ if (!$res) {
 
 #Check that per-section spawn works
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/fake.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'plan'                => 'BogoPlan',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'testsuite_id'        => 9,
-        'sections'            => ['fake.test'],
-        'case_per_ok'         => 1
-    });
-};
+$opts->{'plan'} = 'BogoPlan';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -434,39 +280,16 @@ if (!$res) {
 }
 
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/fake.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'testsuite_id'        => 9,
-        'sections'            => ['potzrebie'],
-        'case_per_ok'         => 1
-    });
-};
+$opts->{'sections'} = ['potzrebie'];
+delete $opts->{'plan'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 isnt($res,undef,"TR Parser explodes on instantiation with invalid section");
 
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/notests.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'testsuite_id'        => 9,
-    });
-};
+$opts->{'source'} = 't/notests.test';
+delete $opts->{'sections'};
+delete $opts->{'case_per_ok'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -477,20 +300,8 @@ if (!$res) {
 }
 
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/pass.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'testsuite_id'        => 9,
-    });
-};
+$opts->{'source'} = 't/pass.test';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -501,20 +312,8 @@ if (!$res) {
 }
 
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/todo_pass.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'testsuite_id'        => 9,
-    });
-};
+$opts->{'source'} = 't/todo_pass.test';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -526,21 +325,10 @@ if (!$res) {
 
 #Check autoclose functionality against Run with all tests in run status.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/skip.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'FinalRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'autoclose'           => 1,
-        'testsuite_id'        => 9,
-    });
-};
+$opts->{'source'} = 't/skip.test';
+$opts->{'run'} = 'FinalRun';
+$opts->{'autoclose'} = 1;
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -552,21 +340,9 @@ if (!$res) {
 
 #Check autoclose functionality against Run with not all tests in run status.
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/todo_pass.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'project'             => 'TestProject',
-        'merge'               => 1,
-        'autoclose'           => 1,
-        'testsuite_id'        => 9,
-    });
-};
+$opts->{'source'} = 't/todo_pass.test';
+$opts->{'run'} = 'BogoRun';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -578,23 +354,12 @@ if (!$res) {
 
 #Check that autoclose works against plan wiht all tests in run status
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/fake.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'FinalRun',
-        'plan'                => 'FinalPlan',
-        'project'             => 'TestProject',
-        'configs'             => ['testConfig'],
-        'merge'               => 1,
-        'autoclose'           => 1,
-        'case_per_ok'         => 1
-    });
-};
+$opts->{'source'} = 't/fake.test';
+$opts->{'run'} = 'FinalRun';
+$opts->{'plan'} = 'FinalPlan';
+$opts->{'configs'} = ['testConfig'];
+$opts->{'case_per_ok'} = 1;
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -604,25 +369,11 @@ if (!$res) {
     is($tap->{'plan_closed'},1, "Plan closed by parser when all tests done");
 }
 
-#Check that autoclose works against plan wiht all tests not in run status
+#Check that autoclose works against plan with all tests not in run status
 undef $tap;
-$res = exception {
-    $tap = Test::Rail::Parser->new({
-        'source'              => 't/fake.test',
-        'apiurl'              => $apiurl,
-        'user'                => $login,
-        'pass'                => $pw,
-        'debug'               => $debug,
-        'browser'             => $browser,
-        'run'                 => 'BogoRun',
-        'plan'                => 'BogoPlan',
-        'project'             => 'TestProject',
-        'testsuite_id'        => 9,
-        'merge'               => 1,
-        'autoclose'           => 1,
-        'case_per_ok'         => 1
-    });
-};
+$opts->{'run'} = 'BogoRun';
+$opts->{'plan'} = 'BogoPlan';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
 is($res,undef,"TR Parser doesn't explode on instantiation");
 isa_ok($tap,"Test::Rail::Parser");
 
@@ -632,3 +383,38 @@ if (!$res) {
     is($tap->{'plan_closed'},undef, "Plan not closed by parser when results are outstanding");
 }
 
+#Plan but no run 'splodes
+undef $tap;
+$opts->{'plan'} = 'CompletePlan';
+delete $opts->{'run'};
+delete $opts->{'configs'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
+like($res,qr/but no run passed/i,"TR Parser explodes on instantiation due to passing plan with no run");
+
+#Check that trying without spawn opts, using completed plan fails
+undef $tap;
+$opts->{'plan'} = 'ClosedPlan';
+$opts->{'run'} = 'BogoRun';
+delete $opts->{'testsuite_id'};
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
+like($res,qr/plan provided is completed/i,"TR Parser explodes on instantiation due to passing closed plan");
+
+#Check that the above two will just spawn a new plan in these cases
+$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");
+
+#Check that trying without spawn opts, using completed run fails
+undef $tap;
+delete $opts->{'testsuite_id'};
+delete $opts->{'plan'};
+$opts->{'run'} = 'ClosedRun';
+$res = exception { $tap = Test::Rail::Parser->new($opts) };
+like($res,qr/run provided is completed/i,"TR Parser explodes on instantiation due to passing closed run");
+
+#Check that the above two will just spawn a new run in these cases
+$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");
+
+

+ 6 - 6
t/TestRail-Utils-Find.t

@@ -30,27 +30,27 @@ $tr->{'browser'} = $Test::LWP::UserAgent::TestRailMock::mockObject;
 
 my $runs = TestRail::Utils::Find::findRuns($opts,$tr);
 is(ref $runs, 'ARRAY', "FindRuns returns ARRAYREF");
-is(scalar(@$runs),4,"All runs for project found when no other options are passed");
+is(scalar(@$runs),5,"All runs for project found when no other options are passed");
 @$runs = map {$_->{'name'}} @$runs;
-my @expected = qw{OtherOtherSuite TestingSuite FinalRun lockRun};
+my @expected = qw{OtherOtherSuite TestingSuite FinalRun lockRun ClosedRun};
 cmp_deeply($runs,\@expected,"Tests ordered FIFO by creation date correctly");
 
 $opts->{'lifo'} = 1;
 $runs = TestRail::Utils::Find::findRuns($opts,$tr);
 @$runs = map {$_->{'name'}} @$runs;
-@expected = qw{lockRun TestingSuite FinalRun OtherOtherSuite};
+@expected = qw{lockRun ClosedRun TestingSuite FinalRun OtherOtherSuite};
 cmp_deeply($runs,\@expected,"Tests ordered LIFO by creation date correctly");
 
 $opts->{'milesort'} = 1;
 $runs = TestRail::Utils::Find::findRuns($opts,$tr);
 @$runs = map {$_->{'name'}} @$runs;
-@expected = qw{OtherOtherSuite TestingSuite FinalRun lockRun};
+@expected = qw{OtherOtherSuite TestingSuite FinalRun lockRun ClosedRun};
 cmp_deeply($runs,\@expected,"Tests ordered LIFO by milestone date correctly");
 
 delete $opts->{'lifo'};
 $runs = TestRail::Utils::Find::findRuns($opts,$tr);
 @$runs = map {$_->{'name'}} @$runs;
-@expected = qw{TestingSuite FinalRun lockRun OtherOtherSuite};
+@expected = qw{TestingSuite FinalRun lockRun ClosedRun OtherOtherSuite};
 cmp_deeply($runs,\@expected,"Tests ordered LIFO by milestone date correctly");
 
 delete $opts->{'milesort'};
@@ -72,7 +72,7 @@ is(scalar(@$runs),0,"No passing runs can be found in projects without them");
 
 $opts->{'statuses'} = ['retest'];
 $runs = TestRail::Utils::Find::findRuns($opts,$tr);
-is(scalar(@$runs),1,"Failed runs can be found in projects with them");
+is(scalar(@$runs),2,"Failed runs can be found in projects with them");
 
 #Test testrail-tests
 

File diff suppressed because it is too large
+ 6 - 5
t/lib/Test/LWP/UserAgent/TestRailMock.pm


+ 3 - 3
t/testrail-runs.t

@@ -8,21 +8,21 @@ my @args = ($^X,qw{bin/testrail-runs --apiurl http://testrail.local --user "test
 my $out = `@args`;
 is($? >> 8, 0, "Exit code OK looking for runs with passes");
 chomp $out;
-like($out,qr/^OtherOtherSuite\nTestingSuite\nFinalRun\nlockRun$/,"Gets run correctly looking for passes");
+like($out,qr/^OtherOtherSuite\nTestingSuite\nFinalRun\nlockRun\nClosedRun$/,"Gets run correctly looking for passes");
 
 #check LIFO sort
 @args = ($^X,qw{bin/testrail-runs --apiurl http://testrail.local --user "test@fake.fake" --password "fake" -j "TestProject" --lifo --mock});
 $out = `@args`;
 is($? >> 8, 0, "Exit code OK looking for runs with passes");
 chomp $out;
-like($out,qr/^lockRun\nTestingSuite\nFinalRun\nOtherOtherSuite$/,"LIFO sort works");
+like($out,qr/^lockRun\nClosedRun\nTestingSuite\nFinalRun\nOtherOtherSuite$/,"LIFO sort works");
 
 #check milesort
 @args = ($^X,qw{bin/testrail-runs --apiurl http://testrail.local --user "test@fake.fake" --password "fake" -j "TestProject" --milesort --mock});
 $out = `@args`;
 is($? >> 8, 0, "Exit code OK looking for runs with passes");
 chomp $out;
-like($out,qr/^TestingSuite\nFinalRun\nlockRun\nOtherOtherSuite$/,"milesort works");
+like($out,qr/^TestingSuite\nFinalRun\nlockRun\nClosedRun\nOtherOtherSuite$/,"milesort works");
 
 
 #check status filters

Some files were not shown because too many files changed in this diff