[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 /** 3 * PEAR_Command_Test (run-tests) 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: This source file is subject to version 3.0 of the PHP license 8 * that is available through the world-wide-web at the following URI: 9 * http://www.php.net/license/3_0.txt. If you did not receive a copy of 10 * the PHP License and are unable to obtain it through the web, please 11 * send a note to license@php.net so we can mail you a copy immediately. 12 * 13 * @category pear 14 * @package PEAR 15 * @author Stig Bakken <ssb@php.net> 16 * @author Martin Jansen <mj@php.net> 17 * @author Greg Beaver <cellog@php.net> 18 * @copyright 1997-2006 The PHP Group 19 * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 * @version CVS: $Id: Test.php,v 1.9 2006/02/03 22:28:08 cellog Exp $ 21 * @link http://pear.php.net/package/PEAR 22 * @since File available since Release 0.1 23 */ 24 25 /** 26 * base class 27 */ 28 require_once 'PEAR/Command/Common.php'; 29 30 /** 31 * PEAR commands for login/logout 32 * 33 * @category pear 34 * @package PEAR 35 * @author Stig Bakken <ssb@php.net> 36 * @author Martin Jansen <mj@php.net> 37 * @author Greg Beaver <cellog@php.net> 38 * @copyright 1997-2006 The PHP Group 39 * @license http://www.php.net/license/3_0.txt PHP License 3.0 40 * @version Release: 1.4.11 41 * @link http://pear.php.net/package/PEAR 42 * @since Class available since Release 0.1 43 */ 44 45 class PEAR_Command_Test extends PEAR_Command_Common 46 { 47 // {{{ properties 48 49 var $commands = array( 50 'run-tests' => array( 51 'summary' => 'Run Regression Tests', 52 'function' => 'doRunTests', 53 'shortcut' => 'rt', 54 'options' => array( 55 'recur' => array( 56 'shortopt' => 'r', 57 'doc' => 'Run tests in child directories, recursively. 4 dirs deep maximum', 58 ), 59 'ini' => array( 60 'shortopt' => 'i', 61 'doc' => 'actual string of settings to pass to php in format " -d setting=blah"', 62 'arg' => 'SETTINGS' 63 ), 64 'realtimelog' => array( 65 'shortopt' => 'l', 66 'doc' => 'Log test runs/results as they are run', 67 ), 68 'quiet' => array( 69 'shortopt' => 'q', 70 'doc' => 'Only display detail for failed tests', 71 ), 72 'simple' => array( 73 'shortopt' => 's', 74 'doc' => 'Display simple output for all tests', 75 ), 76 'package' => array( 77 'shortopt' => 'p', 78 'doc' => 'Treat parameters as installed packages from which to run tests', 79 ), 80 'phpunit' => array( 81 'shortopt' => 'u', 82 'doc' => 'Search parameters for AllTests.php, and use that to run phpunit-based tests', 83 ), 84 ), 85 'doc' => '[testfile|dir ...] 86 Run regression tests with PHP\'s regression testing script (run-tests.php).', 87 ), 88 ); 89 90 var $output; 91 92 // }}} 93 // {{{ constructor 94 95 /** 96 * PEAR_Command_Test constructor. 97 * 98 * @access public 99 */ 100 function PEAR_Command_Test(&$ui, &$config) 101 { 102 parent::PEAR_Command_Common($ui, $config); 103 } 104 105 // }}} 106 // {{{ doRunTests() 107 108 function doRunTests($command, $options, $params) 109 { 110 require_once 'PEAR/Common.php'; 111 require_once 'PEAR/RunTest.php'; 112 require_once 'System.php'; 113 $log = new PEAR_Common; 114 $log->ui = &$this->ui; // slightly hacky, but it will work 115 $run = new PEAR_RunTest($log, $options); 116 $tests = array(); 117 if (isset($options['recur'])) { 118 $depth = 4; 119 } else { 120 $depth = 1; 121 } 122 if (!count($params)) { 123 $params[] = '.'; 124 } 125 if (isset($options['package'])) { 126 $oldparams = $params; 127 $params = array(); 128 $reg = &$this->config->getRegistry(); 129 foreach ($oldparams as $param) { 130 $pname = $reg->parsePackageName($param, $this->config->get('default_channel')); 131 if (PEAR::isError($pname)) { 132 return $this->raiseError($pname); 133 } 134 $package = &$reg->getPackage($pname['package'], $pname['channel']); 135 if (!$package) { 136 return PEAR::raiseError('Unknown package "' . 137 $reg->parsedPackageNameToString($pname) . '"'); 138 } 139 $filelist = $package->getFilelist(); 140 foreach ($filelist as $name => $atts) { 141 if (isset($atts['role']) && $atts['role'] != 'test') { 142 continue; 143 } 144 if (isset($options['phpunit'])) { 145 if (!preg_match('/AllTests\.php$/i', $name)) { 146 continue; 147 } 148 } else { 149 if (!preg_match('/\.phpt$/', $name)) { 150 continue; 151 } 152 } 153 $params[] = $atts['installed_as']; 154 } 155 } 156 } 157 foreach ($params as $p) { 158 if (is_dir($p)) { 159 if (isset($options['phpunit'])) { 160 $dir = System::find(array($p, '-type', 'f', 161 '-maxdepth', $depth, 162 '-name', 'AllTests.php')); 163 } else { 164 $dir = System::find(array($p, '-type', 'f', 165 '-maxdepth', $depth, 166 '-name', '*.phpt')); 167 } 168 $tests = array_merge($tests, $dir); 169 } else { 170 if (isset($options['phpunit'])) { 171 if (!preg_match('/AllTests\.php$/i', $p)) { 172 continue; 173 } 174 $tests[] = $p; 175 } else { 176 if (!@file_exists($p)) { 177 if (!preg_match('/\.phpt$/', $p)) { 178 $p .= '.phpt'; 179 } 180 $dir = System::find(array(dirname($p), '-type', 'f', 181 '-maxdepth', $depth, 182 '-name', $p)); 183 $tests = array_merge($tests, $dir); 184 } else { 185 $tests[] = $p; 186 } 187 } 188 } 189 } 190 $ini_settings = ''; 191 if (isset($options['ini'])) { 192 $ini_settings .= $options['ini']; 193 } 194 if (isset($_ENV['TEST_PHP_INCLUDE_PATH'])) { 195 $ini_settings .= " -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}"; 196 } 197 if ($ini_settings) { 198 $this->ui->outputData('Using INI settings: "' . $ini_settings . '"'); 199 } 200 $skipped = $passed = $failed = array(); 201 $this->ui->outputData('Running ' . count($tests) . ' tests', $command); 202 $start = time(); 203 if (isset($options['realtimelog'])) { 204 @unlink('run-tests.log'); 205 } 206 foreach ($tests as $t) { 207 if (isset($options['realtimelog'])) { 208 $fp = @fopen('run-tests.log', 'a'); 209 if ($fp) { 210 fwrite($fp, "Running test $t..."); 211 fclose($fp); 212 } 213 } 214 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 215 $result = $run->run($t, $ini_settings); 216 PEAR::staticPopErrorHandling(); 217 if (PEAR::isError($result)) { 218 $this->ui->log(0, $result->getMessage()); 219 continue; 220 } 221 if (isset($options['realtimelog'])) { 222 $fp = @fopen('run-tests.log', 'a'); 223 if ($fp) { 224 fwrite($fp, "$result\n"); 225 fclose($fp); 226 } 227 } 228 if ($result == 'FAILED') { 229 $failed[] = $t; 230 } 231 if ($result == 'PASSED') { 232 $passed[] = $t; 233 } 234 if ($result == 'SKIPPED') { 235 $skipped[] = $t; 236 } 237 } 238 $total = date('i:s', time() - $start); 239 if (count($failed)) { 240 $output = "TOTAL TIME: $total\n"; 241 $output .= count($passed) . " PASSED TESTS\n"; 242 $output .= count($skipped) . " SKIPPED TESTS\n"; 243 $output .= count($failed) . " FAILED TESTS:\n"; 244 foreach ($failed as $failure) { 245 $output .= $failure . "\n"; 246 } 247 if (isset($options['realtimelog'])) { 248 $fp = @fopen('run-tests.log', 'a'); 249 } else { 250 $fp = @fopen('run-tests.log', 'w'); 251 } 252 if ($fp) { 253 fwrite($fp, $output, strlen($output)); 254 fclose($fp); 255 $this->ui->outputData('wrote log to "' . realpath('run-tests.log') . '"', $command); 256 } 257 } elseif (@file_exists('run-tests.log') && !@is_dir('run-tests.log')) { 258 @unlink('run-tests.log'); 259 } 260 $this->ui->outputData('TOTAL TIME: ' . $total); 261 $this->ui->outputData(count($passed) . ' PASSED TESTS', $command); 262 $this->ui->outputData(count($skipped) . ' SKIPPED TESTS', $command); 263 if (count($failed)) { 264 $this->ui->outputData(count($failed) . ' FAILED TESTS:', $command); 265 foreach ($failed as $failure) { 266 $this->ui->outputData($failure, $command); 267 } 268 } 269 270 return true; 271 } 272 // }}} 273 } 274 275 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |