Changeset 133
- Timestamp:
- 03/04/08 21:55:39 (10 months ago)
- Location:
- trunk/src/Stagehand
- Files:
-
- 2 modified
-
TestRunner.php (modified) (8 diffs)
-
TestRunner/AlterationMonitor.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Stagehand/TestRunner.php
r128 r133 143 143 -c color the result of a test runner run 144 144 -p <file> preload <file> as a PHP script 145 -a watch for changes in a specified directory and run tests in the directory recursively when changes are detected (autotest) 145 -a watch for changes in one or more directories and run tests in the test directory recursively when changes are detected (autotest) 146 -w <directory1,directory2,...> specify one or more directories to be watched for changes 146 147 147 148 With no [directory or file], run all tests in the current directory. … … 169 170 170 171 /** 171 * Watches for changes in the directory and runs tests in the directory172 * recursively when changes are detected.172 * Watches for changes in one or more target directories and runs tests in 173 * the test directory recursively when changes are detected. 173 174 * 174 175 * @param stdClass $config … … 177 178 private static function _monitorAlteration($config) 178 179 { 179 if (!is_dir($config->directory)) { 180 throw new Stagehand_TestRunner_Exception("ERROR: The specified path [ {$config->directory} ] is not found or not a directory."); 181 } 182 183 $config->directory = realpath($config->directory); 184 if ($config->directory === false) { 185 throw new Stagehand_TestRunner_Exception("ERROR: Cannnot get the absolute path of the specified directory [ {$config->directory} ]. Make sure all elements of the absolute path have valid permissions."); 180 if (!count($config->targetDirectories)) { 181 $directories = (array)$config->directory; 182 } else { 183 $directories = $config->targetDirectories; 184 } 185 186 for ($i = 0, $count = count($directories); $i < $count; ++$i) { 187 if (!is_dir($directories[$i])) { 188 throw new Stagehand_TestRunner_Exception("ERROR: A specified path [ {$directories[$i]} ] is not found or not a directory."); 189 } 190 191 $directories[$i] = realpath($directories[$i]); 192 if ($directories[$i] === false) { 193 throw new Stagehand_TestRunner_Exception("ERROR: Cannnot get the absolute path of a specified directory [ {$directories[$i]} ]. Make sure all elements of the absolute path have valid permissions."); 194 } 186 195 } 187 196 … … 223 232 $options[] = $config->directory; 224 233 225 $monitor = new Stagehand_TestRunner_AlterationMonitor($ config->directory,234 $monitor = new Stagehand_TestRunner_AlterationMonitor($directories, 226 235 "$command " . implode(' ', $options) 227 236 ); … … 242 251 $argv = Console_Getopt::readPHPArgv(); 243 252 array_shift($argv); 244 $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:a ');253 $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:aw:'); 245 254 if (PEAR::isError($allOptions)) { 246 255 throw new Stagehand_TestRunner_Exception('ERROR: ' . preg_replace('/^Console_Getopt: /', '', $allOptions->getMessage())); … … 253 262 $preload = false; 254 263 $preloadFile = null; 264 $useTargetDirectories = false; 265 $targetDirectories = array(); 255 266 foreach ($allOptions as $options) { 256 267 if (!count($options)) { … … 282 293 $enableAutotest = true; 283 294 break; 295 case 'w': 296 $useTargetDirectories = true; 297 $targetDirectories = explode(',', $option[1]); 298 break; 284 299 } 285 300 } else { … … 294 309 'enableAutotest' => $enableAutotest, 295 310 'preload' => $preload, 296 'preloadFile' => $preloadFile 311 'preloadFile' => $preloadFile, 312 'useTargetDirectories' => $useTargetDirectories, 313 'targetDirectories' => $targetDirectories 297 314 ); 298 315 } -
trunk/src/Stagehand/TestRunner/AlterationMonitor.php
r132 r133 77 77 */ 78 78 79 private $_director y;79 private $_directories; 80 80 private $_command; 81 81 private $_currentElements; … … 101 101 102 102 /** 103 * Sets a directoryand command string to the properties.103 * Sets one or more target directories and command string to the properties. 104 104 * 105 * @param string $directory105 * @param array $directories 106 106 * @param string $command 107 107 */ 108 public function __construct($director y, $command)109 { 110 $this->_director y = $directory;108 public function __construct($directories, $command) 109 { 110 $this->_directories = $directories; 111 111 $this->_command = $command; 112 112 } … … 116 116 117 117 /** 118 * Watches for changes in the directory and runs tests in the directory119 * recursively when changes are detected.118 * Watches for changes in the target directories and runs tests in the test 119 * directory recursively when changes are detected. 120 120 */ 121 121 public function monitor() … … 124 124 125 125 while (true) { 126 print "127 Waiting for changes in the directory [ {$this->_directory} ] ...128 ";126 print ' 127 Waiting for changes in the following directories: 128 - ' . implode("\n - ", $this->_directories) . "\n"; 129 129 130 130 $this->_waitForChanges(); … … 165 165 166 166 /** 167 * Watches for changes in the directoryand returns immediately when167 * Watches for changes in the target directories and returns immediately when 168 168 * changes are detected. 169 169 */ … … 180 180 $this->_currentElements = array(); 181 181 $startTime = time(); 182 $this->_collectElements($this->_directory); 182 foreach ($this->_directories as $directory) { 183 $this->_collectElements($directory); 184 } 183 185 $endTime = time(); 184 186 $elapsedTime = $endTime - $startTime; … … 208 210 209 211 /** 210 * Collects all files and directories in thedirectory and detects any212 * Collects all files and directories in a target directory and detects any 211 213 * changes of a file or directory immediately. 212 214 *
