[limb-svn] r6491 - in 3.x/trunk/limb/tests_runner: src tests tests/cases

svn at limb-project.com svn at limb-project.com
Tue Nov 6 23:17:33 MSK 2007


Author: pachanga
Date: 2007-11-06 23:17:33 +0300 (Tue, 06 Nov 2007)
New Revision: 6491
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6491

Modified:
   3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
   3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
   3.x/trunk/limb/tests_runner/tests/common.inc.php
Log:
-- adding group selector by annotation functionality(TR-18)

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php	2007-11-06 15:18:01 UTC (rev 6490)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php	2007-11-06 20:17:33 UTC (rev 6491)
@@ -19,7 +19,8 @@
 {
   static protected $valid_keys = array('file_filter', 
                                        'methods_filter',
-                                       'groups_filter');
+                                       'groups_filter',
+                                       'verbose');
   static protected $options = array();
   static protected $has_defaults = false;
 
@@ -47,7 +48,8 @@
 
     self :: $options = array('file_filter' => LIMB_TESTS_RUNNER_FILE_FILTER,
                             'methods_filter' => array(),
-                            'groups_filter' => array());
+                            'groups_filter' => array(),
+                            'verbose' => false);
 
     self :: $has_defaults = true;
   }

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2007-11-06 15:18:01 UTC (rev 6490)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2007-11-06 20:17:33 UTC (rev 6491)
@@ -66,6 +66,8 @@
   -I, --include='filter1;filter2'   Sets file filters used for including test files during
                                     recursive traversal of directories.
                                     '*Test.class.php;*test.php;*Test.php' by default.
+  -G, --groups=group1[,group2]      Comma separated list of test groups defined in annotations 
+                                    tags which should be executed(e.g @group group1,group2) 
   -M, --methods=testFoo[,testBar]   Comma separated list of test methods which should be
                                     executed 
   -C, --cover=path1;path2           Sets paths delimitered with ';' which should be analyzed
@@ -113,14 +115,14 @@
 
   static function getShortOpts()
   {
-    return 'hvI:c:C:M:';
+    return 'hvI:c:C:M:G:';
   }
 
   static function getLongOpts()
   {
     return array('help', 'version', 'include=', 'config=', 
                  'cover=', 'cover-report=', 'cover-exclude=',
-                 'methods=');
+                 'methods=', 'groups=');
   }
 
   function run()
@@ -182,6 +184,14 @@
         case '--include':
           lmbTestOptions :: set('file_filter', $option[1]);
           break;
+        case 'G':
+        case '--groups':
+          lmbTestOptions :: set('groups_filter', array_map('trim', explode(',', trim($option[1]))));
+          break;
+        case 'M':
+        case '--methods':
+          lmbTestOptions :: set('methods_filter', array_map('trim', explode(',', trim($option[1]))));
+          break;
         case 'C':
         case '--cover':
           $cover_include = $option[1];
@@ -192,10 +202,6 @@
         case '--cover-exclude':
           $cover_exclude = $option[1];
           break;
-        case 'M':
-        case '--methods':
-          lmbTestOptions :: set('methods_filter', array_map('trim', explode(',', trim($option[1]))));
-          break;
       }
     }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php	2007-11-06 15:18:01 UTC (rev 6490)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php	2007-11-06 20:17:33 UTC (rev 6491)
@@ -41,6 +41,27 @@
      return $matches[1];
   }
 
+  protected function _isClassGroupFiltered($class)
+  {
+    if(!$groups = lmbTestOptions :: get('groups_filter'))
+      return false;
+
+    $refclass = new ReflectionClass($class);
+    $doc = $refclass->getDocComment();
+
+    //if there's a group filter and no group annotation class is filtered
+    if(!preg_match('~.*@group\s+([^\n]+).*~s', $doc, $matches))
+      return true;
+
+    $doc_groups = array_map('trim', explode(',', trim($matches[1])));
+    foreach($doc_groups as $group)
+    {
+      if(in_array($group, $groups))
+        return false;
+    }
+    return true;
+  }
+
   protected function _prepareTestCase($test)
   {
     require_once($this->file);
@@ -48,6 +69,9 @@
     $loader = new SimpleFileLoader();
     foreach($loader->selectRunnableTests($candidates) as $class)
     {
+      if($this->_isClassGroupFiltered($class))
+        continue;
+
       $case = new $class();
       $case->filter(lmbTestOptions :: get('methods_filter'));
       $test->addTestCase($case);

Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2007-11-06 15:18:01 UTC (rev 6490)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2007-11-06 20:17:33 UTC (rev 6491)
@@ -99,14 +99,19 @@
 
   function testPerformOnlySelectedMethods()
   {
-    $foo_body = 'function testFoo(){ echo "foo";}';
-    $foo_body .= 'function testJunk(){ echo "junk";}';
-    $bar_body = 'function testBar(){ echo "bar";}';
-    $bar_body .= 'function testJunk(){ echo "junk";}';
+    $foo_body  = '%class_header%'; 
+    $foo_body .= 'function testFoo(){echo "foo";}';
+    $foo_body .= 'function testJunk(){echo "junk";}';
+    $foo_body .= '%class_footer%';
 
-    $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php', '', $foo_body);
-    $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/bar_test.php', '', $bar_body);
+    $bar_body  = '%class_header%';
+    $bar_body .= 'function testBar(){echo "bar";}';
+    $bar_body .= 'function testJunk(){echo "junk";}'; 
+    $bar_body .= '%class_footer%';
 
+    $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php', $foo_body);
+    $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/bar_test.php', $bar_body);
+
     $ret = $this->_execScript("--methods=testFoo,testBar $foo_file $bar_file", $screen);
     if(!$this->assertEqual($ret, 0))
       echo $screen;
@@ -115,12 +120,27 @@
     $this->assertPattern('~bar2\s+of\s+2\s+done\(' . $bar->getClass() . '\)~', $screen);
   }
 
+  function testPerformOnlySelectedGroupsOfTests()
+  {
+    $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php', "/**\n* @group foo\n*/ %class%");
+    $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/bar_test.php', "/**\n* @group bar\n*/ %class%");
+    $junk = $this->_createTestCase($junk_file = LIMB_VAR_DIR . '/cases/junk_test.php', "/*\n* @group junk\n*/ %class%");
+
+    $ret = $this->_execScript("--groups=foo,bar $foo_file $bar_file $junk_file", $screen);
+    if(!$this->assertEqual($ret, 0))
+      echo $screen;
+
+    $this->assertPattern('~1\s+of\s+2\s+done\(' . $foo->getClass() . '\)~', $screen);
+    $this->assertPattern('~2\s+of\s+2\s+done\(' . $bar->getClass() . '\)~', $screen);
+    $this->assertNoPattern('~' . $junk->getClass() . '~', $screen);
+  }
+
   function testAutoDefineConstants()
   {
     $c1 = "FOO_" . mt_rand();
     $c2 = "FOO_" . mt_rand();
 
-    $this->_createTestCase($f = LIMB_VAR_DIR . '/cases/foo_test.php', "echo '$c1=' . $c1;echo '$c2=' . $c2;");
+    $this->_createTestCase($f = LIMB_VAR_DIR . '/cases/foo_test.php', "%class%\n echo '$c1=' . $c1;echo '$c2=' . $c2;");
     $this->_execScript("$f $c1=hey $c2=wow", $screen);
 
     $this->assertPattern("~$c1=hey~", $screen);

Modified: 3.x/trunk/limb/tests_runner/tests/common.inc.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/common.inc.php	2007-11-06 15:18:01 UTC (rev 6490)
+++ 3.x/trunk/limb/tests_runner/tests/common.inc.php	2007-11-06 20:17:33 UTC (rev 6491)
@@ -12,7 +12,7 @@
   protected $class_name;
   protected $body;
 
-  function __construct($body = null)
+  function __construct($body = '%class%')
   {
     $this->class_name = 'GenClass_' . mt_rand(1, 10000);
     $this->body = $body;
@@ -53,23 +53,26 @@
 
   function generateClass()
   {
-    if(!$this->body)
-      $body = "function testSay() {echo \"" . $this->getOutput() . "\";}";
-    else
-      $body = $this->body;
+    $parts = array();
+    $parts['%class_header%'] = "\nclass {$this->class_name} extends UnitTestCase {\n"; 
+    $parts['%class_footer%'] = "\n}\n";
+    $parts['%class%'] = $parts['%class_header%'] . 
+                        "function testMe() {echo \"" . $this->getOutput() . "\";}" . 
+                        $parts['%class_footer%'];
 
-    $code = "class {$this->class_name} extends UnitTestCase {
-             $body
-            }";
-    return $code;
+    return str_replace(array_keys($parts), array_values($parts), $this->body);
   }
 
   function generateClassFailing()
   {
-    $code = "class {$this->class_name} extends UnitTestCase {
-              function testSay() {\$this->assertTrue(false);echo \"" . $this->getOutput() . "\";}
-            }";
-    return $code;
+    $parts = array();
+    $parts['%class_header%'] = "\nclass {$this->class_name} extends UnitTestCase {\n"; 
+    $parts['%class_footer%'] = "\n}\n";
+    $parts['%class%'] = $parts['%class_header%'] . 
+                        "function testMe() {\$this->assertTrue(false);echo \"" . $this->getOutput() . "\";}" . 
+                        $parts['%class_footer%'];
+
+    return str_replace(array_keys($parts), array_values($parts), $this->body);
   }
 }
 
@@ -94,25 +97,25 @@
     return $res;
   }
 
-  function _createTestCase($file, $extra = '', $body = '')
+  function _createTestCase($file, $body = '%class%')
   {
     $dir = dirname($file);
     if(!is_dir($dir))
       mkdir($dir, 0777, true);
 
     $generated = new GeneratedTestClass($body);
-    file_put_contents($file, "<?php\n" . $generated->generateClass() . $extra . "\n?>");
+    file_put_contents($file, "<?php\n" . $generated->generateClass() . "\n?>");
     return $generated;
   }
 
-  function _createTestCaseFailing($file, $extra = '', $body = '')
+  function _createTestCaseFailing($file, $body = '%class%')
   {
     $dir = dirname($file);
     if(!is_dir($dir))
       mkdir($dir, 0777, true);
 
     $generated = new GeneratedTestClass($body);
-    file_put_contents($file, "<?php\n" . $generated->generateClassFailing() . $extra . "\n?>");
+    file_put_contents($file, "<?php\n" . $generated->generateClassFailing() . "\n?>");
     return $generated;
   }
 



More information about the limb-svn mailing list