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

svn at limb-project.com svn at limb-project.com
Mon Nov 5 02:35:34 MSK 2007


Author: pachanga
Date: 2007-11-05 02:35:34 +0300 (Mon, 05 Nov 2007)
New Revision: 6487
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6487

Added:
   3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php
Modified:
   3.x/trunk/limb/tests_runner/lib/simpletest/test_case.php
   3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php
   3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
   3.x/trunk/limb/tests_runner/tests/common.inc.php
Log:
-- completing TR-20: now it's possible using --methods command line option to execute only specified test methods, e.g $ limb_unit --methods=testFoo,testBar sometest.php
-- lmbTestOptions added, it will be used as a global container for all options


Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/test_case.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/test_case.php	2007-11-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/test_case.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -44,6 +44,7 @@
         var $_reporter;
         var $_observers;
 		var $_should_skip = false;
+    var $_methods_filter = array();
 
         /**
          *    Sets up the test with no display.
@@ -151,6 +152,11 @@
             return $reporter->getStatus();
         }
 
+        function filter($methods_filter)
+        {
+            $this->_methods_filter = array_map('strtolower', $methods_filter);
+        }
+
         /**
          *    Gets a list of test names. Normally that will
          *    be all internal methods that start with the
@@ -179,6 +185,8 @@
          */
         function _isTest($method) {
             if (strtolower(substr($method, 0, 4)) == 'test') {
+                if ($this->_methods_filter && !in_array(strtolower($method), $this->_methods_filter))
+                    return false;
                 return ! SimpleTestCompatibility::isA($this, strtolower($method));
             }
             return false;

Added: 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php	                        (rev 0)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -0,0 +1,62 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+ at define('LIMB_TESTS_RUNNER_FILE_FILTER', '*Test.class.php;*test.php;*Test.php');
+
+/**
+ * class lmbTestOptions.
+ *
+ * @package tests_runner
+ * @version $Id$
+ */
+class lmbTestOptions
+{
+  static protected $valid_keys = array('file_filter', 
+                                       'methods_filter',
+                                       'groups_filter');
+  static protected $options = array();
+  static protected $has_defaults = false;
+
+  static function set($name, $value)
+  {
+    self :: _initDefaults();
+    self :: _check($name);
+
+    self :: $options[$name] = $value;
+  }
+
+  static function get($name)
+  {
+    self :: _initDefaults();
+    self :: _check($name);
+
+    if(isset(self :: $options[$name]))
+      return self :: $options[$name];
+  }
+
+  static protected function _initDefaults()
+  {
+    if(self :: $has_defaults)
+      return;
+
+    self :: $options = array('file_filter' => LIMB_TESTS_RUNNER_FILE_FILTER,
+                            'methods_filter' => array(),
+                            'groups_filter' => array());
+
+    self :: $has_defaults = true;
+  }
+
+  static protected function _check($key)
+  {
+    if(!in_array($key, self :: $valid_keys))
+      throw new Exception("Test option '$key' is not supported");
+  }
+}
+
+

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2007-11-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -7,6 +7,7 @@
  * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 require_once(dirname(__FILE__) . '/lmbTestGetopt.class.php');
+require_once(dirname(__FILE__) . '/lmbTestOptions.class.php');
 
 /**
  * class lmbTestShellUI.
@@ -115,7 +116,9 @@
 
   static function getLongOpts()
   {
-    return array('help', 'version', 'include=', 'config=', 'cover=', 'cover-report=', 'cover-exclude=');
+    return array('help', 'version', 'include=', 'config=', 
+                 'cover=', 'cover-report=', 'cover-exclude=',
+                 'methods=');
   }
 
   function run()
@@ -175,7 +178,7 @@
           break;
         case 'I':
         case '--include':
-          @define('LIMB_TESTS_RUNNER_FILE_FILTER', $option[1]);
+          lmbTestOptions :: set('file_filter', $option[1]);
           break;
         case 'C':
         case '--cover':
@@ -187,6 +190,9 @@
         case '--cover-exclude':
           $cover_exclude = $option[1];
           break;
+        case '--methods':
+          lmbTestOptions :: set('methods_filter', explode(',', $option[1]));
+          break;
       }
     }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php	2007-11-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeDirNode.class.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -11,8 +11,6 @@
 require_once(dirname(__FILE__) . '/lmbDetachedFixture.class.php');
 require_once(dirname(__FILE__) . '/lmbTestFileFilter.class.php');
 
- at define('LIMB_TESTS_RUNNER_FILE_FILTER', '*Test.class.php;*test.php;*Test.php');
-
 /**
  * class lmbTestTreeDirNode.
  *
@@ -33,7 +31,7 @@
   static function getFileFilter()
   {
     if(!is_object(self :: $file_filter))
-      self :: setFileFilter(LIMB_TESTS_RUNNER_FILE_FILTER);
+      self :: setFileFilter(lmbTestOptions :: get('file_filter'));
     return self :: $file_filter;
   }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php	2007-11-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeFileNode.class.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -47,7 +47,14 @@
     $candidates = $this->_getClassesDefinedInFile();
     $loader = new SimpleFileLoader();
     foreach($loader->selectRunnableTests($candidates) as $class)
-      $test->addTestCase(new $class());
+    {
+      $case = new $class();
+      $case->filter(lmbTestOptions :: get('methods_filter'));
+      $test->addTestCase($case);
+      //a dirty SimpleTest PHP4 compatibility hack
+      //otherwise $case is overwrittne since it is a reference
+      unset($case);
+    }
   }
 }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php	2007-11-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestTreeGlobNode.class.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -45,7 +45,7 @@
 
   function getTestLabel()
   {
-    return 'All tests in "' . implode(';', $this->paths) . '"(filter "' . LIMB_TESTS_RUNNER_FILE_FILTER . '")';
+    return 'All tests in "' . implode(';', $this->paths) . '"(filter "' . lmbTestOptions :: get('file_filter') . '")';
   }
 }
 

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-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -97,6 +97,24 @@
     $this->assertNoPattern('~Error~i', $screen);
   }
 
+  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 = $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;
+
+    $this->assertPattern('~foo1\s+of\s+2\s+done\(' . $foo->getClass() . '\)~', $screen);
+    $this->assertPattern('~bar2\s+of\s+2\s+done\(' . $bar->getClass() . '\)~', $screen);
+  }
+
   function testAutoDefineConstants()
   {
     $c1 = "FOO_" . mt_rand();

Modified: 3.x/trunk/limb/tests_runner/tests/common.inc.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/common.inc.php	2007-11-04 21:19:50 UTC (rev 6486)
+++ 3.x/trunk/limb/tests_runner/tests/common.inc.php	2007-11-04 23:35:34 UTC (rev 6487)
@@ -10,10 +10,12 @@
 class GeneratedTestClass
 {
   protected $class_name;
+  protected $body;
 
-  function __construct()
+  function __construct($body = null)
   {
     $this->class_name = 'GenClass_' . mt_rand(1, 10000);
+    $this->body = $body;
   }
 
   function getClass()
@@ -51,8 +53,13 @@
 
   function generateClass()
   {
+    if(!$this->body)
+      $body = "function testSay() {echo \"" . $this->getOutput() . "\";}";
+    else
+      $body = $this->body;
+
     $code = "class {$this->class_name} extends UnitTestCase {
-              function testSay() {echo \"" . $this->getOutput() . "\";}
+             $body
             }";
     return $code;
   }
@@ -87,24 +94,24 @@
     return $res;
   }
 
-  function _createTestCase($file, $extra = '')
+  function _createTestCase($file, $extra = '', $body = '')
   {
     $dir = dirname($file);
     if(!is_dir($dir))
       mkdir($dir, 0777, true);
 
-    $generated = new GeneratedTestClass();
+    $generated = new GeneratedTestClass($body);
     file_put_contents($file, "<?php\n" . $generated->generateClass() . $extra . "\n?>");
     return $generated;
   }
 
-  function _createTestCaseFailing($file, $extra = '')
+  function _createTestCaseFailing($file, $extra = '', $body = '')
   {
     $dir = dirname($file);
     if(!is_dir($dir))
       mkdir($dir, 0777, true);
 
-    $generated = new GeneratedTestClass();
+    $generated = new GeneratedTestClass($body);
     file_put_contents($file, "<?php\n" . $generated->generateClassFailing() . $extra . "\n?>");
     return $generated;
   }



More information about the limb-svn mailing list