Changeset 133

Show
Ignore:
Timestamp:
03/04/08 21:55:39 (10 months ago)
Author:
iteman
Message:

- Added a feature so that one or more directories to be watched for changes can specify by the -w option. (Ticket #13)

Location:
trunk/src/Stagehand
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Stagehand/TestRunner.php

    r128 r133  
    143143  -c        color the result of a test runner run 
    144144  -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 
    146147 
    147148With no [directory or file], run all tests in the current directory. 
     
    169170 
    170171    /** 
    171      * Watches for changes in the directory and runs tests in the directory 
    172      * 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. 
    173174     * 
    174175     * @param stdClass $config 
     
    177178    private static function _monitorAlteration($config) 
    178179    { 
    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            } 
    186195        } 
    187196 
     
    223232        $options[] = $config->directory; 
    224233 
    225         $monitor = new Stagehand_TestRunner_AlterationMonitor($config->directory, 
     234        $monitor = new Stagehand_TestRunner_AlterationMonitor($directories, 
    226235                                                              "$command " . implode(' ', $options) 
    227236                                                              ); 
     
    242251        $argv = Console_Getopt::readPHPArgv(); 
    243252        array_shift($argv); 
    244         $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:a'); 
     253        $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:aw:'); 
    245254        if (PEAR::isError($allOptions)) { 
    246255            throw new Stagehand_TestRunner_Exception('ERROR: ' . preg_replace('/^Console_Getopt: /', '', $allOptions->getMessage())); 
     
    253262        $preload = false; 
    254263        $preloadFile = null; 
     264        $useTargetDirectories = false; 
     265        $targetDirectories = array(); 
    255266        foreach ($allOptions as $options) { 
    256267            if (!count($options)) { 
     
    282293                        $enableAutotest = true; 
    283294                        break; 
     295                    case 'w': 
     296                        $useTargetDirectories = true; 
     297                        $targetDirectories = explode(',', $option[1]); 
     298                        break; 
    284299                    } 
    285300                } else { 
     
    294309                             'enableAutotest' => $enableAutotest, 
    295310                             'preload' => $preload, 
    296                              'preloadFile' => $preloadFile 
     311                             'preloadFile' => $preloadFile, 
     312                             'useTargetDirectories' => $useTargetDirectories, 
     313                             'targetDirectories' => $targetDirectories 
    297314                             ); 
    298315    } 
  • trunk/src/Stagehand/TestRunner/AlterationMonitor.php

    r132 r133  
    7777     */ 
    7878 
    79     private $_directory; 
     79    private $_directories; 
    8080    private $_command; 
    8181    private $_currentElements; 
     
    101101 
    102102    /** 
    103      * Sets a directory and command string to the properties. 
     103     * Sets one or more target directories and command string to the properties. 
    104104     * 
    105      * @param string $directory 
     105     * @param array  $directories 
    106106     * @param string $command 
    107107     */ 
    108     public function __construct($directory, $command) 
    109     { 
    110         $this->_directory = $directory; 
     108    public function __construct($directories, $command) 
     109    { 
     110        $this->_directories = $directories; 
    111111        $this->_command = $command; 
    112112    } 
     
    116116 
    117117    /** 
    118      * Watches for changes in the directory and runs tests in the directory 
    119      * 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. 
    120120     */ 
    121121    public function monitor() 
     
    124124 
    125125        while (true) { 
    126             print " 
    127 Waiting for changes in the directory [ {$this->_directory} ] ... 
    128 "; 
     126            print ' 
     127Waiting for changes in the following directories: 
     128  - ' . implode("\n  - ", $this->_directories) . "\n"; 
    129129 
    130130            $this->_waitForChanges(); 
     
    165165 
    166166    /** 
    167      * Watches for changes in the directory and returns immediately when 
     167     * Watches for changes in the target directories and returns immediately when 
    168168     * changes are detected. 
    169169     */ 
     
    180180                $this->_currentElements = array(); 
    181181                $startTime = time(); 
    182                 $this->_collectElements($this->_directory); 
     182                foreach ($this->_directories as $directory) { 
     183                    $this->_collectElements($directory); 
     184                } 
    183185                $endTime = time(); 
    184186                $elapsedTime = $endTime - $startTime; 
     
    208210 
    209211    /** 
    210      * Collects all files and directories in the directory and detects any 
     212     * Collects all files and directories in a target directory and detects any 
    211213     * changes of a file or directory immediately. 
    212214     *