Pārlūkot izejas kodu

Fix #38 add --no-match option to testrail tests to find orphans

George S. Baugh 10 gadi atpakaļ
vecāks
revīzija
ed91eab91b
2 mainītis faili ar 30 papildinājumiem un 5 dzēšanām
  1. 10 4
      bin/testrail-tests
  2. 20 1
      t/testrail-tests.t

+ 10 - 4
bin/testrail-tests

@@ -21,7 +21,8 @@ testrail-tests - list tests in a run matching the provided filters.
 
     -p --plan [plan]: desired plan name.  Required if the run passed is a child of a plan.
     -m --match [dir]: attempt to find filenames matching the test names in the provided dir.
-    -n --no-recurse: if match passed, do not recurse subdirectories.
+    --no-match [dir]: attempt to find filenames that do not match test names in the provided dir.
+    -n --no-recurse: if match (or no-match) passed, do not recurse subdirectories.
 
 =head3 OPTIONAL PARAMETERS
 
@@ -82,6 +83,7 @@ PARAMETERS:
 
     -p --plan [plan]: desired plan name.  Required if the run passed is a child of a plan.
     -m --match [dir]: attempt to find filenames matching the test names in the provided dir.
+    --no-match [dir]: attempt to find filenames that do not match the test names in the provided dir.
     -n --no-recurse: if match passed, do not recurse subdirectories.
 
   [OPTIONAL PARAMETERS]
@@ -126,6 +128,7 @@ GetOptions(
     'a|assignedto=s@' => \$opts{'users'},
     'mock'            => \$opts{'mock'},
     'm|match=s'       => \$opts{'match'},
+    'no-match=s'      => \$opts{'no-match'},
     'n|no-recurse'    => \$opts{'no-recurse'},
     'h|help'          => \$opts{'help'}
 );
@@ -235,14 +238,17 @@ if (!$cases) {
 my @tests =  map {$_->{'title'}} @$cases;
 my @realtests;
 
-if ($opts{'match'}) {
+if ($opts{'match'} || $opts{'no-match'}) {
+    my $dir = $opts{'match'} ? $opts{'match'} : $opts{'no-match'};
     if (!$opts{'no-recurse'}) {
-        File::Find::find( sub { push(@realtests,$File::Find::name) if -f }, $opts{'match'} );
+        File::Find::find( sub { push(@realtests,$File::Find::name) if -f }, $dir );
         @tests = grep {my $real = $_; grep { basename($real) eq $_ } @tests} @realtests; #XXX if you have dups in your tree, be-ware
     } else {
         #Handle special windows case -- glob doesn't prepend abspath
-        @tests = map {$^O eq 'MSWin32' ? $opts{'match'}."/$_" : $_ } grep {my $fname = $_; grep { basename($_) eq $fname} glob($opts{'match'}."/*") } @tests;
+        @realtests = glob("$dir/*");
+        @tests = map {$^O eq 'MSWin32' ? "$dir/$_" : $_ } grep {my $fname = $_; grep { basename($_) eq $fname} @realtests } @tests;
     }
+    @tests = grep {my $otest = basename($_); scalar(grep {basename($_) eq $otest} @tests) == 0} @realtests if $opts{'no-match'}; #invert the list in this case.
 }
 
 @tests = map { abs_path($_) } @tests if $opts{'match'};

+ 20 - 1
t/testrail-tests.t

@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More "tests" => 22;
+use Test::More "tests" => 30;
 
 #check plan mode
 my @args = ($^X,qw{bin/testrail-tests --apiurl http://testrail.local --user "test@fake.fake" --password "fake" -j TestProject -p "GosPlan" -r "Executing the great plan" -m t --config testConfig --mock --no-recurse});
@@ -10,6 +10,25 @@ is($? >> 8, 0, "Exit code OK running plan mode, no recurse");
 chomp $out;
 like($out,qr/skipall\.test$/,"Gets test correctly in plan mode, no recurse");
 
+#check no-match
+@args = ($^X,qw{bin/testrail-tests --apiurl http://testrail.local --user "test@fake.fake" --password "fake" -j TestProject -p "GosPlan" -r "Executing the great plan" --no-match t --config testConfig --mock});
+$out = `@args`;
+is($? >> 8, 0, "Exit code OK running plan mode, no match");
+chomp $out;
+unlike($out,qr/skipall\.test/,"Omits test correctly in plan mode, recurse, no-match");
+unlike($out,qr/NOT SO SEARED AFTER ARR/,"Omits non-file test correctly in plan mode, recurse, no-match");
+like($out,qr/faker\.test/,"Omits non-file test correctly in plan mode, recurse, no-match");
+
+#check no-match, no recurse
+@args = ($^X,qw{bin/testrail-tests --apiurl http://testrail.local --user "test@fake.fake" --password "fake" -j TestProject -p "GosPlan" -r "Executing the great plan" --no-match t --config testConfig --mock --no-recurse});
+$out = `@args`;
+is($? >> 8, 0, "Exit code OK running plan mode, no match, no recurse");
+chomp $out;
+unlike($out,qr/skipall\.test/,"Omits test correctly in plan mode, no recurse, no-match");
+unlike($out,qr/NOT SO SEARED AFTER ARR/,"Omits non-file test correctly in plan mode, no recurse, no-match");
+like($out,qr/faker\.test/,"Omits non-file test correctly in plan mode, no recurse, no-match");
+
+
 @args = ($^X,qw{bin/testrail-tests --apiurl http://testrail.local --user "test@fake.fake" --password "fake" -j TestProject -p "GosPlan" -r "Executing the great plan" --config testConfig -m t --mock});
 $out = `@args`;
 is($? >> 8, 0, "Exit code OK running plan mode, recurse");