cvs: pear-core / package-PEAR.xml package2.xml /PEAR RunTest.php /PEAR/Command Test.php Test.xml /tests/PEAR_RunTest test_bug10092.phpt
test_bug10092post.phpt
| From: | Greg Beaver | Date: | Fri, 16 Feb 2007 05:36:58 +0000 |
| Subject: | cvs: pear-core / package-PEAR.xml package2.xml /PEAR RunTest.php /PEAR/Command Test.php Test.xml /tests/PEAR_RunTest test_bug10092.phpt test_bug10092post.phpt |
||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-5422@lists.php.net to get a copy of this message | ||
cellog Fri Feb 16 05:36:58 2007 UTC
Added files:
/pear-core/tests/PEAR_RunTest test_bug10092.phpt
test_bug10092post.phpt
Modified files:
/pear-core package-PEAR.xml package2.xml
/pear-core/PEAR RunTest.php
/pear-core/PEAR/Command Test.php Test.xml
Log:
* fix Bug #10092: run-tests does not support --INI-- or --POST--
http://cvs.php.net/viewvc.cgi/pear-core/package-PEAR.xml?r1=1.432&r2=1.433&diff_format=u Index: pear-core/package-PEAR.xml diff -u pear-core/package-PEAR.xml:1.432 pear-core/package-PEAR.xml:1.433 --- pear-core/package-PEAR.xml:1.432 Fri Feb 16 04:00:37 2007 +++ pear-core/package-PEAR.xml Fri Feb 16 05:36:57 2007 @@ -90,6 +90,7 @@ * fix Bug #9971: Improve run-tests diffs of EXPECTF sections * fix Bug #10012: pear package: tokenizer should be enabled * fix Bug #10081: installer dies on uninstall (recursion too deep) + * fix Bug #10092: run-tests does not support --INI-- or --POST-- * fix Bug #10108: update-error with backups from test-Folder * fix Bug #10109: on failed upgrade, .bak files everywhere </notes> http://cvs.php.net/viewvc.cgi/pear-core/package2.xml?r1=1.326&r2=1.327&diff_format=u Index: pear-core/package2.xml diff -u pear-core/package2.xml:1.326 pear-core/package2.xml:1.327 --- pear-core/package2.xml:1.326 Fri Feb 16 04:00:37 2007 +++ pear-core/package2.xml Fri Feb 16 05:36:57 2007 @@ -99,6 +99,7 @@ * fix Bug #9971: Improve run-tests diffs of EXPECTF sections * fix Bug #10012: pear package: tokenizer should be enabled * fix Bug #10081: installer dies on uninstall (recursion too deep) + * fix Bug #10092: run-tests does not support --INI-- or --POST-- * fix Bug #10108: update-error with backups from test-Folder * fix Bug #10109: on failed upgrade, .bak files everywhere </notes> http://cvs.php.net/viewvc.cgi/pear-core/PEAR/RunTest.php?r1=1.24&r2=1.25&diff_format=u Index: pear-core/PEAR/RunTest.php diff -u pear-core/PEAR/RunTest.php:1.24 pear-core/PEAR/RunTest.php:1.25 --- pear-core/PEAR/RunTest.php:1.24 Wed Feb 14 06:10:16 2007 +++ pear-core/PEAR/RunTest.php Fri Feb 16 05:36:57 2007 @@ -16,7 +16,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: RunTest.php,v 1.24 2007/02/14 06:10:16 cellog Exp $ + * @version CVS: $Id: RunTest.php,v 1.25 2007/02/16 05:36:57 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.3.3 */ @@ -52,6 +52,28 @@ { var $_logger; var $_options; + var $ini_overwrites = array( + 'output_handler=', + 'open_basedir=', + 'safe_mode=0', + 'disable_functions=', + 'output_buffering=Off', + 'error_reporting=8191', + 'display_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', + ); + /** * An object that supports the PEAR_Common->log() signature, or null @@ -67,6 +89,93 @@ $this->_options = $options; } + /** + * Taken from php-src/run-tests.php + * + * @param string $commandline command name + * @param array $env + * @param string $stdin standard input to pass to the command + * @return unknown + */ + function system_with_timeout($commandline, $env = null, $stdin = null) + { + $data = ''; + + if (version_compare(phpversion(), '5.0.0', '<')) { + $proc = proc_open($commandline, array( + 0 => array('pipe', 'r'), + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w') + ), $pipes); + } else { + $proc = proc_open($commandline, array( + 0 => array('pipe', 'r'), + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w') + ), $pipes, null, $env, array("suppress_errors" => true)); + } + + if (!$proc) { + return false; + } + + if (is_string($stdin)) { + fwrite($pipes[0], $stdin); + } + fclose($pipes[0]); + + while (true) { + /* hide errors from interrupted syscalls */ + $r = $pipes; + $w = null; + $e = null; + $n = @stream_select($r, $w, $e, 60); + + if ($n === 0) { + /* timed out */ + $data .= "\n ** ERROR: process timed out **\n"; + proc_terminate($proc); + return array(1234567890, $data); + } else if ($n > 0) { + $line = fread($pipes[1], 8192); + if (strlen($line) == 0) { + /* EOF */ + break; + } + $data .= $line; + } + } + $stat = proc_get_status($proc); + if ($stat['signaled']) { + $data .= "\nTermsig=".$stat['stopsig']; + } + $code = proc_close($proc); + return array($stat['exitcode'], $data); + } + + function settings2array($settings, $ini_settings) + { + foreach ($settings as $setting) { + if (strpos($setting, '=')!==false) { + $setting = explode("=", $setting, 2); + $name = trim(strtolower($setting[0])); + $value = trim($setting[1]); + $ini_settings[$name] = $value; + } + } + return $ini_settings; + } + + function settings2params($ini_settings) + { + $settings = ''; + foreach ($ini_settings as $name => $value) { + $value = addslashes($value); + $settings .= " -d \"$name=$value\""; + } + return $settings; + } + // // Run an individual test case. // @@ -88,8 +197,10 @@ chdir($savedir); return 'PASSED'; // we have no way of knowing this information so assume passing } - //var_dump($php);exit; - global $log_format, $info_params, $ini_overwrites; + $pass_options = ''; + if (!empty($this->_options['ini'])) { + $pass_options = $this->_options['ini']; + } $info_params = ''; $log_format = 'LEOD'; @@ -99,6 +210,7 @@ 'TEST' => '(unnamed test)', 'SKIPIF' => '', 'GET' => '', + 'POST' => '', 'ARGS' => '', 'INI' => '', 'CLEAN' => '', @@ -114,20 +226,42 @@ $line = fgets($fp); // Match the beginning of a section. - if (ereg('^--([A-Z]+)--',$line,$r)) { + if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { $section = $r[1]; $section_text[$section] = ''; continue; } elseif (empty($section)) { fclose($fp); return PEAR::raiseError("Invalid sections formats in test file: $file"); - } + } // Add to the section text. $section_text[$section] .= $line; } fclose($fp); + $ini_settings = array(); + $ini_settings = $this->settings2array($this->ini_overwrites, $ini_settings); + if ($section_text['INI']) { + if (strpos($section_text['INI'], '{PWD}') !== false) { + $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); + } + $ini_settings = $this->settings2array(preg_split( "/[\n\r]+/", + $section_text['INI']), $ini_settings); + } + $ini_settings = $this->settings2params($ini_settings); + if (!empty($section_text['GET']) || !empty($section_text['POST'])) { + if (empty($this->_options['cgi'])) { + if (!isset($this->_options['quiet'])) { + $this->_logger->log(0, "SKIP $tested (reason: --cgi option needed for this test, type 'pear help run-tests')"); + } + if (isset($this->_options['tapoutput'])) { + return array('ok', ' # skip --cgi option needed for this test, "pear help run-tests" for info'); + } + return 'SKIPPED'; + } + $php = $this->_options['cgi']; + } $shortname = str_replace($cwd . DIRECTORY_SEPARATOR, '', $file); if (!isset($this->_options['simple'])) { $tested = trim($section_text['TEST']) . "[$shortname]"; @@ -135,119 +269,171 @@ $tested = trim($section_text['TEST']) . ' '; } - $tmp = realpath(dirname($file)); - $tmp_skipif = $tmp . uniqid('/phpt.'); - $tmp_file = ereg_replace('\.phpt$','.php',$file); - $tmp_post = $tmp . uniqid('/phpt.'); - - if (file_exists($tmp_skipif)) { - unlink($tmp_skipif); - } - if (file_exists($tmp_file)) { - unlink($tmp_file); - } - if (file_exists($tmp_post)) { - unlink($tmp_post); - } - - // unlink old test results - if (file_exists(ereg_replace('\.phpt$','.diff',$file))) { - unlink(ereg_replace('\.phpt$','.diff',$file)); - } - if (file_exists(ereg_replace('\.phpt$','.log',$file))) { - unlink(ereg_replace('\.phpt$','.log',$file)); - } - if (file_exists(ereg_replace('\.phpt$','.exp',$file))) { - unlink(ereg_replace('\.phpt$','.exp',$file)); - } - if (file_exists(ereg_replace('\.phpt$','.out',$file))) { - unlink(ereg_replace('\.phpt$','.out',$file)); - } + $temp_dir = $test_dir = realpath(dirname($file)); + $main_file_name = basename($file,'phpt'); + $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'diff'; + $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'log'; + $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'exp'; + $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out'; + $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem'; + $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; + $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; + $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; + $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; + $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php'; + $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php'; + $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); + + // unlink old test results + @unlink($diff_filename); + @unlink($log_filename); + @unlink($exp_filename); + @unlink($output_filename); + @unlink($memcheck_filename); + @unlink($temp_file); + @unlink($test_file); + @unlink($temp_skipif); + @unlink($test_skipif); + @unlink($tmp_post); + @unlink($temp_clean); + @unlink($test_clean); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { - $this->save_text($tmp_skipif, $section_text['SKIPIF']); - //$extra = substr(PHP_OS, 0, 3) !== "WIN" ? - // "unset REQUEST_METHOD;": ""; - - //$output = `$extra $php $info_params -f $tmp_skipif`; - $output = `$php $info_params -f $tmp_skipif`; - unlink($tmp_skipif); - if (eregi("^skip", trim($output))) { + $this->save_text($temp_skipif, $section_text['SKIPIF']); + $output = $this->system_with_timeout("$php $info_params -f $temp_skipif"); + $output = $output[1]; + unlink($temp_skipif); + if (!strncasecmp('skip', ltrim($output), 4)) { $skipreason = "SKIP $tested"; - $reason = (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; - if ($reason) { - $skipreason .= " (reason: $reason)"; + if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) { + $skipreason .= '(reason: ' . $m[1] . ')'; } if (!isset($this->_options['quiet'])) { $this->_logger->log(0, $skipreason); } - if (isset($old_php)) { - $php = $old_php; - } if (isset($this->_options['tapoutput'])) { return array('ok', ' # skip ' . $reason); } return 'SKIPPED'; } - if (eregi("^info", trim($output))) { - $reason = (ereg("^info[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; - if ($reason) { - $info = " (info: $reason)"; + if (!strncasecmp('info', ltrim($output), 4)) { + if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) { + $info = " (info: $m[1])"; } } - if (eregi("^warn", trim($output))) { - $reason = (ereg("^warn[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; - if ($reason) { + if (!strncasecmp('warn', ltrim($output), 4)) { + if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ - $info = " (warn: $reason)"; + $info = " (warn: $m[1])"; } } } } // We've satisfied the preconditions - run the test! - $this->save_text($tmp_file,$section_text['FILE']); + $this->save_text($temp_file,$section_text['FILE']); $args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : ''; - $cmd = "$php$ini_settings -f $tmp_file$args 2>&1"; + $cmd = "$php$ini_settings -f $temp_file$args 2>&1"; if (isset($this->_logger)) { $this->_logger->log(2, 'Running command "' . $cmd . '"'); } $savedir = getcwd(); // in case the test moves us around - if (isset($section_text['RETURNS'])) { - ob_start(); - system($cmd, $return_value); - $out = ob_get_contents(); - ob_end_clean(); - if (file_exists($tmp_post)) { - unlink($tmp_post); + // Reset environment from any previous test. + $env['REDIRECT_STATUS']=''; + $env['QUERY_STRING']=''; + $env['PATH_TRANSLATED']=''; + $env['SCRIPT_FILENAME']=''; + $env['REQUEST_METHOD']=''; + $env['CONTENT_TYPE']=''; + $env['CONTENT_LENGTH']=''; + if (!empty($section_text['ENV'])) { + foreach(explode("\n", trim($section_text['ENV'])) as $e) { + $e = explode('=',trim($e),2); + if (!empty($e[0]) && isset($e[1])) { + $env[$e[0]] = $e[1]; + } } + } + if (array_key_exists('GET', $section_text)) { + $query_string = trim($section_text['GET']); + } else { + $query_string = ''; + } + if (array_key_exists('COOKIE', $section_text)) { + $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); + } else { + $env['HTTP_COOKIE'] = ''; + } + $env['REDIRECT_STATUS'] = '1'; + $env['QUERY_STRING'] = $query_string; + $env['PATH_TRANSLATED'] = $test_file; + $env['SCRIPT_FILENAME'] = $test_file; + if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { + + $post = trim($section_text['POST']); + $this->save_text($tmp_post, $post); + $content_length = strlen($post); + + $env['REQUEST_METHOD'] = 'POST'; + $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + $env['CONTENT_LENGTH'] = $content_length; + + $cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post"; + + } else { + + $env['REQUEST_METHOD'] = 'GET'; + $env['CONTENT_TYPE'] = ''; + $env['CONTENT_LENGTH'] = ''; + + $cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1"; + } + $out = $this->system_with_timeout($cmd, $env, + isset($section_text['STDIN']) ? $section_text['STDIN'] : null); + $return_value = $out[0]; + $out = $out[1]; + if (isset($section_text['RETURNS'])) { $section_text['RETURNS'] = (int) trim($section_text['RETURNS']); $returnfail = ($return_value != $section_text['RETURNS']); } else { - $out = `$cmd`; $returnfail = false; } chdir($savedir); if ($section_text['CLEAN']) { // perform test cleanup - $this->save_text($clean = $tmp . uniqid('/phpt.'), $section_text['CLEAN']); - `$php $clean`; - if (file_exists($clean)) { - unlink($clean); + $this->save_text($temp_clean, $section_text['CLEAN']); + $this->system_with_timeout("$php $temp_clean"); + if (file_exists($temp_clean)) { + unlink($temp_clean); } } // Does the output match what is expected? $output = trim($out); $output = preg_replace('/\r\n/', "\n", $output); + /* when using CGI, strip the headers from the output */ + $headers = ""; + if (!empty($this->_options['cgi']) && + preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { + $output = trim($match[2]); + $rh = preg_split("/[\n\r]+/",$match[1]); + $headers = array(); + foreach ($rh as $line) { + if (strpos($line, ':')!==false) { + $line = explode(':', $line, 2); + $headers[trim($line[0])] = trim($line[1]); + } + } + } + if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); @@ -272,8 +458,8 @@ var_dump($output); */ if (!$returnfail && preg_match("/^$wanted_re\$/s", $output)) { - if (file_exists($tmp_file)) { - unlink($tmp_file); + if (file_exists($temp_file)) { + unlink($temp_file); } if (!isset($this->_options['quiet'])) { $this->_logger->log(0, "PASS $tested$info"); @@ -293,8 +479,8 @@ // compare and leave on success $ok = (0 == strcmp($output,$wanted)); if (!$returnfail && $ok) { - if (file_exists($tmp_file)) { - unlink($tmp_file); + if (file_exists($temp_file)) { + unlink($temp_file); } if (!isset($this->_options['quiet'])) { $this->_logger->log(0, "PASS $tested$info"); @@ -320,8 +506,8 @@ $GLOBALS['__PHP_FAILED_TESTS__'][] = array( 'name' => $file, 'test_name' => $tested, - 'output' => ereg_replace('\.phpt$','.log', $file), - 'diff' => ereg_replace('\.phpt$','.diff', $file), + 'output' => $log_filename, + 'diff' => $diff_filename, 'info' => $info, 'return' => $return_value ); @@ -329,15 +515,15 @@ $GLOBALS['__PHP_FAILED_TESTS__'][] = array( 'name' => $file, 'test_name' => $tested, - 'output' => ereg_replace('\.phpt$','.log', $file), - 'diff' => ereg_replace('\.phpt$','.diff', $file), + 'output' => $output_filename, + 'diff' => $diff_filename, 'info' => $info, ); } // write .exp if (strpos($log_format,'E') !== FALSE) { - $logname = ereg_replace('\.phpt$','.exp',$file); + $logname = $log_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } @@ -347,7 +533,7 @@ // write .out if (strpos($log_format,'O') !== FALSE) { - $logname = ereg_replace('\.phpt$','.out',$file); + $logname = $output_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } @@ -357,7 +543,7 @@ // write .diff if (strpos($log_format,'D') !== FALSE) { - $logname = ereg_replace('\.phpt$','.diff',$file); + $logname = $diff_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } @@ -373,7 +559,7 @@ // write .log if (strpos($log_format,'L') !== FALSE) { - $logname = ereg_replace('\.phpt$','.log',$file); + $logname = $log_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Command/Test.php?r1=1.12&r2=1.13&diff_format=u Index: pear-core/PEAR/Command/Test.php diff -u pear-core/PEAR/Command/Test.php:1.12 pear-core/PEAR/Command/Test.php:1.13 --- pear-core/PEAR/Command/Test.php:1.12 Tue Mar 28 05:33:42 2006 +++ pear-core/PEAR/Command/Test.php Fri Feb 16 05:36:57 2007 @@ -17,7 +17,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Test.php,v 1.12 2006/03/28 05:33:42 cellog Exp $ + * @version CVS: $Id: Test.php,v 1.13 2007/02/16 05:36:57 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -85,6 +85,10 @@ 'shortopt' => 't', 'doc' => 'Output run-tests.log in TAP-compliant format', ), + 'cgi' => array( + 'shortopt' => 'c', + 'doc' => 'CGI php executable (needed for tests with POST/GET section)', + ), ), 'doc' => '[testfile|dir ...] Run regression tests with PHP\'s regression testing script (run-tests.php).', http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Command/Test.xml?r1=1.4&r2=1.5&diff_format=u Index: pear-core/PEAR/Command/Test.xml diff -u pear-core/PEAR/Command/Test.xml:1.4 pear-core/PEAR/Command/Test.xml:1.5 --- pear-core/PEAR/Command/Test.xml:1.4 Tue Mar 28 05:33:42 2006 +++ pear-core/PEAR/Command/Test.xml Fri Feb 16 05:36:57 2007 @@ -37,6 +37,10 @@ <shortopt>t</shortopt> <doc>Output run-tests.log in TAP-compliant format</doc> </tapoutput> + <cgi> + <shortopt>c</shortopt> + <doc>CGI php executable (needed for tests with POST/GET section)</doc> + </cgi> </options> <doc>[testfile|dir ...] Run regression tests with PHP's regression testing script (run-tests.php).</doc> http://cvs.php.net/viewvc.cgi/pear-core/tests/PEAR_RunTest/test_bug10092.phpt?view=markup&rev=1.1 Index: pear-core/tests/PEAR_RunTest/test_bug10092.phpt +++ pear-core/tests/PEAR_RunTest/test_bug10092.phpt --TEST-- PEAR_RunTest --INI-- --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --INI-- open_basedir=hooba --FILE-- <?php var_dump(ini_get('open_basedir')); var_dump($_POST); ?> --EXPECT-- string(5) "hooba" array(1) { ["test"]=> string(2) "hi" } http://cvs.php.net/viewvc.cgi/pear-core/tests/PEAR_RunTest/test_bug10092post.phpt?view=markup&rev=1.1 Index: pear-core/tests/PEAR_RunTest/test_bug10092post.phpt +++ pear-core/tests/PEAR_RunTest/test_bug10092post.phpt --TEST-- PEAR_RunTest --POST-- --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --POST-- test=hi --FILE-- <?php var_dump($_POST); ?> --EXPECT-- array(1) { ["test"]=> string(2) "hi" }
http://cvs.php.net/viewvc.cgi/pear-core/package-PEAR.xml?r1=1.432&r2=1.433&diff_format=u Index: pear-core/package-PEAR.xml diff -u pear-core/package-PEAR.xml:1.432 pear-core/package-PEAR.xml:1.433 --- pear-core/package-PEAR.xml:1.432 Fri Feb 16 04:00:37 2007 +++ pear-core/package-PEAR.xml Fri Feb 16 05:36:57 2007 @@ -90,6 +90,7 @@ * fix Bug #9971: Improve run-tests diffs of EXPECTF sections * fix Bug #10012: pear package: tokenizer should be enabled * fix Bug #10081: installer dies on uninstall (recursion too deep) + * fix Bug #10092: run-tests does not support --INI-- or --POST-- * fix Bug #10108: update-error with backups from test-Folder * fix Bug #10109: on failed upgrade, .bak files everywhere </notes> http://cvs.php.net/viewvc.cgi/pear-core/package2.xml?r1=1.326&r2=1.327&diff_format=u Index: pear-core/package2.xml diff -u pear-core/package2.xml:1.326 pear-core/package2.xml:1.327 --- pear-core/package2.xml:1.326 Fri Feb 16 04:00:37 2007 +++ pear-core/package2.xml Fri Feb 16 05:36:57 2007 @@ -99,6 +99,7 @@ * fix Bug #9971: Improve run-tests diffs of EXPECTF sections * fix Bug #10012: pear package: tokenizer should be enabled * fix Bug #10081: installer dies on uninstall (recursion too deep) + * fix Bug #10092: run-tests does not support --INI-- or --POST-- * fix Bug #10108: update-error with backups from test-Folder * fix Bug #10109: on failed upgrade, .bak files everywhere </notes> http://cvs.php.net/viewvc.cgi/pear-core/PEAR/RunTest.php?r1=1.24&r2=1.25&diff_format=u Index: pear-core/PEAR/RunTest.php diff -u pear-core/PEAR/RunTest.php:1.24 pear-core/PEAR/RunTest.php:1.25 --- pear-core/PEAR/RunTest.php:1.24 Wed Feb 14 06:10:16 2007 +++ pear-core/PEAR/RunTest.php Fri Feb 16 05:36:57 2007 @@ -16,7 +16,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: RunTest.php,v 1.24 2007/02/14 06:10:16 cellog Exp $ + * @version CVS: $Id: RunTest.php,v 1.25 2007/02/16 05:36:57 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.3.3 */ @@ -52,6 +52,28 @@ { var $_logger; var $_options; + var $ini_overwrites = array( + 'output_handler=', + 'open_basedir=', + 'safe_mode=0', + 'disable_functions=', + 'output_buffering=Off', + 'error_reporting=8191', + 'display_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', + ); + /** * An object that supports the PEAR_Common->log() signature, or null @@ -67,6 +89,93 @@ $this->_options = $options; } + /** + * Taken from php-src/run-tests.php + * + * @param string $commandline command name + * @param array $env + * @param string $stdin standard input to pass to the command + * @return unknown + */ + function system_with_timeout($commandline, $env = null, $stdin = null) + { + $data = ''; + + if (version_compare(phpversion(), '5.0.0', '<')) { + $proc = proc_open($commandline, array( + 0 => array('pipe', 'r'), + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w') + ), $pipes); + } else { + $proc = proc_open($commandline, array( + 0 => array('pipe', 'r'), + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w') + ), $pipes, null, $env, array("suppress_errors" => true)); + } + + if (!$proc) { + return false; + } + + if (is_string($stdin)) { + fwrite($pipes[0], $stdin); + } + fclose($pipes[0]); + + while (true) { + /* hide errors from interrupted syscalls */ + $r = $pipes; + $w = null; + $e = null; + $n = @stream_select($r, $w, $e, 60); + + if ($n === 0) { + /* timed out */ + $data .= "\n ** ERROR: process timed out **\n"; + proc_terminate($proc); + return array(1234567890, $data); + } else if ($n > 0) { + $line = fread($pipes[1], 8192); + if (strlen($line) == 0) { + /* EOF */ + break; + } + $data .= $line; + } + } + $stat = proc_get_status($proc); + if ($stat['signaled']) { + $data .= "\nTermsig=".$stat['stopsig']; + } + $code = proc_close($proc); + return array($stat['exitcode'], $data); + } + + function settings2array($settings, $ini_settings) + { + foreach ($settings as $setting) { + if (strpos($setting, '=')!==false) { + $setting = explode("=", $setting, 2); + $name = trim(strtolower($setting[0])); + $value = trim($setting[1]); + $ini_settings[$name] = $value; + } + } + return $ini_settings; + } + + function settings2params($ini_settings) + { + $settings = ''; + foreach ($ini_settings as $name => $value) { + $value = addslashes($value); + $settings .= " -d \"$name=$value\""; + } + return $settings; + } + // // Run an individual test case. // @@ -88,8 +197,10 @@ chdir($savedir); return 'PASSED'; // we have no way of knowing this information so assume passing } - //var_dump($php);exit; - global $log_format, $info_params, $ini_overwrites; + $pass_options = ''; + if (!empty($this->_options['ini'])) { + $pass_options = $this->_options['ini']; + } $info_params = ''; $log_format = 'LEOD'; @@ -99,6 +210,7 @@ 'TEST' => '(unnamed test)', 'SKIPIF' => '', 'GET' => '', + 'POST' => '', 'ARGS' => '', 'INI' => '', 'CLEAN' => '', @@ -114,20 +226,42 @@ $line = fgets($fp); // Match the beginning of a section. - if (ereg('^--([A-Z]+)--',$line,$r)) { + if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { $section = $r[1]; $section_text[$section] = ''; continue; } elseif (empty($section)) { fclose($fp); return PEAR::raiseError("Invalid sections formats in test file: $file"); - } + } // Add to the section text. $section_text[$section] .= $line; } fclose($fp); + $ini_settings = array(); + $ini_settings = $this->settings2array($this->ini_overwrites, $ini_settings); + if ($section_text['INI']) { + if (strpos($section_text['INI'], '{PWD}') !== false) { + $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); + } + $ini_settings = $this->settings2array(preg_split( "/[\n\r]+/", + $section_text['INI']), $ini_settings); + } + $ini_settings = $this->settings2params($ini_settings); + if (!empty($section_text['GET']) || !empty($section_text['POST'])) { + if (empty($this->_options['cgi'])) { + if (!isset($this->_options['quiet'])) { + $this->_logger->log(0, "SKIP $tested (reason: --cgi option needed for this test, type 'pear help run-tests')"); + } + if (isset($this->_options['tapoutput'])) { + return array('ok', ' # skip --cgi option needed for this test, "pear help run-tests" for info'); + } + return 'SKIPPED'; + } + $php = $this->_options['cgi']; + } $shortname = str_replace($cwd . DIRECTORY_SEPARATOR, '', $file); if (!isset($this->_options['simple'])) { $tested = trim($section_text['TEST']) . "[$shortname]"; @@ -135,119 +269,171 @@ $tested = trim($section_text['TEST']) . ' '; } - $tmp = realpath(dirname($file)); - $tmp_skipif = $tmp . uniqid('/phpt.'); - $tmp_file = ereg_replace('\.phpt$','.php',$file); - $tmp_post = $tmp . uniqid('/phpt.'); - - if (file_exists($tmp_skipif)) { - unlink($tmp_skipif); - } - if (file_exists($tmp_file)) { - unlink($tmp_file); - } - if (file_exists($tmp_post)) { - unlink($tmp_post); - } - - // unlink old test results - if (file_exists(ereg_replace('\.phpt$','.diff',$file))) { - unlink(ereg_replace('\.phpt$','.diff',$file)); - } - if (file_exists(ereg_replace('\.phpt$','.log',$file))) { - unlink(ereg_replace('\.phpt$','.log',$file)); - } - if (file_exists(ereg_replace('\.phpt$','.exp',$file))) { - unlink(ereg_replace('\.phpt$','.exp',$file)); - } - if (file_exists(ereg_replace('\.phpt$','.out',$file))) { - unlink(ereg_replace('\.phpt$','.out',$file)); - } + $temp_dir = $test_dir = realpath(dirname($file)); + $main_file_name = basename($file,'phpt'); + $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'diff'; + $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'log'; + $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'exp'; + $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out'; + $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem'; + $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; + $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; + $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; + $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; + $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php'; + $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php'; + $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); + + // unlink old test results + @unlink($diff_filename); + @unlink($log_filename); + @unlink($exp_filename); + @unlink($output_filename); + @unlink($memcheck_filename); + @unlink($temp_file); + @unlink($test_file); + @unlink($temp_skipif); + @unlink($test_skipif); + @unlink($tmp_post); + @unlink($temp_clean); + @unlink($test_clean); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { - $this->save_text($tmp_skipif, $section_text['SKIPIF']); - //$extra = substr(PHP_OS, 0, 3) !== "WIN" ? - // "unset REQUEST_METHOD;": ""; - - //$output = `$extra $php $info_params -f $tmp_skipif`; - $output = `$php $info_params -f $tmp_skipif`; - unlink($tmp_skipif); - if (eregi("^skip", trim($output))) { + $this->save_text($temp_skipif, $section_text['SKIPIF']); + $output = $this->system_with_timeout("$php $info_params -f $temp_skipif"); + $output = $output[1]; + unlink($temp_skipif); + if (!strncasecmp('skip', ltrim($output), 4)) { $skipreason = "SKIP $tested"; - $reason = (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; - if ($reason) { - $skipreason .= " (reason: $reason)"; + if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) { + $skipreason .= '(reason: ' . $m[1] . ')'; } if (!isset($this->_options['quiet'])) { $this->_logger->log(0, $skipreason); } - if (isset($old_php)) { - $php = $old_php; - } if (isset($this->_options['tapoutput'])) { return array('ok', ' # skip ' . $reason); } return 'SKIPPED'; } - if (eregi("^info", trim($output))) { - $reason = (ereg("^info[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; - if ($reason) { - $info = " (info: $reason)"; + if (!strncasecmp('info', ltrim($output), 4)) { + if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) { + $info = " (info: $m[1])"; } } - if (eregi("^warn", trim($output))) { - $reason = (ereg("^warn[[:space:]]*(.+)\$", trim($output))) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; - if ($reason) { + if (!strncasecmp('warn', ltrim($output), 4)) { + if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ - $info = " (warn: $reason)"; + $info = " (warn: $m[1])"; } } } } // We've satisfied the preconditions - run the test! - $this->save_text($tmp_file,$section_text['FILE']); + $this->save_text($temp_file,$section_text['FILE']); $args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : ''; - $cmd = "$php$ini_settings -f $tmp_file$args 2>&1"; + $cmd = "$php$ini_settings -f $temp_file$args 2>&1"; if (isset($this->_logger)) { $this->_logger->log(2, 'Running command "' . $cmd . '"'); } $savedir = getcwd(); // in case the test moves us around - if (isset($section_text['RETURNS'])) { - ob_start(); - system($cmd, $return_value); - $out = ob_get_contents(); - ob_end_clean(); - if (file_exists($tmp_post)) { - unlink($tmp_post); + // Reset environment from any previous test. + $env['REDIRECT_STATUS']=''; + $env['QUERY_STRING']=''; + $env['PATH_TRANSLATED']=''; + $env['SCRIPT_FILENAME']=''; + $env['REQUEST_METHOD']=''; + $env['CONTENT_TYPE']=''; + $env['CONTENT_LENGTH']=''; + if (!empty($section_text['ENV'])) { + foreach(explode("\n", trim($section_text['ENV'])) as $e) { + $e = explode('=',trim($e),2); + if (!empty($e[0]) && isset($e[1])) { + $env[$e[0]] = $e[1]; + } } + } + if (array_key_exists('GET', $section_text)) { + $query_string = trim($section_text['GET']); + } else { + $query_string = ''; + } + if (array_key_exists('COOKIE', $section_text)) { + $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); + } else { + $env['HTTP_COOKIE'] = ''; + } + $env['REDIRECT_STATUS'] = '1'; + $env['QUERY_STRING'] = $query_string; + $env['PATH_TRANSLATED'] = $test_file; + $env['SCRIPT_FILENAME'] = $test_file; + if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { + + $post = trim($section_text['POST']); + $this->save_text($tmp_post, $post); + $content_length = strlen($post); + + $env['REQUEST_METHOD'] = 'POST'; + $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + $env['CONTENT_LENGTH'] = $content_length; + + $cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post"; + + } else { + + $env['REQUEST_METHOD'] = 'GET'; + $env['CONTENT_TYPE'] = ''; + $env['CONTENT_LENGTH'] = ''; + + $cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1"; + } + $out = $this->system_with_timeout($cmd, $env, + isset($section_text['STDIN']) ? $section_text['STDIN'] : null); + $return_value = $out[0]; + $out = $out[1]; + if (isset($section_text['RETURNS'])) { $section_text['RETURNS'] = (int) trim($section_text['RETURNS']); $returnfail = ($return_value != $section_text['RETURNS']); } else { - $out = `$cmd`; $returnfail = false; } chdir($savedir); if ($section_text['CLEAN']) { // perform test cleanup - $this->save_text($clean = $tmp . uniqid('/phpt.'), $section_text['CLEAN']); - `$php $clean`; - if (file_exists($clean)) { - unlink($clean); + $this->save_text($temp_clean, $section_text['CLEAN']); + $this->system_with_timeout("$php $temp_clean"); + if (file_exists($temp_clean)) { + unlink($temp_clean); } } // Does the output match what is expected? $output = trim($out); $output = preg_replace('/\r\n/', "\n", $output); + /* when using CGI, strip the headers from the output */ + $headers = ""; + if (!empty($this->_options['cgi']) && + preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { + $output = trim($match[2]); + $rh = preg_split("/[\n\r]+/",$match[1]); + $headers = array(); + foreach ($rh as $line) { + if (strpos($line, ':')!==false) { + $line = explode(':', $line, 2); + $headers[trim($line[0])] = trim($line[1]); + } + } + } + if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); @@ -272,8 +458,8 @@ var_dump($output); */ if (!$returnfail && preg_match("/^$wanted_re\$/s", $output)) { - if (file_exists($tmp_file)) { - unlink($tmp_file); + if (file_exists($temp_file)) { + unlink($temp_file); } if (!isset($this->_options['quiet'])) { $this->_logger->log(0, "PASS $tested$info"); @@ -293,8 +479,8 @@ // compare and leave on success $ok = (0 == strcmp($output,$wanted)); if (!$returnfail && $ok) { - if (file_exists($tmp_file)) { - unlink($tmp_file); + if (file_exists($temp_file)) { + unlink($temp_file); } if (!isset($this->_options['quiet'])) { $this->_logger->log(0, "PASS $tested$info"); @@ -320,8 +506,8 @@ $GLOBALS['__PHP_FAILED_TESTS__'][] = array( 'name' => $file, 'test_name' => $tested, - 'output' => ereg_replace('\.phpt$','.log', $file), - 'diff' => ereg_replace('\.phpt$','.diff', $file), + 'output' => $log_filename, + 'diff' => $diff_filename, 'info' => $info, 'return' => $return_value ); @@ -329,15 +515,15 @@ $GLOBALS['__PHP_FAILED_TESTS__'][] = array( 'name' => $file, 'test_name' => $tested, - 'output' => ereg_replace('\.phpt$','.log', $file), - 'diff' => ereg_replace('\.phpt$','.diff', $file), + 'output' => $output_filename, + 'diff' => $diff_filename, 'info' => $info, ); } // write .exp if (strpos($log_format,'E') !== FALSE) { - $logname = ereg_replace('\.phpt$','.exp',$file); + $logname = $log_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } @@ -347,7 +533,7 @@ // write .out if (strpos($log_format,'O') !== FALSE) { - $logname = ereg_replace('\.phpt$','.out',$file); + $logname = $output_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } @@ -357,7 +543,7 @@ // write .diff if (strpos($log_format,'D') !== FALSE) { - $logname = ereg_replace('\.phpt$','.diff',$file); + $logname = $diff_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } @@ -373,7 +559,7 @@ // write .log if (strpos($log_format,'L') !== FALSE) { - $logname = ereg_replace('\.phpt$','.log',$file); + $logname = $log_filename; if (!$log = fopen($logname,'w')) { return PEAR::raiseError("Cannot create test log - $logname"); } http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Command/Test.php?r1=1.12&r2=1.13&diff_format=u Index: pear-core/PEAR/Command/Test.php diff -u pear-core/PEAR/Command/Test.php:1.12 pear-core/PEAR/Command/Test.php:1.13 --- pear-core/PEAR/Command/Test.php:1.12 Tue Mar 28 05:33:42 2006 +++ pear-core/PEAR/Command/Test.php Fri Feb 16 05:36:57 2007 @@ -17,7 +17,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Test.php,v 1.12 2006/03/28 05:33:42 cellog Exp $ + * @version CVS: $Id: Test.php,v 1.13 2007/02/16 05:36:57 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 0.1 */ @@ -85,6 +85,10 @@ 'shortopt' => 't', 'doc' => 'Output run-tests.log in TAP-compliant format', ), + 'cgi' => array( + 'shortopt' => 'c', + 'doc' => 'CGI php executable (needed for tests with POST/GET section)', + ), ), 'doc' => '[testfile|dir ...] Run regression tests with PHP\'s regression testing script (run-tests.php).', http://cvs.php.net/viewvc.cgi/pear-core/PEAR/Command/Test.xml?r1=1.4&r2=1.5&diff_format=u Index: pear-core/PEAR/Command/Test.xml diff -u pear-core/PEAR/Command/Test.xml:1.4 pear-core/PEAR/Command/Test.xml:1.5 --- pear-core/PEAR/Command/Test.xml:1.4 Tue Mar 28 05:33:42 2006 +++ pear-core/PEAR/Command/Test.xml Fri Feb 16 05:36:57 2007 @@ -37,6 +37,10 @@ <shortopt>t</shortopt> <doc>Output run-tests.log in TAP-compliant format</doc> </tapoutput> + <cgi> + <shortopt>c</shortopt> + <doc>CGI php executable (needed for tests with POST/GET section)</doc> + </cgi> </options> <doc>[testfile|dir ...] Run regression tests with PHP's regression testing script (run-tests.php).</doc> http://cvs.php.net/viewvc.cgi/pear-core/tests/PEAR_RunTest/test_bug10092.phpt?view=markup&rev=1.1 Index: pear-core/tests/PEAR_RunTest/test_bug10092.phpt +++ pear-core/tests/PEAR_RunTest/test_bug10092.phpt --TEST-- PEAR_RunTest --INI-- --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --INI-- open_basedir=hooba --FILE-- <?php var_dump(ini_get('open_basedir')); var_dump($_POST); ?> --EXPECT-- string(5) "hooba" array(1) { ["test"]=> string(2) "hi" } http://cvs.php.net/viewvc.cgi/pear-core/tests/PEAR_RunTest/test_bug10092post.phpt?view=markup&rev=1.1 Index: pear-core/tests/PEAR_RunTest/test_bug10092post.phpt +++ pear-core/tests/PEAR_RunTest/test_bug10092post.phpt --TEST-- PEAR_RunTest --POST-- --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --POST-- test=hi --FILE-- <?php var_dump($_POST); ?> --EXPECT-- array(1) { ["test"]=> string(2) "hi" }