Changeset 118
- Timestamp:
- 02/29/08 19:14:02 (11 months ago)
- Location:
- trunk/src/Stagehand
- Files:
-
- 1 added
- 2 modified
-
TestRunner.php (modified) (5 diffs)
-
TestRunner/Common.php (modified) (4 diffs)
-
TestRunner/Exception.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Stagehand/TestRunner.php
r117 r118 104 104 $isRecursive = false; 105 105 $color = false; 106 $isFile = false;107 106 foreach ($allOptions as $options) { 108 107 if (!count($options)) { … … 130 129 } else { 131 130 $directory = $option; 132 $isFile = true;133 131 } 134 132 } … … 137 135 include_once "Stagehand/TestRunner/$testRunnerName.php"; 138 136 $className = "Stagehand_TestRunner_$testRunnerName"; 139 $testRunner = new $className($color, $isFile, $directory, $isRecursive); 137 try { 138 $testRunner = new $className($color, $directory, $isRecursive); 139 } catch (Stagehand_TestRunner_Exception $e) { 140 echo 'ERROR: ' . $e->getMessage() . "\n"; 141 self::_displayUsage(); 142 return 1; 143 } 144 140 145 $testRunner->run(); 141 146 … … 164 169 private static function _displayUsage() 165 170 { 166 echo "Usage: {$_SERVER['SCRIPT_NAME']} [options] [ testcase]171 echo "Usage: {$_SERVER['SCRIPT_NAME']} [options] [directory or file] 167 172 168 173 Options: … … 173 178 -p <file> preload <file> as a PHP script 174 179 175 With no [ testcase], run all tests in the current directory.180 With no [directory or file], run all tests in the current directory. 176 181 "; 177 182 } -
trunk/src/Stagehand/TestRunner/Common.php
r117 r118 36 36 */ 37 37 38 require_once 'Stagehand/TestRunner/Exception.php'; 39 38 40 // {{{ Stagehand_TestRunner_Common 39 41 … … 74 76 */ 75 77 76 private $_isFile; 77 private $_directory; 78 private $_targetPath; 78 79 private $_isRecursive; 79 80 … … 89 90 /** 90 91 * @param boolean $color 91 * @param boolean $isFile 92 * @param string $directory 92 * @param string $targetPath 93 93 * @param boolean $isRecursive 94 */ 95 public function __construct($color, $isFile, $directory, $isRecursive) 96 { 97 if ($isRecursive || is_null($directory)) { 98 $directory = getcwd(); 99 } 100 101 if ($isFile) { 102 if (!preg_match("/{$this->_suffix}\.php\$/", $directory)) { 103 $directory = "$directory{$this->_suffix}.php"; 104 } 105 } 106 107 $this->_directory = $directory; 94 * @throws Stagehand_TestRunner_Exception 95 */ 96 public function __construct($color, $targetPath, $isRecursive) 97 { 98 if (is_null($targetPath)) { 99 $absoluteTargetPath = getcwd(); 100 } else { 101 if (!file_exists($targetPath)) { 102 if (preg_match("/{$this->_suffix}\.php\$/", $targetPath)) { 103 throw new Stagehand_TestRunner_Exception("The directory or file [ $targetPath ] is not found."); 104 } 105 106 $targetPath = "$targetPath{$this->_suffix}.php"; 107 } 108 109 $absoluteTargetPath = realpath($targetPath); 110 if ($absoluteTargetPath === false) { 111 throw new Stagehand_TestRunner_Exception("The directory or file [ $targetPath ] is not found."); 112 } 113 } 114 115 $this->_targetPath = $absoluteTargetPath; 108 116 $this->_color = $color; 109 $this->_isRecursive = $isRecursive;117 $this->_isRecursive = is_dir($absoluteTargetPath) && $isRecursive; 110 118 } 111 119 … … 122 130 if ($this->_isRecursive) { 123 131 $suite = $this->_createTestSuite(); 124 $directories = $this->_getDirectories($this->_ directory);132 $directories = $this->_getDirectories($this->_targetPath); 125 133 for ($i = 0, $count = count($directories); $i < $count; ++$i) { 126 134 $this->_buildTestSuite($suite, $directories[$i]); 127 135 } 128 136 } else { 129 $suite = $this->_buildTestSuite($this->_createTestSuite(), $this->_ directory);137 $suite = $this->_buildTestSuite($this->_createTestSuite(), $this->_targetPath); 130 138 } 131 139
