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

svn at limb-project.com svn at limb-project.com
Sun Apr 13 11:15:26 MSD 2008


Author: pachanga
Date: 2008-04-13 11:15:26 +0400 (Sun, 13 Apr 2008)
New Revision: 6926
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6926

Modified:
   3.x/trunk/limb/runtests.php
   3.x/trunk/limb/tests_runner/src/lmbTestGetopt.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestShellReporter.class.php
   3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
   3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
Log:
-- adding -V/--verbose option
-- some more experiments with shell reporter: 
 * showing names of cases and methods if verbose mode is on 
 * showing more meaningfull name of the group test(it's fragile though)
 * showing names of failed tests
-- fixing bug in command line constants extracting



Modified: 3.x/trunk/limb/runtests.php
===================================================================
--- 3.x/trunk/limb/runtests.php	2008-04-11 21:43:55 UTC (rev 6925)
+++ 3.x/trunk/limb/runtests.php	2008-04-13 07:15:26 UTC (rev 6926)
@@ -9,7 +9,6 @@
 $fork = false;
 $quiet = false;
 $tests = array();
-$failed_tests = array();
 
 function out($msg)
 {
@@ -82,25 +81,17 @@
 {
   if(file_exists($test) || is_dir($test))
   {
-    out("=========== Running tests from '$test' ===========\n");
-
     if($fork)
     {
       system($php_bin . " " . __FILE__ . " -q $test", $ret);
       if($ret != 0)
-      {
         $res = false;
-        $failed_tests[] = $test;
-      }
     }
     else
     {
       $runner = new lmbTestRunner();
       if(!$runner->run(new lmbTestTreeFilePathNode($test)))
-      {
         $res = false;
-        $failed_tests[] = $test;
-      }
     }
   }
   else
@@ -108,10 +99,7 @@
 }
 
 if(!$res)
-{
-  out("=========== TESTS HAD ERRORS ===========\n");
-  out("Failed tests: [" . implode(", ", $failed_tests) . "]\n");
-}
+  out("=========== TESTS HAD ERRORS(see above) ===========\n");
 else
   out("=========== ALL TESTS PASSED ===========\n");
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestGetopt.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestGetopt.class.php	2008-04-11 21:43:55 UTC (rev 6925)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestGetopt.class.php	2008-04-13 07:15:26 UTC (rev 6926)
@@ -92,18 +92,21 @@
 
     function defineAndExtractConstants(&$argv)
     {
+        $filtered = array();
         for($i=0;$i<sizeof($argv);$i++) {
-          if(preg_match('~^[A-Z_][A-Z0-9_]+$~', $argv[$i])) {
+          //Windows cmd.exe uses '=' symbols as separators
+          //that's why we need to fetch the next argument as well
+          if(preg_match('~^[A-Z_][A-Z0-9_]+$~', $argv[$i]) && isset($argv[$i+1])) {
             @define($argv[$i], $argv[$i+1]);
-            unset($argv[$i]);
-            unset($argv[$i+1]);
             $i++;
           }
           elseif(preg_match('~^([A-Z_][A-Z0-9_]+)=(.*)$~', $argv[$i], $m)) {
             @define($m[1], $m[2]);
-            unset($argv[$i]);
+          } else {
+            $filtered[] = $argv[$i];
           }
         }
+        $argv = $filtered;
     }
 
     /**

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php	2008-04-11 21:43:55 UTC (rev 6925)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestOptions.class.php	2008-04-13 07:15:26 UTC (rev 6926)
@@ -46,8 +46,6 @@
     if(self :: $has_defaults)
       return;
 
-    //???
-
     self :: $has_defaults = true;
   }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestShellReporter.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestShellReporter.class.php	2008-04-11 21:43:55 UTC (rev 6925)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellReporter.class.php	2008-04-13 07:15:26 UTC (rev 6926)
@@ -16,10 +16,18 @@
 class lmbTestShellReporter extends TextReporter
 {
   protected $failed_tests = array();
+  protected $first_group_test = false;
 
   function paintGroupStart($test_name, $size)
   {
     parent :: paintGroupStart($test_name, $size);
+
+    //TODO: make this less fragile
+    if(!$this->first_group_test && strpos($test_name, "Group test in") === 0)
+    {
+      $this->first_group_test = true;
+      print "=========== $test_name ===========\n";
+    }
   }
 
   function paintGroupEnd($test_name)
@@ -30,17 +38,24 @@
   function paintCaseStart($test_name)
   {
     parent :: paintCaseStart($test_name);
+
+    if(lmbTestOptions :: get('verbose'))
+      print "======== $test_name ========\n";
   }
 
   function paintCaseEnd($test_name)
   {
     parent :: paintCaseEnd($test_name);
-    echo $this->getTestCaseProgress() . " of " . $this->getTestCaseCount() . " done({$test_name})\n";
+
+    print $this->getTestCaseProgress() . " of " . $this->getTestCaseCount() . " done({$test_name})\n";
   }
 
   function paintMethodStart($test_name)
   {
     parent :: paintMethodStart($test_name);
+
+    if(lmbTestOptions :: get('verbose'))
+      print "===== [$test_name] =====\n";
   }
 
   function paintMethodEnd($test_name)
@@ -55,7 +70,7 @@
 
   function paintHeader($test_name) 
   {
-    parent :: paintHeader($test_name);
+    //don't show any header since it's shown in paintGroupStart
   }
 
   function paintFooter($test_name) 
@@ -67,26 +82,23 @@
     if($memory = $runner->getMemoryUsage())
       print 'Tests memory usage: ' . $memory . " Mb.\n";
 
-    /*if($this->failed_tests)
+    if($this->failed_tests)
     {
-      print "=========== TESTS HAD ERRORS ===========\n";
-      print "Failed tests: [" . implode(", ", $this->failed_tests) . "]\n";
+      print "=========== FAILED TESTS  ===========\n";
+      print implode("\n", $this->failed_tests) . "\n";
     }
-    else
-      print "=========== ALL TESTS PASSED ===========\n";
-      */
   }
 
   function paintFail($message) 
   {
     parent :: paintFail($message);
-    $this->failed_tests[] = $this->_extractFileName($message);
+    $this->failed_tests[] = $this->_extractFileNameAndLine($message);
   }
 
   function paintError($message) 
   {
     parent :: paintError($message);
-    $this->failed_tests[] = $this->_extractFileName($message);
+    $this->failed_tests[] = $this->_extractFileNameAndLine($message);
   }
 
   function paintException($exception) 
@@ -105,11 +117,11 @@
     print $exception->__toString();
   }  
 
-  protected function _extractFileName($message)
+  protected function _extractFileNameAndLine($message)
   {
     $regex = "~.*\[([^\]]+)\s+line\s+(\d+)\].*~";
     preg_match($regex, $message, $m);
-    return $m[1];
+    return $m[1] . ':' . $m[2];
   }
 }
 

Modified: 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2008-04-11 21:43:55 UTC (rev 6925)
+++ 3.x/trunk/limb/tests_runner/src/lmbTestShellUI.class.php	2008-04-13 07:15:26 UTC (rev 6926)
@@ -64,6 +64,7 @@
                                                 as constants using PHP define call
 Options:
   -h, --help                        Displays this help and exit
+  -V, --verbose                     Be extra verbose
   -c, --config=/file.php            PHP configuration file path
   -I, --include='filter1;filter2'   Sets file filters used for including test files during
                                     recursive traversal of directories.
@@ -119,12 +120,12 @@
 
   static function getShortOpts()
   {
-    return 'hvI:c:C:T:M:G:';
+    return 'hVvI:c:C:T:M:G:';
   }
 
   static function getLongOpts()
   {
-    return array('help', 'version', 'include=', 'config=',
+    return array('help', 'verbose', 'version', 'include=', 'config=',
                  'cover=', 'cover-report=', 'cover-exclude=',
                  'tests=', 'methods=', 'groups=');
   }
@@ -176,6 +177,10 @@
         case '--help':
           $this->_help(0);
           break;
+        case 'V':
+        case '--verbose':
+          lmbTestOptions :: set('verbose', true);
+          break;
         case 'v':
         case '--version':
           $this->_version();

Modified: 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php
===================================================================
--- 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2008-04-11 21:43:55 UTC (rev 6925)
+++ 3.x/trunk/limb/tests_runner/tests/cases/lmbTestShellUITest.class.php	2008-04-13 07:15:26 UTC (rev 6926)
@@ -151,8 +151,8 @@
 
   function testAutoDefineConstants()
   {
-    $c1 = "FOO_" . mt_rand();
-    $c2 = "FOO_" . mt_rand();
+    $c1 = "FOO_" . mt_rand() . "_H" . mt_rand();
+    $c2 = "FOO_" . mt_rand() . "_K" . mt_rand();
 
     $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);



More information about the limb-svn mailing list