run-tests.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,986 行 · 第 1/4 页
PHP
1,986 行
<?php/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Ilia Alshanetsky <iliaa@php.net> | | Preston L. Bannister <pbannister@php.net> | | Marcus Boerger <helly@php.net> | | Derick Rethans <derick@php.net> | | Sander Roobol <sander@php.net> | | (based on version by: Stig Bakken <ssb@php.net>) | | (based on the PHP 3 test framework by Rasmus Lerdorf) | +----------------------------------------------------------------------+ *//* $Id: run-tests.php,v 1.226.2.37.2.35 2007/09/14 15:28:03 nlopess Exp $ *//* Sanity check to ensure that pcre extension needed by this script is available. * In the event it is not, print a nice error message indicating that this script will * not run without it. */if (!extension_loaded("pcre")) { echo <<<NO_PCRE_ERROR+-----------------------------------------------------------+| ! ERROR ! || The test-suite requires that you have pcre extension || enabled. To enable this extension either compile your PHP || with --with-pcre-regex or if you've compiled pcre as a || shared module load it via php.ini. |+-----------------------------------------------------------+NO_PCRE_ERROR;exit;}if (!function_exists("proc_open")) { echo <<<NO_PROC_OPEN_ERROR+-----------------------------------------------------------+| ! ERROR ! || The test-suite requires that proc_open() is available. || Please check if you disabled it in php.ini. |+-----------------------------------------------------------+NO_PROC_OPEN_ERROR;exit;}// store current directory$CUR_DIR = getcwd();// change into the PHP source directory.if (getenv('TEST_PHP_SRCDIR')) { @chdir(getenv('TEST_PHP_SRCDIR'));}// Delete some security related environment variablesputenv('SSH_CLIENT=deleted');putenv('SSH_AUTH_SOCK=deleted');putenv('SSH_TTY=deleted');putenv('SSH_CONNECTION=deleted');$cwd = getcwd();set_time_limit(0);// delete as much output buffers as possiblewhile(@ob_end_clean());if (ob_get_level()) echo "Not all buffers were deleted.\n";error_reporting(E_ALL);ini_set('magic_quotes_runtime',0); // this would break tests by modifying EXPECT sectionsif (ini_get('safe_mode')) { echo <<< SAFE_MODE_WARNING+-----------------------------------------------------------+| ! WARNING ! || You are running the test-suite with "safe_mode" ENABLED ! || || Chances are high that no test will work at all, || depending on how you configured "safe_mode" ! |+-----------------------------------------------------------+SAFE_MODE_WARNING;}$environment = isset($_ENV) ? $_ENV : array();// Don't ever guess at the PHP executable location.// Require the explicit specification.// Otherwise we could end up testing the wrong file!if (getenv('TEST_PHP_EXECUTABLE')) { $php = getenv('TEST_PHP_EXECUTABLE'); if ($php=='auto') { $php = $cwd.'/sapi/cli/php'; putenv("TEST_PHP_EXECUTABLE=$php"); } $environment['TEST_PHP_EXECUTABLE'] = $php;}if (getenv('TEST_PHP_CGI_EXECUTABLE')) { $php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE'); if ($php_cgi=='auto') { $php_cgi = $cwd.'/sapi/cgi/php-cgi'; putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi"); } $environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;}if ($argc !=2 || ($argv[1] != '-h' && $argv[1] != '-help' && $argv != '--help')){ if (empty($php) || !file_exists($php)) { error("environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!"); } if (function_exists('is_executable') && !@is_executable($php)) { error("invalid PHP executable specified by TEST_PHP_EXECUTABLE = " . $php); }}if (getenv('TEST_PHP_LOG_FORMAT')) { $log_format = strtoupper(getenv('TEST_PHP_LOG_FORMAT'));} else { $log_format = 'LEOD';}// Check whether a detailed log is wanted.if (getenv('TEST_PHP_DETAILED')) { $DETAILED = getenv('TEST_PHP_DETAILED');} else { $DETAILED = 0;}// Check whether user test dirs are requested.if (getenv('TEST_PHP_USER')) { $user_tests = explode (',', getenv('TEST_PHP_USER'));} else { $user_tests = array();}$exts_to_test = array();$ini_overwrites = array( 'output_handler=', 'open_basedir=', 'safe_mode=0', 'disable_functions=', 'output_buffering=Off', 'error_reporting=8191', 'display_errors=1', 'display_startup_errors=1', 'log_errors=0', 'html_errors=0', 'track_errors=1', 'report_memleaks=1', 'report_zend_debug=0', 'docref_root=', 'docref_ext=.html', 'error_prepend_string=', 'error_append_string=', 'auto_prepend_file=', 'auto_append_file=', 'magic_quotes_runtime=0', );function write_information($show_html){ global $cwd, $php, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test; // Get info from php $info_file = realpath(dirname(__FILE__)) . '/run-test-info.php'; @unlink($info_file); $php_info = '<?php echo "PHP_SAPI : " . PHP_SAPI . "PHP_VERSION : " . phpversion() . "ZEND_VERSION: " . zend_version() . "PHP_OS : " . PHP_OS . " - " . php_uname() . "INI actual : " . realpath(get_cfg_var("cfg_file_path")) . "More .INIs : " . (function_exists(\'php_ini_scanned_files\') ? str_replace("\n","", php_ini_scanned_files()) : "** not determined **"); ?>'; save_text($info_file, $php_info); $info_params = array(); settings2array($ini_overwrites,$info_params); settings2params($info_params); $php_info = `$php $pass_options $info_params "$info_file"`; @unlink($info_file); define('TESTED_PHP_VERSION', `$php -r "echo PHP_VERSION;"`); // load list of enabled extensions save_text($info_file, '<?php echo join(",",get_loaded_extensions()); ?>'); $exts_to_test = explode(',',`$php $pass_options $info_params "$info_file"`); // check for extensions that need special handling and regenerate $info_params_ex = array( 'session' => array('session.auto_start=0'), 'tidy' => array('tidy.clean_output=0'), 'zlib' => array('zlib.output_compression=Off'), 'xdebug' => array('xdebug.default_enable=0'), ); foreach($info_params_ex as $ext => $ini_overwrites_ex) { if (in_array($ext, $exts_to_test)) { $ini_overwrites = array_merge($ini_overwrites, $ini_overwrites_ex); } } @unlink($info_file); // Write test context information. echo "=====================================================================CWD : $cwdPHP : $php $php_infoExtra dirs : "; foreach ($user_tests as $test_dir) { echo "{$test_dir}\n "; } echo "=====================================================================";}// Determine the tests to be run.$test_files = array();$redir_tests = array();$test_results = array();$PHP_FAILED_TESTS = array('BORKED' => array(), 'FAILED' => array(), 'WARNED' => array(), 'LEAKED' => array());// If parameters given assume they represent selected tests to run.$failed_tests_file= false;$pass_option_n = false;$pass_options = '';$compression = 0;$output_file = $CUR_DIR . '/php_test_results_' . @date('Ymd_Hi') . '.txt';if ($compression) { $output_file = 'compress.zlib://' . $output_file . '.gz';}$just_save_results = false;$leak_check = false;$html_output = false;$html_file = null;$temp_source = null;$temp_target = null;$temp_urlbase = null;$conf_passed = null;$no_clean = false;$cfgtypes = array('show', 'keep');$cfgfiles = array('skip', 'php', 'clean');$cfg = array();foreach($cfgtypes as $type) { $cfg[$type] = array(); foreach($cfgfiles as $file) { $cfg[$type][$file] = false; }}if (getenv('TEST_PHP_ARGS')){ if (!isset($argc) || !$argc || !isset($argv)) { $argv = array(__FILE__); } $argv = array_merge($argv, split(' ', getenv('TEST_PHP_ARGS'))); $argc = count($argv);}if (isset($argc) && $argc > 1) { for ($i=1; $i<$argc; $i++) { $is_switch = false; $switch = substr($argv[$i],1,1); $repeat = substr($argv[$i],0,1) == '-'; while ($repeat) { $repeat = false; if (!$is_switch) { $switch = substr($argv[$i],1,1); } $is_switch = true; switch($switch) { case 'r': case 'l': $test_list = @file($argv[++$i]); if ($test_list) { foreach($test_list as $test) { $matches = array(); if (preg_match('/^#.*\[(.*)\]\:\s+(.*)$/', $test, $matches)) { $redir_tests[] = array($matches[1], $matches[2]); } else if (strlen($test)) { $test_files[] = trim($test); } } } if ($switch != 'l') { break; } $i--; // break left intentionally case 'w': $failed_tests_file = fopen($argv[++$i], 'w+t'); break; case 'a': $failed_tests_file = fopen($argv[++$i], 'a+t'); break; case 'c': $conf_passed = $argv[++$i]; break; case 'd': $ini_overwrites[] = $argv[++$i]; break; //case 'h' case '--keep-all': foreach($cfgfiles as $file) { $cfg['keep'][$file] = true; } break; case '--keep-skip': $cfg['keep']['skip'] = true; break; case '--keep-php': $cfg['keep']['php'] = true; break; case '--keep-clean': $cfg['keep']['clean'] = true; break; //case 'l' case 'm': $leak_check = true; break; case 'n': if (!$pass_option_n) { $pass_options .= ' -n'; } $pass_option_n = true; break; case 'N': // this is always native break; case '--no-clean': $no_clean = true; break; case 'q': putenv('NO_INTERACTION=1'); break; //case 'r' case 's': $output_file = $argv[++$i]; $just_save_results = true; break; case '--show-all': foreach($cfgfiles as $file) { $cfg['show'][$file] = true; } break; case '--show-skip': $cfg['show']['skip'] = true; break; case '--show-php': $cfg['show']['php'] = true; break; case '--show-clean': $cfg['show']['clean'] = true; break; case '--temp-source': $temp_source = $argv[++$i]; break; case '--temp-target': $temp_target = $argv[++$i]; if ($temp_urlbase) { $temp_urlbase = $temp_target; } break; case '--temp-urlbase': $temp_urlbase = $argv[++$i]; break; case 'v': case '--verbose': $DETAILED = true; break; //case 'w' case '-': // repeat check with full switch $switch = $argv[$i]; if ($switch != '-') { $repeat = true; } break; case '--html': $html_file = @fopen($argv[++$i], 'wt'); $html_output = is_resource($html_file); break; case '--version': echo '$Revision: 1.226.2.37.2.35 $'."\n"; exit(1); case 'u': case 'U': // Allow using u or U for forward compatibility break; default: echo "Illegal switch '$switch' specified!\n"; case 'h': case '-help': case '--help': echo <<<HELPSynopsis: php run-tests.php [options] [files] [directories]Options: -l <file> Read the testfiles to be executed from <file>. After the test has finished all failed tests are written to the same <file>. If the list is empty and no further test is specified then all tests are executed (same as: -r <file> -w <file>). -r <file> Read the testfiles to be executed from <file>. -w <file> Write a list of all failed tests to <file>. -a <file> Same as -w but append rather then truncating <file>. -c <file> Look for php.ini in directory <file> or use <file> as ini. -n Pass -n option to the php binary (Do not use a php.ini). -d foo=bar Pass -d option to the php binary (Define INI entry foo with value 'bar'). -m Test for memory leaks with Valgrind. -N Always set (Test with unicode_semantics set off in PHP 6). -s <file> Write output to <file>. -q Quiet, no user interaction (same as environment NO_INTERACTION). --verbose -v Verbose mode. --help -h This Help. --html <file> Generate HTML output. --temp-source <sdir> --temp-target <tdir> [--temp-urlbase <url>] Write temporary files to <tdir> by replacing <sdir> from the filenames to generate with <tdir>. If --html is being used and <url> given then the generated links are relative and prefixed with the given url. In general you want to make <sdir> the path to your source files and <tdir> some pach in your web page hierarchy with <url> pointing to <tdir>. --keep-[all|php|skip|clean] Do not delete 'all' files, 'php' test file, 'skip' or 'clean' file. --show-[all|php|skip|clean] Show 'all' files, 'php' test file, 'skip' or 'clean' file. --no-clean Do not execute clean section if any.HELP; exit(1); } } if (!$is_switch) { $testfile = realpath($argv[$i]); if (!$testfile && strpos($argv[$i], '*') !== false && function_exists('glob')) { if (preg_match("/\.phpt$/", $argv[$i])) { $pattern_match = glob($argv[$i]); } else if (preg_match("/\*$/", $argv[$i])) { $pattern_match = glob($argv[$i] . '.phpt'); } else { die("bogus test name " . $argv[$i] . "\n"); } if (is_array($pattern_match)) { $test_files = array_merge($test_files, $pattern_match); } } else if (is_dir($testfile)) { find_files($testfile); } else if (preg_match("/\.phpt$/", $testfile)) { $test_files[] = $testfile; } else { die("bogus test name " . $argv[$i] . "\n"); } } } if (strlen($conf_passed))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?