Changeset 118

Show
Ignore:
Timestamp:
02/29/08 19:14:02 (11 months ago)
Author:
iteman
Message:

- Added support for specifying a target directory.

Location:
trunk/src/Stagehand
Files:
1 added
2 modified

Legend:

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

    r117 r118  
    104104        $isRecursive = false; 
    105105        $color = false; 
    106         $isFile = false; 
    107106        foreach ($allOptions as $options) { 
    108107            if (!count($options)) { 
     
    130129                } else { 
    131130                    $directory = $option; 
    132                     $isFile = true; 
    133131                } 
    134132            } 
     
    137135        include_once "Stagehand/TestRunner/$testRunnerName.php"; 
    138136        $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 
    140145        $testRunner->run(); 
    141146 
     
    164169    private static function _displayUsage() 
    165170    { 
    166         echo "Usage: {$_SERVER['SCRIPT_NAME']} [options] [testcase] 
     171        echo "Usage: {$_SERVER['SCRIPT_NAME']} [options] [directory or file] 
    167172 
    168173Options: 
     
    173178  -p <file> preload <file> as a PHP script 
    174179 
    175 With no [testcase], run all tests in the current directory. 
     180With no [directory or file], run all tests in the current directory. 
    176181"; 
    177182    } 
  • trunk/src/Stagehand/TestRunner/Common.php

    r117 r118  
    3636 */ 
    3737 
     38require_once 'Stagehand/TestRunner/Exception.php'; 
     39 
    3840// {{{ Stagehand_TestRunner_Common 
    3941 
     
    7476     */ 
    7577 
    76     private $_isFile; 
    77     private $_directory; 
     78    private $_targetPath; 
    7879    private $_isRecursive; 
    7980 
     
    8990    /** 
    9091     * @param boolean $color 
    91      * @param boolean $isFile 
    92      * @param string  $directory 
     92     * @param string  $targetPath 
    9393     * @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; 
    108116        $this->_color = $color; 
    109         $this->_isRecursive = $isRecursive; 
     117        $this->_isRecursive = is_dir($absoluteTargetPath) && $isRecursive; 
    110118    } 
    111119 
     
    122130        if ($this->_isRecursive) { 
    123131            $suite = $this->_createTestSuite(); 
    124             $directories = $this->_getDirectories($this->_directory); 
     132            $directories = $this->_getDirectories($this->_targetPath); 
    125133            for ($i = 0, $count = count($directories); $i < $count; ++$i) { 
    126134                $this->_buildTestSuite($suite, $directories[$i]); 
    127135            } 
    128136        } else { 
    129             $suite = $this->_buildTestSuite($this->_createTestSuite(), $this->_directory); 
     137            $suite = $this->_buildTestSuite($this->_createTestSuite(), $this->_targetPath); 
    130138        } 
    131139