From: Steph Fox Date: Wed, 11 Jun 2008 14:35:08 +0000 (+0000) Subject: - code beauty (ws/cs) X-Git-Tag: BEFORE_HEAD_NS_CHANGE~1548 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09dd52d7b6f8dd043f77eaed1676327b3e276a16;p=php - code beauty (ws/cs) --- diff --git a/run-tests.php b/run-tests.php index ccbec42d76..c5dba76ee3 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2,7 +2,7 @@ '; save_text($info_file, $php_info); $info_params = array(); - settings2array($ini_overwrites,$info_params); + settings2array($ini_overwrites, $info_params); settings2params($info_params); $php_info = `$php $pass_options $info_params "$info_file"`; define('TESTED_PHP_VERSION', `$php -r "echo PHP_VERSION;"`); + if ($php_cgi && $php != $php_cgi) { $php_info_cgi = `$php_cgi $pass_options $info_params -q "$info_file"`; $php_info_sep = "\n---------------------------------------------------------------------"; @@ -208,14 +215,15 @@ More .INIs : " , (function_exists(\'php_ini_scanned_files\') ? str_replace("\n" } else { $php_cgi_info = ''; } + @unlink($info_file); $unicode = 1; define('TESTED_UNICODE', 1); // load list of enabled extensions - save_text($info_file, ''); - $exts_to_test = explode(',',`$php $pass_options $info_params "$info_file"`); + save_text($info_file, ''); + $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'), @@ -223,11 +231,13 @@ More .INIs : " , (function_exists(\'php_ini_scanned_files\') ? str_replace("\n" '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. @@ -259,9 +269,11 @@ $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; $unicode_and_native = false; @@ -277,38 +289,45 @@ $no_clean = false; $cfgtypes = array('show', 'keep'); $cfgfiles = array('skip', 'php', 'clean', 'out', 'diff', 'exp'); $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)) - { +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) { + if (!$is_switch) { $switch = substr($argv[$i],1,1); } + $is_switch = true; + if ($repeat) { foreach($cfgtypes as $type) { - if (strpos($switch, '--'.$type) === 0) { + if (strpos($switch, '--' . $type) === 0) { foreach($cfgfiles as $file) { - if ($switch == '--'.$type.'-'.$file) { + if ($switch == '--' . $type.'-' . $file) { $cfg[$type][$file] = true; $is_switch = false; break; @@ -317,11 +336,14 @@ if (isset($argc) && $argc > 1) { } } } + if (!$is_switch) { $is_switch = true; break; } + $repeat = false; + switch($switch) { case 'r': case 'l': @@ -482,7 +504,7 @@ Options: -U Test in unicode and non unicode mode. -m Test for memory leaks with Valgrind. - + -N Test with unicode.semantics set off. -p Specify PHP executable to run. @@ -514,7 +536,7 @@ Options: --show-[all|php|skip|clean|exp|diff|out] Show 'all' files, 'php' test file, 'skip' or 'clean' file. You can also use this to show the output 'out', the expected result - 'exp' or the difference between them 'exp'. The result types + 'exp' or the difference between them 'diff'. The result types get written independent of the log format, however 'diff' only exists when a test fails. @@ -524,9 +546,12 @@ 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])) { @@ -534,9 +559,11 @@ HELP; } 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)) { @@ -546,34 +573,41 @@ HELP; } } } - if (strlen($conf_passed)) - { + + if (strlen($conf_passed)) { $pass_options .= " -c '$conf_passed'"; } + $test_files = array_unique($test_files); $test_files = array_merge($test_files, $redir_tests); // Run selected tests. $test_cnt = count($test_files); + if ($test_cnt) { verify_config(); write_information($html_output); usort($test_files, "test_sort"); $start_time = time(); + if (!$html_output) { echo "Running selected tests.\n"; } else { show_start($start_time); } + $test_idx = 0; run_all_tests($test_files, $environment); $end_time = time(); + if ($html_output) { show_end($end_time); } + if ($failed_tests_file) { fclose($failed_tests_file); } + if (count($test_files) || count($test_results)) { compute_summary(); if ($html_output) { @@ -582,12 +616,15 @@ HELP; echo "====================================================================="; echo get_summary(false, false); } + if ($html_output) { fclose($html_file); } + if (getenv('REPORT_EXIT_STATUS') == 1 and preg_match('/FAILED(?: |$)/', implode(' ', $test_results))) { exit(1); } + exit(0); } } @@ -603,6 +640,7 @@ $ignored_by_ext = 0; sort($exts_to_test); $test_dirs = array(); $optionals = array('tests', 'ext', 'Zend', 'ZendEngine2', 'sapi/cli', 'sapi/cgi'); + foreach($optionals as $dir) { if (@filetype($dir) == 'dir') { $test_dirs[] = $dir; @@ -622,18 +660,20 @@ foreach ($user_tests as $dir) { find_files($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(strtolower($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. @@ -652,6 +692,7 @@ function find_files($dir,$is_ext_dir=FALSE,$ignore=FALSE) } } } + closedir($o); } @@ -671,8 +712,9 @@ function test_sort($a, $b) $a = test_name($a); $b = test_name($b); - $ta = strpos($a, "{$cwd}/tests")===0 ? 1 + (strpos($a, "{$cwd}/tests/run-test")===0 ? 1 : 0) : 0; - $tb = strpos($b, "{$cwd}/tests")===0 ? 1 + (strpos($b, "{$cwd}/tests/run-test")===0 ? 1 : 0) : 0; + $ta = strpos($a, "{$cwd}/tests") === 0 ? 1 + (strpos($a, "{$cwd}/tests/run-test") === 0 ? 1 : 0) : 0; + $tb = strpos($b, "{$cwd}/tests") === 0 ? 1 + (strpos($b, "{$cwd}/tests/run-test") === 0 ? 1 : 0) : 0; + if ($ta == $tb) { return strcmp($a, $b); } else { @@ -690,6 +732,7 @@ $test_cnt = count($test_files); $test_idx = 0; run_all_tests($test_files, $environment); $end_time = time(); + if ($failed_tests_file) { fclose($failed_tests_file); } @@ -724,21 +767,23 @@ if (!getenv('NO_INTERACTION')) { echo "immediately, you can choose \"s\" to save the report to\na file that you can send us later.\n"; echo "Do you want to send this report now? [Yns]: "; flush(); + $user_input = fgets($fp, 10); $just_save_results = (strtolower($user_input[0]) == 's'); } -if ($just_save_results || !getenv('NO_INTERACTION')) { + +if ($just_save_results || !getenv('NO_INTERACTION')) { if ($just_save_results || strlen(trim($user_input)) == 0 || strtolower($user_input[0]) == 'y') { - /* + /* * Collect information about the host system for our report * Fetch phpinfo() output so that we can see the PHP enviroment * Make an archive of all the failed tests * Send an email */ - if ($just_save_results) - { + if ($just_save_results) { $user_input = 's'; } + /* Ask the user to provide an email address, so that QA team can contact the user */ if (!strncasecmp($user_input, 'y', 1) || strlen(trim($user_input)) == 0) { echo "\nPlease enter your email address.\n(Your address will be mangled so that it will not go out on any\nmailinglist in plain text): "; @@ -746,25 +791,26 @@ if ($just_save_results || !getenv('NO_INTERACTION')) { $user_email = trim(fgets($fp, 1024)); $user_email = str_replace("@", " at ", str_replace(".", " dot ", $user_email)); } - + $failed_tests_data = ''; $sep = "\n" . str_repeat('=', 80) . "\n"; - $failed_tests_data .= $failed_test_summary . "\n"; $failed_tests_data .= get_summary(true, false) . "\n"; if ($sum_results['FAILED']) { + foreach ($PHP_FAILED_TESTS['FAILED'] as $test_info) { $failed_tests_data .= $sep . ($test_info['unicode']?'U:':'N:') . $test_info['name'] . $test_info['info']; $failed_tests_data .= $sep . file_get_contents(realpath($test_info['output'])); $failed_tests_data .= $sep . file_get_contents(realpath($test_info['diff'])); $failed_tests_data .= $sep . "\n\n"; } + $status = "failed"; } else { $status = "success"; } - + $failed_tests_data .= "\n" . $sep . 'BUILD ENVIRONMENT' . $sep; $failed_tests_data .= "OS:\n" . PHP_OS . " - " . php_uname() . "\n\n"; $ldd = $autoconf = $sys_libtool = $libtool = $compiler = 'N/A'; @@ -782,6 +828,7 @@ if ($just_save_results || !getenv('NO_INTERACTION')) { /* Use shtool to find out if there is glibtool present (MacOSX) */ $sys_libtool_path = shell_exec(__DIR__ . '/build/shtool path glibtool libtool'); + if ($sys_libtool_path) { $sys_libtool = shell_exec(str_replace("\n", "", $sys_libtool_path) . ' --version'); } @@ -789,6 +836,7 @@ if ($just_save_results || !getenv('NO_INTERACTION')) { /* Try the most common flags for 'version' */ $flags = array('-v', '-V', '--version'); $cc_status=0; + foreach($flags AS $flag) { system(getenv('CC')." $flag >/dev/null 2>&1", $cc_status); if ($cc_status == 0) { @@ -796,8 +844,10 @@ if ($just_save_results || !getenv('NO_INTERACTION')) { break; } } + $ldd = shell_exec("ldd $php 2>/dev/null"); } + $failed_tests_data .= "Autoconf:\n$autoconf\n"; $failed_tests_data .= "Bundled Libtool:\n$libtool\n"; $failed_tests_data .= "System Libtool:\n$sys_libtool\n"; @@ -805,14 +855,14 @@ if ($just_save_results || !getenv('NO_INTERACTION')) { $failed_tests_data .= "Bison:\n". @shell_exec('bison --version 2>/dev/null'). "\n"; $failed_tests_data .= "Libraries:\n$ldd\n"; $failed_tests_data .= "\n"; - + if (isset($user_email)) { - $failed_tests_data .= "User's E-mail: ".$user_email."\n\n"; - } - + $failed_tests_data .= "User's E-mail: " . $user_email."\n\n"; + } + $failed_tests_data .= $sep . "PHPINFO" . $sep; $failed_tests_data .= shell_exec($php.' -dhtml_errors=0 -i'); - + if ($just_save_results || !mail_qa_team($failed_tests_data, $compression, $status)) { file_put_contents($output_file, $failed_tests_data); @@ -820,11 +870,11 @@ if ($just_save_results || !getenv('NO_INTERACTION')) { echo "\nThe test script was unable to automatically send the report to PHP's QA Team\n"; } - echo "Please send ".$output_file." to ".PHP_QA_EMAIL." manually, thank you.\n"; + echo "Please send " . $output_file . " to " . PHP_QA_EMAIL . " manually, thank you.\n"; } else { fwrite($fp, "\nThank you for helping to make PHP better.\n"); fclose($fp); - } + } } } @@ -837,35 +887,39 @@ exit(0); // Send Email to QA Team // -function mail_qa_team($data, $compression, $status = FALSE) +function mail_qa_team($data, $compression, $status = false) { $url_bits = parse_url(QA_SUBMISSION_PAGE); - if (empty($url_bits['port'])) $url_bits['port'] = 80; - + + if (empty($url_bits['port'])) { + $url_bits['port'] = 80; + } + $data = "php_test_data=" . urlencode(base64_encode(str_replace("\00", '[0x0]', $data))); $data_length = strlen($data); $fs = fsockopen($url_bits['host'], $url_bits['port'], $errno, $errstr, 10); + if (!$fs) { - return FALSE; + return false; } $php_version = urlencode(TESTED_PHP_VERSION); echo "\nPosting to {$url_bits['host']} {$url_bits['path']}\n"; - fwrite($fs, "POST ".$url_bits['path']."?status=$status&version=$php_version HTTP/1.1\r\n"); - fwrite($fs, "Host: ".$url_bits['host']."\r\n"); + fwrite($fs, "POST " . $url_bits['path'] . "?status=$status&version=$php_version HTTP/1.1\r\n"); + fwrite($fs, "Host: " . $url_bits['host'] . "\r\n"); fwrite($fs, "User-Agent: QA Browser 0.1\r\n"); fwrite($fs, "Content-Type: application/x-www-form-urlencoded\r\n"); - fwrite($fs, "Content-Length: ".$data_length."\r\n\r\n"); + fwrite($fs, "Content-Length: " . $data_length . "\r\n\r\n"); fwrite($fs, $data); fwrite($fs, "\r\n\r\n"); fclose($fs); return 1; } - - + + // // Write the given text to a temporary file, and return the filename. // @@ -879,9 +933,11 @@ function save_text($filename, $text, $filename_copy = null) error("Cannot open file '" . $filename_copy . "' (save_text)"); } } + if (@file_put_contents($filename, $text) === false) { error("Cannot open file '" . $filename . "' (save_text)"); } + if (1 < $DETAILED) echo " FILE $filename {{{ $text @@ -897,15 +953,16 @@ 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; + 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; } } @@ -914,19 +971,20 @@ function system_with_timeout($commandline, $env = null, $stdin = null) global $leak_check; $data = ""; - $proc = proc_open($commandline, array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ), $pipes, null, $env, array("suppress_errors" => true, "binary_pipes" => true)); - if (!$proc) + if (!$proc) { return false; + } if (!is_null($stdin)) { @fwrite($pipes[0], $stdin); } + fclose($pipes[0]); while (true) { @@ -945,63 +1003,65 @@ function system_with_timeout($commandline, $env = null, $stdin = null) return $data; } else if ($n > 0) { $line = fread($pipes[1], 8192); + if ($line === false) { /* EOF */ break; } + $data .= $line; } } + $stat = proc_get_status($proc); + if ($stat['signaled']) { - $data .= "\nTermsig=".$stat['stopsig']; + $data .= "\nTermsig=" . $stat['stopsig']; } + $code = proc_close($proc); return $data; } -function run_all_tests($test_files, $env, $redir_tested = NULL) +function run_all_tests($test_files, $env, $redir_tested = null) { global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx, $unicode_and_native, $unicode_testing; - if ($unicode_and_native && is_null($redir_tested)) - { + if ($unicode_and_native && is_null($redir_tested)) { $test_cnt *= 2; } - foreach($test_files as $name) - { - if (is_array($name)) - { + + foreach($test_files as $name) { + + if (is_array($name)) { $index = "# $name[1]: $name[0]"; - if ($redir_tested) - { + + if ($redir_tested) { $name = $name[0]; } } - else if ($redir_tested) - { + else if ($redir_tested) { $index = "# $redir_tested: $name"; - } - else - { + } else { $index = $name; } + $unicode_semantics = $unicode_and_native ? 0 : ($unicode_testing ? 1 : 0); - for(; $unicode_semantics < ($unicode_testing ? 2 : 1); $unicode_semantics++) - { + for(; $unicode_semantics < ($unicode_testing ? 2 : 1); $unicode_semantics++) { + $test_idx++; $result = run_test($php, $name, $env, $unicode_semantics); - if (!is_array($name) && $result != 'REDIR') - { + + if (!is_array($name) && $result != 'REDIR') { $pu = $unicode_and_native && $unicode_semantics ? '.u' : ''; $test_results[$index.$pu] = $result; - if ($failed_tests_file && ($result== 'XFAILED' || $result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED')) - { + + if ($failed_tests_file && ($result== 'XFAILED' || $result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED')) { fwrite($failed_tests_file, "$index\n"); } } - if ($result == 'REDIR') - { + + if ($result == 'REDIR') { $unicode_semantics = 2; } } @@ -1011,15 +1071,17 @@ function run_all_tests($test_files, $env, $redir_tested = NULL) // // Show file or result block // -function show_file_block($file, $block, $section=NULL) +function show_file_block($file, $block, $section = null) { global $cfg; if ($cfg['show'][$file]) { + if (is_null($section)) { $section = strtoupper($file); } - echo "\n========".$section."========\n"; + + echo "\n========" . $section . "========\n"; echo rtrim($block); echo "\n========DONE========\n"; } @@ -1044,7 +1106,9 @@ function run_test($php, $file, $env, $unicode_semantics) $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE']; } - if (is_array($file)) $file = $file[0]; + if (is_array($file)) { + $file = $file[0]; + } if ($DETAILED) echo " ================= @@ -1055,11 +1119,12 @@ TEST $file $section_text = array('TEST' => ''); $fp = fopen($file, "rt") or error("Cannot open test file: $file"); - $borked = false; $bork_info = ''; + if (!feof($fp)) { $line = fgets($fp); + if ($line === false) { $bork_info = "cannot read test"; $borked = true; @@ -1068,13 +1133,16 @@ TEST $file $bork_info = "empty test"; $borked = true; } + if (!$borked && strncmp('--TEST--', $line, 8)) { $bork_info = "tests must start with --TEST--"; $borked = true; } + $section = 'TEST'; $secfile = false; $secdone = false; + while (!feof($fp)) { $line = fgets($fp); @@ -1092,7 +1160,7 @@ TEST $file $secdone = false; continue; } - + // Add to the section text. if (!$secdone) { $section_text[$section] .= $line; @@ -1108,24 +1176,30 @@ TEST $file // a given test dir if (!$borked) { if (@count($section_text['REDIRECTTEST']) == 1) { + if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } + } else { + if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { $bork_info = "missing section --FILE--"; $borked = true; } + if (@count($section_text['FILEEOF']) == 1) { $section_text['FILE'] = preg_replace("/[\r\n]+$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } + if (@count($section_text['FILE_EXTERNAL']) == 1) { // don't allow tests to retrieve files from anywhere but this subdirectory $section_text['FILE_EXTERNAL'] = dirname($file) . '/' . trim(str_replace('..', '', $section_text['FILE_EXTERNAL'])); + if (@file_exists($section_text['FILE_EXTERNAL'])) { $section_text['FILE'] = file_get_contents($section_text['FILE_EXTERNAL']); unset($section_text['FILE_EXTERNAL']); @@ -1134,16 +1208,19 @@ TEST $file $borked = true; } } + if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; } + if ((@count($section_text['UEXPECT']) + @count($section_text['UEXPECTF']) + @count($section_text['UEXPECTREGEX'])) > 1) { $bork_info = "missing section --UEXPECT--, --UEXPECTF-- or --UEXPECTREGEX--"; $borked = true; } } } + fclose($fp); $shortname = str_replace($cwd.'/', '', $file); @@ -1152,12 +1229,12 @@ TEST $file if ($borked) { show_result("BORK", $bork_info, $tested_file, $unicode_semantics); $PHP_FAILED_TESTS['BORKED'][] = array ( - 'name' => $file, + 'name' => $file, 'test_name' => '', - 'output' => '', - 'diff' => '', - 'info' => "$bork_info [$file]", - 'unicode'=> $unicode_semantics, + 'output' => '', + 'diff' => '', + 'info' => "$bork_info [$file]", + 'unicode' => $unicode_semantics, ); return 'BORKED'; } @@ -1166,13 +1243,17 @@ TEST $file /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { + if (isset($php_cgi)) { $old_php = $php; $php = $php_cgi .' -C '; + } else if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) ."/php-cgi.exe")) { $old_php = $php; $php = realpath(dirname($php) ."/php-cgi.exe") .' -C '; + } else { + if (file_exists(dirname($php)."/../../sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath(dirname($php)."/../../sapi/cgi/php-cgi") . ' -C '; @@ -1193,6 +1274,7 @@ TEST $file } else { $temp_dir = $test_dir = realpath(dirname($file)); } + if ($temp_source && $temp_target) { $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); } @@ -1217,13 +1299,16 @@ TEST $file $temp_skipif .= 's'; $temp_file .= 's'; $temp_clean .= 's'; - $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file).'.phps'; + $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file) . '.phps'; + if (!is_dir(dirname($copy_file))) { @mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); } + if (isset($section_text['FILE'])) { save_text($copy_file, $section_text['FILE']); } + $temp_filenames = array( 'file' => $copy_file, 'diff' => $diff_filename, @@ -1257,16 +1342,19 @@ TEST $file @unlink($test_clean); // 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']=''; + $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); + $e = explode('=', trim($e), 2); + if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } @@ -1297,12 +1385,15 @@ TEST $file } else { $unicode_test = $unicode_and_native ? $unicode_semantics : TESTED_UNICODE; } + settings2params($ini_settings); // Check if test should be skipped. $info = ''; $warn = false; + if (array_key_exists('SKIPIF', $section_text)) { + if (trim($section_text['SKIPIF'])) { show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); @@ -1318,28 +1409,36 @@ TEST $file } $output = system_with_timeout("$extra $php $pass_options -q $ini_settings $test_skipif", $env); + if (!$cfg['keep']['skip']) { @unlink($test_skipif); } + if (!strncasecmp('skip', ltrim($output), 4)) { + if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) { show_result("SKIP", $tested, $tested_file, $unicode_semantics, "reason: $m[1]", $temp_filenames); } else { show_result("SKIP", $tested, $tested_file, $unicode_semantics, '', $temp_filenames); } + if (isset($old_php)) { $php = $old_php; } + if (!$cfg['keep']['skip']) { @unlink($test_skipif); } + return 'SKIPPED'; } + if (!strncasecmp('info', ltrim($output), 4)) { if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) { $info = " (info: $m[1])"; } } + if (!strncasecmp('warn', ltrim($output), 4)) { if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ @@ -1358,33 +1457,36 @@ TEST $file $IN_REDIRECT['prefix'] = trim($section_text['TEST']); if (@count($IN_REDIRECT['TESTS']) == 1) { + if (is_array($org_file)) { $test_files[] = $org_file[1]; } else { $GLOBALS['test_files'] = $test_files; find_files($IN_REDIRECT['TESTS']); + foreach($GLOBALS['test_files'] as $f) { $test_files[] = array($f, $file); } } + $test_cnt += (count($test_files) - 1) * ($unicode_and_native ? 2 : 1); $test_idx--; - show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); // set up environment $redirenv = array_merge($environment, $IN_REDIRECT['ENV']); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR; - + usort($test_files, "test_sort"); run_all_tests($test_files, $redirenv, $tested); - show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); - + // a redirected test never fails $IN_REDIRECT = false; return 'REDIR'; + } else { + $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; show_result("BORK", $bork_info, '', $unicode_semantics, $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array ( @@ -1397,8 +1499,13 @@ TEST $file ); } } + if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { - if (is_array($org_file)) $file = $org_file[0]; + + if (is_array($org_file)) { + $file = $org_file[0]; + } + $bork_info = "Redirected test did not contain redirection info"; show_result("BORK", $bork_info, '', $unicode_semantics, $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array ( @@ -1409,11 +1516,9 @@ TEST $file 'info' => "$bork_info [$file]", 'unicode'=> $unicode_semantics, ); - //$test_cnt -= 1; // Only if is_array($org_file) ? - //$test_idx--; return 'BORKED'; } - + if ($unicode_test) { if (isset($section_text['UEXPECT'])) { unset($section_text['EXPECT']); @@ -1439,6 +1544,7 @@ TEST $file // We've satisfied the preconditions - run the test! show_file_block('php', $section_text['FILE'], 'TEST'); save_text($test_file, $section_text['FILE'], $temp_file); + if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { @@ -1456,20 +1562,27 @@ TEST $file $env['HTTP_COOKIE'] = ''; } - $args = isset($section_text['ARGS']) ? ' -- '.$section_text['ARGS'] : ''; + $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { + $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; + foreach ($raw_lines as $line) { + if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } - if ($started) $request .= "\n"; + + if ($started) { + $request .= "\n"; + } + $started = true; $request .= $line; } @@ -1480,8 +1593,10 @@ TEST $file if (empty($request)) { return 'BORKED'; } + save_text($tmp_post, $request); $cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post"; + } elseif (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); @@ -1514,12 +1629,14 @@ TEST $file if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; + if ($valgrind_version >= 330) { /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file=$memcheck_filename $cmd"; } else { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file-exactly=$memcheck_filename $cmd"; } + } else { $env['USE_ZEND_ALLOC'] = '1'; } @@ -1539,17 +1656,20 @@ COMMAND $cmd $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { + if (trim($section_text['CLEAN'])) { show_file_block('clean', $section_text['CLEAN']); save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); + if (!$no_clean) { $clean_params = array(); - settings2array($ini_overwrites,$clean_params); + settings2array($ini_overwrites, $clean_params); settings2params($clean_params); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;": ""; system_with_timeout("$extra $php $pass_options -q $clean_params $test_clean", $env); } + if (!$cfg['keep']['clean']) { @unlink($test_clean); } @@ -1563,6 +1683,7 @@ COMMAND $cmd if ($leak_check) { // leak check $leaked = @filesize($memcheck_filename) > 0; + if (!$leaked) { @unlink($memcheck_filename); } @@ -1573,12 +1694,14 @@ COMMAND $cmd /* when using CGI, strip the headers from the output */ $headers = ""; + if (isset($old_php) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { $output = trim($match[2]); - $rh = preg_split("/[\n\r]+/",$match[1]); + $rh = preg_split("/[\n\r]+/", $match[1]); $headers = array(); + foreach ($rh as $line) { - if (strpos($line, ':')!==false) { + if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $headers[trim($line[0])] = trim($line[1]); } @@ -1586,10 +1709,12 @@ COMMAND $cmd } $failed_headers = false; + if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); - $lines = preg_split("/[\n\r]+/",$section_text['EXPECTHEADERS']); + $lines = preg_split("/[\n\r]+/", $section_text['EXPECTHEADERS']); + foreach($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); @@ -1597,18 +1722,23 @@ COMMAND $cmd $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } + $org_headers = $headers; $headers = array(); $output_headers = array(); + foreach($want as $k => $v) { + if (isset($org_headers[$k])) { $headers = $org_headers[$k]; $output_headers[] = $k . ': ' . $org_headers[$k]; } + if (!isset($org_headers[$k]) || $org_headers[$k] != $v) { $failed_headers = true; } } + ksort($wanted_headers); $wanted_headers = join("\n", $wanted_headers); ksort($output_headers); @@ -1616,14 +1746,18 @@ COMMAND $cmd } show_file_block('out', $output); + if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { + if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } + show_file_block('exp', $wanted); - $wanted_re = preg_replace('/\r\n/',"\n",$wanted); + $wanted_re = preg_replace('/\r\n/', "\n", $wanted); + if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); // Stick to basics @@ -1645,40 +1779,54 @@ COMMAND $cmd */ if (preg_match("/^$wanted_re\$/s", $output)) { $passed = true; + } + + if ($passed) { if (!$cfg['keep']['php']) { @unlink($test_file); } + if (isset($old_php)) { $php = $old_php; } + if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, $unicode_semantics, '', $temp_filenames); return 'PASSED'; } } + } else { + $wanted = trim($section_text['EXPECT']); + if ($unicode_semantics && is_unicode($wanted)) { /* workaround until preg_replace() or str_replace() are upgraded */ $wanted = unicode_encode($wanted, ini_get('unicode.output_encoding') ?: 'utf-8'); } + $wanted = preg_replace('/\r\n/',"\n",$wanted); show_file_block('exp', $wanted); + // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; + if (!$cfg['keep']['php']) { @unlink($test_file); } + if (isset($old_php)) { $php = $old_php; } + if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, $unicode_semantics, '', $temp_filenames); return 'PASSED'; } } - $wanted_re = NULL; + + $wanted_re = null; } // Test failed so we need to report details. @@ -1686,6 +1834,7 @@ COMMAND $cmd $passed = false; $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; $output = $output_headers . "\n--HEADERS--\n" . $output; + if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } @@ -1694,43 +1843,47 @@ COMMAND $cmd if ($leaked) { $restype[] = 'LEAK'; } + if ($warn) { $restype[] = 'WARN'; } + if (!$passed) { - if(isset($section_text['XFAIL'])) { - $restype[] = 'XFAIL'; - }else{ - $restype[] = 'FAIL'; - } + if (isset($section_text['XFAIL'])) { + $restype[] = 'XFAIL'; + } else { + $restype[] = 'FAIL'; + } } if (!$passed) { + // write .exp - if (strpos($log_format,'E') !== FALSE && file_put_contents($exp_filename, $wanted) === FALSE) { + if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, $wanted) === false) { error("Cannot create expected test output - $exp_filename"); } // write .out - if (strpos($log_format,'O') !== FALSE && file_put_contents($output_filename, $output) === FALSE) { + if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, $output) === false) { error("Cannot create test output - $output_filename"); } // write .diff - $diff = generate_diff($wanted,$wanted_re,$output); + $diff = generate_diff($wanted, $wanted_re, $output); show_file_block('diff', $diff); - if (strpos($log_format,'D') !== FALSE && file_put_contents($diff_filename, $diff) === FALSE) { + + if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, $diff) === false) { error("Cannot create test diff - $diff_filename"); } // write .log - if (strpos($log_format,'L') !== FALSE && file_put_contents($log_filename, " + if (strpos($log_format,'L') !== false && file_put_contents($log_filename, " ---- EXPECTED OUTPUT $wanted ---- ACTUAL OUTPUT $output ---- FAILED -") === FALSE) { +") === false) { error("Cannot create test log - $log_filename"); error_report($file, $log_filename, $tested); } @@ -1740,12 +1893,12 @@ $output foreach ($restype as $type) { $PHP_FAILED_TESTS[$type.'ED'][] = array ( - 'name' => $file, + 'name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]", - 'output' => $output_filename, - 'diff' => $diff_filename, - 'info' => $info, - 'unicode'=> $unicode_semantics, + 'output' => $output_filename, + 'diff' => $diff_filename, + 'info' => $info, + 'unicode' => $unicode_semantics, ); } @@ -1756,18 +1909,19 @@ $output return $restype[0].'ED'; } -function comp_line($l1,$l2,$is_reg) +function comp_line($l1, $l2, $is_reg) { if ($is_reg) { - return preg_match('/^'.$l1.'$/s', $l2); + return preg_match("/^$l1$/s", $l2); } else { return !strcmp($l1, $l2); } } -function count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$idx2,$cnt1,$cnt2,$steps) +function count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) { $equal = 0; + while ($idx1 < $cnt1 && $idx2 < $cnt2 && comp_line($ar1[$idx1], $ar2[$idx2], $is_reg)) { $idx1++; $idx2++; @@ -1777,94 +1931,109 @@ function count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$idx2,$cnt1,$cnt2,$steps) if (--$steps > 0) { $eq1 = 0; $st = $steps / 2; - for ($ofs1 = $idx1+1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { - $eq = count_array_diff($ar1,$ar2,$is_reg,$w,$ofs1,$idx2,$cnt1,$cnt2,$st); + + for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { + $eq = count_array_diff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); + if ($eq > $eq1) { $eq1 = $eq; } } + $eq2 = 0; $st = $steps; - for ($ofs2 = $idx2+1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { - $eq = count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$ofs2,$cnt1,$cnt2,$st); + + for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { + $eq = count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); if ($eq > $eq2) { $eq2 = $eq; } } + if ($eq1 > $eq2) { $equal += $eq1; } else if ($eq2 > 0) { $equal += $eq2; } } + return $equal; } -function generate_array_diff($ar1,$ar2,$is_reg,$w) +function generate_array_diff($ar1, $ar2, $is_reg, $w) { $idx1 = 0; $ofs1 = 0; $cnt1 = count($ar1); $idx2 = 0; $ofs2 = 0; $cnt2 = count($ar2); $diff = array(); $old1 = array(); $old2 = array(); - + while ($idx1 < $cnt1 && $idx2 < $cnt2) { + if (comp_line($ar1[$idx1], $ar2[$idx2], $is_reg)) { $idx1++; $idx2++; continue; } else { - $c1 = count_array_diff($ar1,$ar2,$is_reg,$w,$idx1+1,$idx2,$cnt1,$cnt2,10); - $c2 = count_array_diff($ar1,$ar2,$is_reg,$w,$idx1,$idx2+1,$cnt1,$cnt2,10); + + $c1 = count_array_diff($ar1, $ar2, $is_reg, $w, $idx1+1, $idx2, $cnt1, $cnt2, 10); + $c2 = count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2+1, $cnt1, $cnt2, 10); + if ($c1 > $c2) { - $old1[$idx1] = sprintf("%03d- ", $idx1+1).$w[$idx1++]; + $old1[$idx1] = sprintf("%03d- ", $idx1+1) . $w[$idx1++]; $last = 1; } else if ($c2 > 0) { - $old2[$idx2] = sprintf("%03d+ ", $idx2+1).$ar2[$idx2++]; + $old2[$idx2] = sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; $last = 2; } else { - $old1[$idx1] = sprintf("%03d- ", $idx1+1).$w[$idx1++]; - $old2[$idx2] = sprintf("%03d+ ", $idx2+1).$ar2[$idx2++]; + $old1[$idx1] = sprintf("%03d- ", $idx1+1) . $w[$idx1++]; + $old2[$idx2] = sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; } } } - + reset($old1); $k1 = key($old1); $l1 = -2; - reset($old2); $k2 = key($old2); $l2 = -2; - while ($k1 !== NULL || $k2 !== NULL) { - if ($k1 == $l1+1 || $k2 === NULL) { + reset($old2); $k2 = key($old2); $l2 = -2; + + while ($k1 !== null || $k2 !== null) { + + if ($k1 == $l1 + 1 || $k2 === null) { $l1 = $k1; $diff[] = current($old1); - $k1 = next($old1) ? key($old1) : NULL; - } else if ($k2 == $l2+1 || $k1 === NULL) { + $k1 = next($old1) ? key($old1) : null; + } else if ($k2 == $l2 + 1 || $k1 === null) { $l2 = $k2; $diff[] = current($old2); - $k2 = next($old2) ? key($old2) : NULL; + $k2 = next($old2) ? key($old2) : null; } else if ($k1 < $k2) { $l1 = $k1; $diff[] = current($old1); - $k1 = next($old1) ? key($old1) : NULL; + $k1 = next($old1) ? key($old1) : null; } else { $l2 = $k2; $diff[] = current($old2); - $k2 = next($old2) ? key($old2) : NULL; + $k2 = next($old2) ? key($old2) : null; } } + while ($idx1 < $cnt1) { - $diff[] = sprintf("%03d- ", $idx1+1).$w[$idx1++]; + $diff[] = sprintf("%03d- ", $idx1 + 1) . $w[$idx1++]; } + while ($idx2 < $cnt2) { - $diff[] = sprintf("%03d+ ", $idx2+1).$ar2[$idx2++]; + $diff[] = sprintf("%03d+ ", $idx2 + 1) . $ar2[$idx2++]; } + return $diff; } -function generate_diff($wanted,$wanted_re,$output) +function generate_diff($wanted, $wanted_re, $output) { $w = explode("\n", $wanted); $o = explode("\n", $output); $r = is_null($wanted_re) ? $w : explode("\n", $wanted_re); - $diff = generate_array_diff($r,$o,!is_null($wanted_re),$w); + $diff = generate_array_diff($r, $o, !is_null($wanted_re), $w); + return implode("\r\n", $diff); } @@ -1877,15 +2046,20 @@ function error($message) function settings2array($settings, &$ini_settings) { foreach($settings as $setting) { - if (strpos($setting, '=')!==false) { + + if (strpos($setting, '=') !== false) { $setting = explode("=", $setting, 2); $name = trim(strtolower($setting[0])); $value = trim($setting[1]); + if ($name == 'extension') { + if (!isset($ini_settings[$name])) { $ini_settings[$name] = array(); } + $ini_settings[$name][] = $value; + } else { $ini_settings[$name] = $value; } @@ -1896,7 +2070,9 @@ function settings2array($settings, &$ini_settings) function settings2params(&$ini_settings) { $settings = ''; + foreach($ini_settings as $name => $value) { + if (is_array($value)) { foreach($value as $val) { $val = addslashes($val); @@ -1907,6 +2083,7 @@ function settings2params(&$ini_settings) $settings .= " -d \"$name=$value\""; } } + $ini_settings = $settings; } @@ -1916,13 +2093,16 @@ function compute_summary() $n_total = count($test_results); $n_total += $ignored_by_ext; - $sum_results = array('PASSED'=>0, 'WARNED'=>0, 'SKIPPED'=>0, 'FAILED'=>0, 'BORKED'=>0, 'LEAKED'=>0, 'XFAILED' => 0); + $sum_results = array('PASSED' => 0, 'WARNED' => 0, 'SKIPPED' => 0, 'FAILED' => 0, 'BORKED' => 0, 'LEAKED' => 0, 'XFAILED' => 0); + foreach ($test_results as $v) { $sum_results[$v]++; } + $sum_results['SKIPPED'] += $ignored_by_ext; $percent_results = array(); - while (list($v,$n) = each($sum_results)) { + + while (list($v, $n) = each($sum_results)) { $percent_results[$v] = (100.0 * $n) / $n_total; } } @@ -1932,6 +2112,7 @@ function get_summary($show_ext_summary, $show_html) global $exts_skipped, $exts_tested, $n_total, $sum_results, $percent_results, $end_time, $start_time, $failed_test_summary, $PHP_FAILED_TESTS, $leak_check; $x_total = $n_total - $sum_results['SKIPPED'] - $sum_results['BORKED']; + if ($x_total) { $x_warned = (100.0 * $sum_results['WARNED']) / $x_total; $x_failed = (100.0 * $sum_results['FAILED']) / $x_total; @@ -1939,44 +2120,53 @@ function get_summary($show_ext_summary, $show_html) $x_leaked = (100.0 * $sum_results['LEAKED']) / $x_total; $x_passed = (100.0 * $sum_results['PASSED']) / $x_total; } else { - $x_warned = $x_failed = $x_passed = $x_leaked = $x_failed = 0; + $x_warned = $x_failed = $x_passed = $x_leaked = $x_xfailed = 0; } $summary = ""; - if ($show_html) $summary .= "
\n";
+
+	if ($show_html) {
+		$summary .= "
\n";
+	}
+
 	if ($show_ext_summary) {
 		$summary .= "
 =====================================================================
 TEST RESULT SUMMARY
 ---------------------------------------------------------------------
-Exts skipped    : " . sprintf("%4d",$exts_skipped) . "
-Exts tested     : " . sprintf("%4d",$exts_tested) . "
+Exts skipped    : " . sprintf("%4d", $exts_skipped) . "
+Exts tested     : " . sprintf("%4d", $exts_tested) . "
 ---------------------------------------------------------------------
 ";
 	}
+
 	$summary .= "
-Number of tests : " . sprintf("%4d",$n_total). "          " . sprintf("%8d",$x_total);
+Number of tests : " . sprintf("%4d", $n_total). "          " . sprintf("%8d", $x_total);
+
 	if ($sum_results['BORKED']) {
-	$summary .= "
-Tests borked    : " . sprintf("%4d (%5.1f%%)",$sum_results['BORKED'],$percent_results['BORKED']) . " --------";
+		$summary .= "
+Tests borked    : " . sprintf("%4d (%5.1f%%)", $sum_results['BORKED'], $percent_results['BORKED']) . " --------";
 	}
+
 	$summary .= "
-Tests skipped   : " . sprintf("%4d (%5.1f%%)",$sum_results['SKIPPED'],$percent_results['SKIPPED']) . " --------
-Tests warned    : " . sprintf("%4d (%5.1f%%)",$sum_results['WARNED'], $percent_results['WARNED']) . " " . sprintf("(%5.1f%%)",$x_warned) . "
-Tests failed    : " . sprintf("%4d (%5.1f%%)",$sum_results['FAILED'], $percent_results['FAILED']) . " " . sprintf("(%5.1f%%)",$x_failed) . "
-Expected fail   : " . sprintf("%4d (%5.1f%%)",$sum_results['XFAILED'], $percent_results['XFAILED']) . " " . sprintf("(%5.1f%%)",$x_xfailed);
+Tests skipped   : " . sprintf("%4d (%5.1f%%)", $sum_results['SKIPPED'], $percent_results['SKIPPED']) . " --------
+Tests warned    : " . sprintf("%4d (%5.1f%%)", $sum_results['WARNED'], $percent_results['WARNED']) . " " . sprintf("(%5.1f%%)", $x_warned) . "
+Tests failed    : " . sprintf("%4d (%5.1f%%)", $sum_results['FAILED'], $percent_results['FAILED']) . " " . sprintf("(%5.1f%%)", $x_failed) . "
+Expected fail   : " . sprintf("%4d (%5.1f%%)", $sum_results['XFAILED'], $percent_results['XFAILED']) . " " . sprintf("(%5.1f%%)", $x_xfailed);
 
 	if ($leak_check) {
 		$summary .= "
-Tests leaked    : " . sprintf("%4d (%5.1f%%)",$sum_results['LEAKED'], $percent_results['LEAKED']) . " " . sprintf("(%5.1f%%)",$x_leaked);
+Tests leaked    : " . sprintf("%4d (%5.1f%%)", $sum_results['LEAKED'], $percent_results['LEAKED']) . " " . sprintf("(%5.1f%%)", $x_leaked);
 	}
+
 	$summary .= "
-Tests passed    : " . sprintf("%4d (%5.1f%%)",$sum_results['PASSED'], $percent_results['PASSED']) . " " . sprintf("(%5.1f%%)",$x_passed) . "
+Tests passed    : " . sprintf("%4d (%5.1f%%)", $sum_results['PASSED'], $percent_results['PASSED']) . " " . sprintf("(%5.1f%%)", $x_passed) . "
 ---------------------------------------------------------------------
 Time taken      : " . sprintf("%4d seconds", $end_time - $start_time) . "
 =====================================================================
 ";
 	$failed_test_summary = '';
+
 	if (count($PHP_FAILED_TESTS['BORKED'])) {
 		$failed_test_summary .= "
 =====================================================================
@@ -1986,9 +2176,10 @@ BORKED TEST SUMMARY
 		foreach ($PHP_FAILED_TESTS['BORKED'] as $test_data) {
 			$failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['info'] . "\n";
 		}
+
 		$failed_test_summary .=  "=====================================================================\n";
 	}
-	
+
 	if (count($PHP_FAILED_TESTS['FAILED'])) {
 		$failed_test_summary .= "
 =====================================================================
@@ -1998,6 +2189,7 @@ FAILED TEST SUMMARY
 		foreach ($PHP_FAILED_TESTS['FAILED'] as $test_data) {
 			$failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['test_name'] . $test_data['info'] . "\n";
 		}
+
 		$failed_test_summary .=  "=====================================================================\n";
 	}
 
@@ -2010,9 +2202,10 @@ EXPECTED FAILED TEST SUMMARY
 		foreach ($PHP_FAILED_TESTS['XFAILED'] as $test_data) {
 			$failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['test_name'] . $test_data['info'] . "\n";
 		}
+
 		$failed_test_summary .=  "=====================================================================\n";
 	}
-	
+
 	if (count($PHP_FAILED_TESTS['LEAKED'])) {
 		$failed_test_summary .= "
 =====================================================================
@@ -2022,14 +2215,17 @@ LEAKED TEST SUMMARY
 		foreach ($PHP_FAILED_TESTS['LEAKED'] as $test_data) {
 			$failed_test_summary .= ($test_data['unicode']?'U:':'N:') . $test_data['test_name'] . $test_data['info'] . "\n";
 		}
+
 		$failed_test_summary .=  "=====================================================================\n";
 	}
-	
+
 	if ($failed_test_summary && !getenv('NO_PHPTEST_SUMMARY')) {
 		$summary .= $failed_test_summary;
 	}
 
-	if ($show_html) $summary .= "
"; + if ($show_html) { + $summary .= "
"; + } return $summary; } @@ -2038,11 +2234,11 @@ function show_start($start_time) { global $html_output, $html_file; - if ($html_output) - { + if ($html_output) { fwrite($html_file, "

Time Start: " . @date('Y-m-d H:i:s', $start_time) . "

\n"); fwrite($html_file, "\n"); } + echo "TIME START " . @date('Y-m-d H:i:s', $start_time) . "\n=====================================================================\n"; } @@ -2050,11 +2246,11 @@ function show_end($end_time) { global $html_output, $html_file; - if ($html_output) - { + if ($html_output) { fwrite($html_file, "
\n"); fwrite($html_file, "

Time End: " . @date('Y-m-d H:i:s', $end_time) . "

\n"); } + echo "=====================================================================\nTIME END " . @date('Y-m-d H:i:s', $end_time) . "\n"; } @@ -2062,10 +2258,10 @@ function show_summary() { global $html_output, $html_file; - if ($html_output) - { + if ($html_output) { fwrite($html_file, "
\n" . get_summary(true, true)); } + echo get_summary(true, false); } @@ -2073,10 +2269,10 @@ function show_redirect_start($tests, $tested, $tested_file) { global $html_output, $html_file; - if ($html_output) - { + if ($html_output) { fwrite($html_file, "---> $tests ($tested [$tested_file]) begin\n"); } + echo "---> $tests ($tested [$tested_file]) begin\n"; } @@ -2084,10 +2280,10 @@ function show_redirect_ends($tests, $tested, $tested_file) { global $html_output, $html_file; - if ($html_output) - { + if ($html_output) { fwrite($html_file, "---> $tests ($tested [$tested_file]) done\n"); } + echo "---> $tests ($tested [$tested_file]) done\n"; } @@ -2108,33 +2304,40 @@ function show_result($result, $tested, $tested_file, $unicode_semantics, $extra echo "$result$kind $tested [$tested_file] $extra\n"; - if ($html_output) - { + if ($html_output) { + if (isset($temp_filenames['file']) && @file_exists($temp_filenames['file'])) { $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['file']); $tested = "$tested"; } + if (isset($temp_filenames['skip']) && @file_exists($temp_filenames['skip'])) { + if (empty($extra)) { $extra = "skipif"; } + $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['skip']); $extra = "$extra"; + } else if (empty($extra)) { $extra = " "; } + if (isset($temp_filenames['diff']) && @file_exists($temp_filenames['diff'])) { $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['diff']); $diff = "diff"; } else { $diff = " "; } + if (isset($temp_filenames['mem']) && @file_exists($temp_filenames['mem'])) { $url = str_replace($temp_target, $temp_urlbase, $temp_filenames['mem']); $mem = "leaks"; } else { $mem = " "; } + fwrite($html_file, "" . "$result" .