- MFH Fix environment handling

This commit is contained in:
Marcus Boerger 2005-12-31 17:48:26 +00:00
parent 8479546920
commit 9846878450

View File

@ -97,6 +97,8 @@ if (ini_get('safe_mode')) {
SAFE_MODE_WARNING; SAFE_MODE_WARNING;
} }
$environment = isset($_ENV) ? $_ENV : array();
// Don't ever guess at the PHP executable location. // Don't ever guess at the PHP executable location.
// Require the explicit specification. // Require the explicit specification.
// Otherwise we could end up testing the wrong file! // Otherwise we could end up testing the wrong file!
@ -107,6 +109,7 @@ if (getenv('TEST_PHP_EXECUTABLE')) {
$php = $cwd.'/sapi/cli/php'; $php = $cwd.'/sapi/cli/php';
putenv("TEST_PHP_EXECUTABLE=$php"); putenv("TEST_PHP_EXECUTABLE=$php");
} }
$environment['TEST_PHP_EXECUTABLE'] = $php;
} }
if ($argc !=2 || ($argv[1] != '-h' && $argv[1] != '-help' && $argv != '--help')) if ($argc !=2 || ($argv[1] != '-h' && $argv[1] != '-help' && $argv != '--help'))
@ -467,7 +470,7 @@ HELP;
show_start($start_time); show_start($start_time);
} }
$test_idx = 0; $test_idx = 0;
run_all_tests($test_files); run_all_tests($test_files, $environment);
$end_time = time(); $end_time = time();
if ($html_output) { if ($html_output) {
show_end($end_time); show_end($end_time);
@ -589,7 +592,7 @@ show_start($start_time);
$test_cnt = count($test_files); $test_cnt = count($test_files);
$test_idx = 0; $test_idx = 0;
run_all_tests($test_files); run_all_tests($test_files, $environment);
$end_time = time(); $end_time = time();
if ($failed_tests_file) { if ($failed_tests_file) {
fclose($failed_tests_file); fclose($failed_tests_file);
@ -805,7 +808,7 @@ function error_report($testname, $logname, $tested)
} }
} }
function system_with_timeout($commandline) function system_with_timeout($commandline, $env = null)
{ {
global $leak_check; global $leak_check;
@ -815,7 +818,7 @@ function system_with_timeout($commandline)
0 => array('pipe', 'r'), 0 => array('pipe', 'r'),
1 => array('pipe', 'w'), 1 => array('pipe', 'w'),
2 => array('pipe', 'w') 2 => array('pipe', 'w')
), $pipes, null, null, array("suppress_errors" => true)); ), $pipes, null, $env, array("suppress_errors" => true));
if (!$proc) if (!$proc)
return false; return false;
@ -851,7 +854,7 @@ function system_with_timeout($commandline)
return $data; return $data;
} }
function run_all_tests($test_files, $redir_tested = NULL) function run_all_tests($test_files, $env, $redir_tested = NULL)
{ {
global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx; global $test_results, $failed_tests_file, $php, $test_cnt, $test_idx;
@ -859,7 +862,7 @@ function run_all_tests($test_files, $redir_tested = NULL)
{ {
$index = is_array($name) ? $name[0] : $name; $index = is_array($name) ? $name[0] : $name;
$test_idx++; $test_idx++;
$result = run_test($php, $name); $result = run_test($php, $name, $env);
if (!is_array($name) && $result != 'REDIR') if (!is_array($name) && $result != 'REDIR')
{ {
$test_results[$index] = $result; $test_results[$index] = $result;
@ -879,9 +882,11 @@ function run_all_tests($test_files, $redir_tested = NULL)
// //
// Run an individual test case. // Run an individual test case.
// //
function run_test($php, $file) function run_test($php, $file, $env)
{ {
global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS, $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx, $leak_check, $temp_source, $temp_target, $cfg; global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS;
global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx;
global $leak_check, $temp_source, $temp_target, $cfg, $environment;
$temp_filenames = null; $temp_filenames = null;
$org_file = $file; $org_file = $file;
@ -1058,13 +1063,21 @@ TEST $file
@unlink($tmp_post); @unlink($tmp_post);
// Reset environment from any previous test. // Reset environment from any previous test.
putenv("REDIRECT_STATUS="); $env['REDIRECT_STATUS']='';
putenv("QUERY_STRING="); $env['QUERY_STRING']='';
putenv("PATH_TRANSLATED="); $env['PATH_TRANSLATED']='';
putenv("SCRIPT_FILENAME="); $env['SCRIPT_FILENAME']='';
putenv("REQUEST_METHOD="); $env['REQUEST_METHOD']='';
putenv("CONTENT_TYPE="); $env['CONTENT_TYPE']='';
putenv("CONTENT_LENGTH="); $env['CONTENT_LENGTH']='';
if (!empty($section_text['ENV'])) {
foreach(explode("\n", $section_text['ENV']) as $e) {
$e = explode('=',trim($e));
if (count($e) == 2) {
$env[$e[0]] = $e[1];
}
}
}
// Check if test should be skipped. // Check if test should be skipped.
$info = ''; $info = '';
@ -1083,7 +1096,7 @@ TEST $file
save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif);
$extra = substr(PHP_OS, 0, 3) !== "WIN" ? $extra = substr(PHP_OS, 0, 3) !== "WIN" ?
"unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;": ""; "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;": "";
$output = system_with_timeout("$extra $php -q $skipif_params $test_skipif"); $output = system_with_timeout("$extra $php -q $skipif_params $test_skipif", $env);
@unlink($test_skipif); @unlink($test_skipif);
if (!strncasecmp('skip', trim($output), 4)) { if (!strncasecmp('skip', trim($output), 4)) {
$reason = (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; $reason = (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;
@ -1138,22 +1151,14 @@ TEST $file
show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file);
// set up environment // set up environment
foreach ($IN_REDIRECT['ENV'] as $k => $v) { $redirenv = array_merge($environment, $IN_REDIRECT['ENV']);
putenv("$k=$v"); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR;
}
putenv("REDIR_TEST_DIR=" . realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR);
usort($test_files, "test_sort"); usort($test_files, "test_sort");
run_all_tests($test_files, $tested); run_all_tests($test_files, $redirenv, $tested);
show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file);
// clean up environment
foreach ($IN_REDIRECT['ENV'] as $k => $v) {
putenv("$k=");
}
putenv("REDIR_TEST_DIR=");
// a redirected test never fails // a redirected test never fails
$IN_REDIRECT = false; $IN_REDIRECT = false;
return 'REDIR'; return 'REDIR';
@ -1205,16 +1210,10 @@ TEST $file
$query_string = ''; $query_string = '';
} }
if (!empty($section_text['ENV'])) { $env['REDIRECT_STATUS'] = '1';
foreach (explode("\n", $section_text['ENV']) as $env) { $env['QUERY_STRING'] = $query_string;
($env = trim($env)) and putenv($env); $env['PATH_TRANSLATED'] = $test_file;
} $env['SCRIPT_FILENAME'] = $test_file;
}
putenv("REDIRECT_STATUS=1");
putenv("QUERY_STRING=$query_string");
putenv("PATH_TRANSLATED=$test_file");
putenv("SCRIPT_FILENAME=$test_file");
$args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : ''; $args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
@ -1224,23 +1223,19 @@ TEST $file
save_text($tmp_post, $post); save_text($tmp_post, $post);
$content_length = strlen($post); $content_length = strlen($post);
putenv("REQUEST_METHOD=POST"); $env['REQUEST_METHOD'] = 'POST';
putenv("CONTENT_TYPE=application/x-www-form-urlencoded"); $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
putenv("CONTENT_LENGTH=$content_length"); $env['CONTENT_LENGTH'] = $content_length;
$cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post"; $cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post";
} else { } else {
putenv("REQUEST_METHOD=GET"); $env['REQUEST_METHOD'] = 'GET';
putenv("CONTENT_TYPE="); $env['CONTENT_TYPE'] = '';
putenv("CONTENT_LENGTH="); $env['CONTENT_LENGTH'] = '';
if (empty($section_text['ENV'])) { $cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1";
$cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1";
} else {
$cmd = "$php$pass_options$ini_settings < \"$test_file\" $args 2>&1";
}
} }
if ($leak_check) { if ($leak_check) {
@ -1248,25 +1243,17 @@ TEST $file
} }
if ($DETAILED) echo " if ($DETAILED) echo "
CONTENT_LENGTH = " . getenv("CONTENT_LENGTH") . " CONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "
CONTENT_TYPE = " . getenv("CONTENT_TYPE") . " CONTENT_TYPE = " . $env['CONTENT_TYPE'] . "
PATH_TRANSLATED = " . getenv("PATH_TRANSLATED") . " PATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "
QUERY_STRING = " . getenv("QUERY_STRING") . " QUERY_STRING = " . $env['QUERY_STRING'] . "
REDIRECT_STATUS = " . getenv("REDIRECT_STATUS") . " REDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "
REQUEST_METHOD = " . getenv("REQUEST_METHOD") . " REQUEST_METHOD = " . $env['REQUEST_METHOD'] . "
SCRIPT_FILENAME = " . getenv("SCRIPT_FILENAME") . " SCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "
COMMAND $cmd COMMAND $cmd
"; ";
// $out = `$cmd`; $out = system_with_timeout($cmd, $env);
$out = system_with_timeout($cmd);
if (!empty($section_text['ENV'])) {
foreach (explode("\n", $section_text['ENV']) as $env) {
$env = explode('=', $env);
putenv($env[0] .'=');
}
}
@unlink($tmp_post); @unlink($tmp_post);