cvs: php-src(PHP_5_2) / run-tests.php

From: Date: Sat, 13 May 2006 14:01:58 +0000
Subject: cvs: php-src(PHP_5_2) / run-tests.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-38186@lists.php.net to get a copy of this message
helly Sat May 13 14:01:58 2006 UTC Modified files: (Branch: PHP_5_2) /php-src run-tests.php Log: - MFH add support for --EXPECTHEADERS-- http://cvs.php.net/viewcvs.cgi/php-src/run-tests.php?r1=1.226.2.37.2.1&r2=1.226.2.37.2.2&diff_format=u Index: php-src/run-tests.php diff -u php-src/run-tests.php:1.226.2.37.2.1 php-src/run-tests.php:1.226.2.37.2.2 --- php-src/run-tests.php:1.226.2.37.2.1 Wed May 10 20:00:26 2006 +++ php-src/run-tests.php Sat May 13 14:01:58 2006 @@ -23,7 +23,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: run-tests.php,v 1.226.2.37.2.1 2006/05/10 20:00:26 helly Exp $ */ +/* $Id: run-tests.php,v 1.226.2.37.2.2 2006/05/13 14:01:58 helly Exp $ */ /* Sanity check to ensure that pcre extension needed by this script is available. * In the event it is not, print a nice error message indicating that this script will @@ -397,7 +397,7 @@ $html_output = is_resource($html_file); break; case '--version': - echo '$Revision: 1.226.2.37.2.1 $'."\n"; + echo '$Revision: 1.226.2.37.2.2 $'."\n"; exit(1); default: echo "Illegal switch '$switch' specified!\n"; @@ -972,7 +972,7 @@ $line = fgets($fp); // Match the beginning of a section. - if (preg_match('/^--([A-Z_]+)--/', $line, $r)) { + if (preg_match('/^--([A-Z]+)--/', $line, $r)) { $section = $r[1]; $section_text[$section] = ''; $secfile = $section == 'FILE' || $section == 'FILEEOF'; @@ -1236,6 +1236,17 @@ // 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, '', $temp_filenames); + $PHP_FAILED_TESTS['BORKED'][] = array ( + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "$bork_info [$file]", + 'unicode'=> $unicode_semantics, + ); } } if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { @@ -1299,13 +1310,14 @@ $post = trim($section_text['POST']); 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'; @@ -1370,8 +1382,47 @@ $output = str_replace("\r\n", "\n", trim($out)); /* when using CGI, strip the headers from the output */ - if (isset($old_php) && ($pos = strpos($output, "\n\n")) !== FALSE) { - $output = substr($output, ($pos + 2)); + $headers = ""; + if (isset($old_php) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { + $output = $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]); + } + } + } + + $failed_headers = false; + if (isset($section_text['EXPECTHEADERS'])) { + $want = array(); + $wanted_headers = array(); + $lines = preg_split("/[\n\r]+/",$section_text['EXPECTHEADERS']); + foreach($lines as $line) { + if (strpos($line, ':') !== false) { + $line = explode(':', $line, 2); + $want[trim($line[0])] = trim($line[1]); + $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); + $output_headers = join("\n", $output_headers); } if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { @@ -1407,7 +1458,7 @@ if (isset($old_php)) { $php = $old_php; } - if (!$leaked) { + if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } @@ -1424,7 +1475,7 @@ if (isset($old_php)) { $php = $old_php; } - if (!$leaked) { + if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } @@ -1433,7 +1484,15 @@ } // Test failed so we need to report details. - + if ($failed_headers) { + $passed = false; + $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; + $output = $output_headers . "\n--HEADERS--\n" . $output; + if (isset($wanted_re)) { + $wanted_re = $wanted_headers . "\n--HEADERS--\n" . $wanted_re; + } + } + if ($leaked) { $restype = 'LEAK'; } else if ($warn) { @@ -1478,7 +1537,7 @@ 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]", 'output' => $output_filename, 'diff' => $diff_filename, - 'info' => $info + 'info' => $info, ); if (isset($old_php)) {

« previous php.cvs (#38186) next »