Browse Source

ws fixes

migration/unlabaled-1.29.2
foobar 23 years ago
parent
commit
9a010becf1
  1. 406
      run-tests.php

406
run-tests.php

@ -23,14 +23,14 @@
/*
Require exact specification of PHP executable to test (no guessing!).
Require exact specification of PHP executable to test (no guessing!).
Die if any internal errors encountered in test script.
Die if any internal errors encountered in test script.
Regularized output for simpler post-processing of output.
Regularized output for simpler post-processing of output.
Optionally output error lines indicating the failing test source and log
for direct jump with MSVC or Emacs.
Optionally output error lines indicating the failing test source and log
for direct jump with MSVC or Emacs.
*/
@ -39,12 +39,13 @@
* - do not test PEAR components if base class and/or component class cannot be instanciated
*/
$cwd = getcwd();
set_time_limit(0);
ob_implicit_flush();
error_reporting(E_ALL);
if (ini_get('safe_mode')) {
echo <<< SAFE_MODE_WARNING
echo <<< SAFE_MODE_WARNING
+-----------------------------------------------------------+
| ! WARNING ! |
@ -90,7 +91,7 @@ if (isset($_ENV['TEST_PHP_DETAILED'])) {
echo "
=====================================================================
CWD : " . getcwd() . "
CWD : $cwd
PHP : $php
PHP_SAPI : " . PHP_SAPI . "
PHP_VERSION : " . PHP_VERSION . "
@ -143,26 +144,25 @@ $exts_skipped = 0;
$ignored_by_ext = 0;
sort($exts_to_test);
$test_dirs = array('tests', 'pear', 'ext');
$cwd=getcwd();
foreach ($test_dirs as $dir) {
find_files("{$cwd}/{$dir}", $dir=='ext');
find_files("{$cwd}/{$dir}", ($dir == 'ext'));
}
function find_files($dir,$is_ext_dir=false,$ignore=false)
function find_files($dir,$is_ext_dir=FALSE,$ignore=FALSE)
{
global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped, $exts_tested;
$o = opendir($dir) or error("cannot open directory: $dir");
while (($name = readdir($o)) !== false) {
while (($name = readdir($o)) !== FALSE) {
if (is_dir("{$dir}/{$name}") && !in_array($name, array('.', '..', 'CVS'))) {
$skip_ext = ($is_ext_dir && !in_array($name, $exts_to_test));
if ($skip_ext) {
$exts_skipped++;
}
find_files("{$dir}/{$name}", false, $ignore || $skip_ext);
}
find_files("{$dir}/{$name}", FALSE, $ignore || $skip_ext);
}
// Cleanup any left-over tmp files from last run.
if (substr($name, -4) == '.tmp') {
@unlink("$dir/$name");
@ -192,14 +192,13 @@ echo "TIME START " . date('Y-m-d H:i:s', $start_time) . "
$path_current = '';
foreach ($test_files as $name) {
$path = dirname($name);
if ($path_current != $path) {
$path_current = $path;
echo " entering directory $path\n";
}
$test_results[$name] = run_test($php,$name);
$path = dirname($name);
if ($path_current != $path) {
$path_current = $path;
echo " entering directory $path\n";
}
$test_results[$name] = run_test($php,$name);
}
$end_time = time();
@ -207,8 +206,8 @@ $end_time = time();
// Summarize results
if (0 == count($test_results)) {
echo "No tests were run.\n";
return;
echo "No tests were run.\n";
return;
}
$n_total = count($test_results);
@ -216,12 +215,12 @@ $n_total += $ignored_by_ext;
$sum_results = array('PASSED'=>0, 'SKIPPED'=>0, 'FAILED'=>0);
foreach ($test_results as $v) {
$sum_results[$v]++;
$sum_results[$v]++;
}
$sum_results['SKIPPED'] += $ignored_by_ext;
$percent_results = array();
while (list($v,$n) = each($sum_results)) {
$percent_results[$v] = (100.0 * $n) / $n_total;
$percent_results[$v] = (100.0 * $n) / $n_total;
}
echo "
@ -248,10 +247,10 @@ Time taken : " . sprintf("%4d seconds", $end_time - $start_time) . "
function save_text($filename,$text)
{
$fp = @fopen($filename,'w') or error("Cannot open file '" . $filename . "' (save_text)");
fwrite($fp,$text);
fclose($fp);
if (1 < DETAILED) echo "
$fp = @fopen($filename,'w') or error("Cannot open file '" . $filename . "' (save_text)");
fwrite($fp,$text);
fclose($fp);
if (1 < DETAILED) echo "
FILE $filename {{{
$text
}}}
@ -264,18 +263,18 @@ $text
function error_report($testname,$logname,$tested)
{
$testname = realpath($testname);
$logname = realpath($logname);
switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) {
case 'MSVC':
echo $testname . "(1) : $tested\n";
echo $logname . "(1) : $tested\n";
break;
case 'EMACS':
echo $testname . ":1: $tested\n";
echo $logname . ":1: $tested\n";
break;
}
$testname = realpath($testname);
$logname = realpath($logname);
switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) {
case 'MSVC':
echo $testname . "(1) : $tested\n";
echo $logname . "(1) : $tested\n";
break;
case 'EMACS':
echo $testname . ":1: $tested\n";
echo $logname . ":1: $tested\n";
break;
}
}
//
@ -286,60 +285,58 @@ function run_test($php,$file)
{
global $log_format;
if (DETAILED) echo "
if (DETAILED) echo "
=================
TEST $file
";
// Load the sections of the test file.
$section_text = array(
'TEST' => '(unnamed test)',
'SKIPIF' => '',
'GET' => '',
'ARGS' => '',
);
$fp = @fopen($file, "r")
or error("Cannot open test file: $file");
$section = '';
while (!feof($fp)) {
$line = fgets($fp);
// Match the beginning of a section.
if (ereg('^--([A-Z]+)--',$line,$r)) {
$section = $r[1];
$section_text[$section] = '';
continue;
}
// Add to the section text.
$section_text[$section] .= $line;
}
fclose($fp);
$tested = trim($section_text['TEST']).' ('.basename($file).')';
$tmp = realpath(dirname($file));
$tmp_skipif = $tmp.uniqid('/phpt.');
$tmp_file = $tmp.uniqid('/phpt.');
$tmp_post = $tmp.uniqid('/phpt.');
// Load the sections of the test file.
$section_text = array(
'TEST' => '(unnamed test)',
'SKIPIF' => '',
'GET' => '',
'ARGS' => '',
);
$fp = @fopen($file, "r") or error("Cannot open test file: $file");
$section = '';
while (!feof($fp)) {
$line = fgets($fp);
// Match the beginning of a section.
if (ereg('^--([A-Z]+)--',$line,$r)) {
$section = $r[1];
$section_text[$section] = '';
continue;
}
// Add to the section text.
$section_text[$section] .= $line;
}
fclose($fp);
$tested = trim($section_text['TEST']).' ('.basename($file).')';
$tmp = realpath(dirname($file));
$tmp_skipif = $tmp . uniqid('/phpt.');
$tmp_file = $tmp . uniqid('/phpt.');
$tmp_post = $tmp . uniqid('/phpt.');
@unlink($tmp_skipif);
@unlink($tmp_file);
@unlink($tmp_post);
// Reset environment from any previous test.
putenv("REDIRECT_STATUS=");
putenv("QUERY_STRING=");
putenv("PATH_TRANSLATED=");
putenv("SCRIPT_FILENAME=");
putenv("REQUEST_METHOD=");
putenv("CONTENT_TYPE=");
putenv("CONTENT_LENGTH=");
// Reset environment from any previous test.
putenv("REDIRECT_STATUS=");
putenv("QUERY_STRING=");
putenv("PATH_TRANSLATED=");
putenv("SCRIPT_FILENAME=");
putenv("REQUEST_METHOD=");
putenv("CONTENT_TYPE=");
putenv("CONTENT_LENGTH=");
// unlink old test results
@unlink(ereg_replace('\.phpt$','.diff',$file));
@unlink(ereg_replace('\.phpt$','.log',$file));
@ -348,62 +345,64 @@ TEST $file
// Check if test should be skipped.
if (array_key_exists('SKIPIF', $section_text)) {
if (trim($section_text['SKIPIF'])) {
if (trim($section_text['SKIPIF'])) {
save_text($tmp_skipif, $section_text['SKIPIF']);
$output = `$php $tmp_skipif`;
@unlink($tmp_skipif);
if(trim($output)=='skip') {
if (trim($output) == 'skip') {
echo "SKIP $tested\n";
return 'SKIPPED';
}
}
}
// Any special ini settings
// Any special ini settings
$ini_settings = '';
if (array_key_exists('INI', $section_text)) {
foreach(preg_split( "/[\n\r]+/", $section_text['INI']) as $setting)
if (strlen($setting))
foreach(preg_split( "/[\n\r]+/", $section_text['INI']) as $setting) {
if (strlen($setting)) {
$ini_settings .= " -d '$setting'";
}
}
}
// We've satisfied the preconditions - run the test!
save_text($tmp_file,$section_text['FILE']);
if (array_key_exists('GET', $section_text))
$query_string = trim($section_text['GET']);
else
// We've satisfied the preconditions - run the test!
save_text($tmp_file,$section_text['FILE']);
if (array_key_exists('GET', $section_text)) {
$query_string = trim($section_text['GET']);
} else {
$query_string = '';
}
putenv("REDIRECT_STATUS=1");
putenv("QUERY_STRING=$query_string");
putenv("PATH_TRANSLATED=$tmp_file");
putenv("SCRIPT_FILENAME=$tmp_file");
$args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
$post = trim($section_text['POST']);
save_text($tmp_post,$post);
$content_length = strlen($post);
putenv("REQUEST_METHOD=POST");
putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
putenv("CONTENT_LENGTH=$content_length");
$cmd = "$php$ini_settings -f $tmp_file 2>&1 < $tmp_post";
} else {
putenv("REQUEST_METHOD=GET");
putenv("CONTENT_TYPE=");
putenv("CONTENT_LENGTH=");
$cmd = "$php$ini_settings -f $tmp_file$args 2>&1";
}
if (DETAILED) echo "
putenv("REDIRECT_STATUS=1");
putenv("QUERY_STRING=$query_string");
putenv("PATH_TRANSLATED=$tmp_file");
putenv("SCRIPT_FILENAME=$tmp_file");
$args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
$post = trim($section_text['POST']);
save_text($tmp_post,$post);
$content_length = strlen($post);
putenv("REQUEST_METHOD=POST");
putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
putenv("CONTENT_LENGTH=$content_length");
$cmd = "$php$ini_settings -f $tmp_file 2>&1 < $tmp_post";
} else {
putenv("REQUEST_METHOD=GET");
putenv("CONTENT_TYPE=");
putenv("CONTENT_LENGTH=");
$cmd = "$php$ini_settings -f $tmp_file$args 2>&1";
}
if (DETAILED) echo "
CONTENT_LENGTH = " . getenv("CONTENT_LENGTH") . "
CONTENT_TYPE = " . getenv("CONTENT_TYPE") . "
PATH_TRANSLATED = " . getenv("PATH_TRANSLATED") . "
@ -413,106 +412,104 @@ REQUEST_METHOD = " . getenv("REQUEST_METHOD") . "
SCRIPT_FILENAME = " . getenv("SCRIPT_FILENAME") . "
COMMAND $cmd
";
$out = `$cmd`;
@unlink($tmp_post);
@unlink($tmp_file);
// Does the output match what is expected?
$output = trim($out);
$output = preg_replace('/\r\n/',"\n",$output);
if(isset($section_text['EXPECTF'])) {
$wanted = trim($section_text['EXPECTF']);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
$wanted = preg_quote($wanted, '/');
// Stick to basics
$wanted = str_replace("%s", ".*?", $wanted); //not greedy
$wanted = str_replace("%i", "[0-9]+", $wanted);
$wanted = str_replace("%f", "[0-9\.+\-]+", $wanted);
$out = `$cmd`;
@unlink($tmp_post);
@unlink($tmp_file);
// Does the output match what is expected?
$output = trim($out);
$output = preg_replace('/\r\n/',"\n",$output);
if (isset($section_text['EXPECTF'])) {
$wanted = trim($section_text['EXPECTF']);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
$wanted = preg_quote($wanted, '/');
// Stick to basics
$wanted = str_replace("%s", ".*?", $wanted); //not greedy
$wanted = str_replace("%i", "[0-9]+", $wanted);
$wanted = str_replace("%f", "[0-9\.+\-]+", $wanted);
/* DEBUG YOUR REGEX HERE
var_dump($wanted);
print(str_repeat('=', 80) . "\n");
var_dump($output);
var_dump($wanted);
print(str_repeat('=', 80) . "\n");
var_dump($output);
*/
if(preg_match("/$wanted/s", $output)) {
echo "PASS $tested\n";
return 'PASSED';
}
}
else {
$wanted = trim($section_text['EXPECT']);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
if (preg_match("/$wanted/s", $output)) {
echo "PASS $tested\n";
return 'PASSED';
}
} else {
$wanted = trim($section_text['EXPECT']);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
// compare and leave on success
$ok = (0 == strcmp($output,$wanted));
if ($ok) {
echo "PASS $tested\n";
return 'PASSED';
}
}
// Test failed so we need to report details.
echo "FAIL $tested\n";
$ok = (0 == strcmp($output,$wanted));
if ($ok) {
echo "PASS $tested\n";
return 'PASSED';
}
}
// Test failed so we need to report details.
echo "FAIL $tested\n";
// write .exp
if (strpos($log_format,'E')!==false) {
$logname = ereg_replace('\.phpt$','.exp',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,$wanted);
fclose($log);
if (strpos($log_format,'E') !== FALSE) {
$logname = ereg_replace('\.phpt$','.exp',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,$wanted);
fclose($log);
}
// write .out
if (strpos($log_format,'O')!==false) {
$logname = ereg_replace('\.phpt$','.out',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,$output);
fclose($log);
if (strpos($log_format,'O') !== FALSE) {
$logname = ereg_replace('\.phpt$','.out',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,$output);
fclose($log);
}
// write .diff
if (strpos($log_format,'D')!==false) {
$logname = ereg_replace('\.phpt$','.diff',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,generate_diff($wanted,$output));
fclose($log);
}
if (strpos($log_format,'D') !== FALSE) {
$logname = ereg_replace('\.phpt$','.diff',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,generate_diff($wanted,$output));
fclose($log);
}
// write .log
if (strpos($log_format,'L')!==false) {
$logname = ereg_replace('\.phpt$','.log',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,"
if (strpos($log_format,'L') !== FALSE) {
$logname = ereg_replace('\.phpt$','.log',$file);
$log = fopen($logname,'w') or error("Cannot create test log - $logname");
fwrite($log,"
---- EXPECTED OUTPUT
$wanted
---- ACTUAL OUTPUT
$output
---- FAILED
");
fclose($log);
error_report($file,$logname,$tested);
fclose($log);
error_report($file,$logname,$tested);
}
return 'FAILED';
return 'FAILED';
}
function generate_diff($wanted,$output)
{
$w = explode("\n", $wanted);
$o = explode("\n", $output);
$w1 = array_diff($w,$o);
$o1 = array_diff($o,$w);
$w2 = array();
$o2 = array();
foreach($w1 as $idx => $val) $w2[sprintf("%03d<",$idx)] = sprintf("%03d- ", $idx+1).$val;
foreach($o1 as $idx => $val) $o2[sprintf("%03d>",$idx)] = sprintf("%03d+ ", $idx+1).$val;
$diff = array_merge($w2, $o2);
ksort($diff);
return implode("\r\n", $diff);
$w = explode("\n", $wanted);
$o = explode("\n", $output);
$w1 = array_diff($w,$o);
$o1 = array_diff($o,$w);
$w2 = array();
$o2 = array();
foreach($w1 as $idx => $val) $w2[sprintf("%03d<",$idx)] = sprintf("%03d- ", $idx+1).$val;
foreach($o1 as $idx => $val) $o2[sprintf("%03d>",$idx)] = sprintf("%03d+ ", $idx+1).$val;
$diff = array_merge($w2, $o2);
ksort($diff);
return implode("\r\n", $diff);
}
function error($message)
@ -525,7 +522,8 @@ function error($message)
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
* vim600: fdm=marker
* vim: noet sw=4 ts=4
*/
?>
Loading…
Cancel
Save