helly           Sat Dec 31 17:48:26 2005 EDT

  Modified files:              (Branch: PHP_5_1)
    /php-src    run-tests.php 
  Log:
  - MFH Fix environment handling
  
http://cvs.php.net/viewcvs.cgi/php-src/run-tests.php?r1=1.226.2.23&r2=1.226.2.24&diff_format=u
Index: php-src/run-tests.php
diff -u php-src/run-tests.php:1.226.2.23 php-src/run-tests.php:1.226.2.24
--- php-src/run-tests.php:1.226.2.23    Fri Dec 30 15:05:17 2005
+++ php-src/run-tests.php       Sat Dec 31 17:48:26 2005
@@ -23,7 +23,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: run-tests.php,v 1.226.2.23 2005/12/30 15:05:17 helly Exp $ */
+/* $Id: run-tests.php,v 1.226.2.24 2005/12/31 17:48:26 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
@@ -97,6 +97,8 @@
 SAFE_MODE_WARNING;
 }
 
+$environment = isset($_ENV) ? $_ENV : array();
+
 // Don't ever guess at the PHP executable location.
 // Require the explicit specification.
 // Otherwise we could end up testing the wrong file!
@@ -107,6 +109,7 @@
                $php = $cwd.'/sapi/cli/php';
                putenv("TEST_PHP_EXECUTABLE=$php");
        }
+       $environment['TEST_PHP_EXECUTABLE'] = $php;
 }
 
 if ($argc !=2 || ($argv[1] != '-h' && $argv[1] != '-help' && $argv != 
'--help'))
@@ -371,7 +374,7 @@
                                        $html_output = is_resource($html_file);
                                        break;
                                case '--version':
-                                       echo '$Revision: 1.226.2.23 $'."\n";
+                                       echo '$Revision: 1.226.2.24 $'."\n";
                                        exit(1);
                                default:
                                        echo "Illegal switch '$switch' 
specified!\n";
@@ -467,7 +470,7 @@
                        show_start($start_time);
                }
                $test_idx = 0;
-               run_all_tests($test_files);
+               run_all_tests($test_files, $environment);
                $end_time = time();
                if ($html_output) {
                        show_end($end_time);
@@ -589,7 +592,7 @@
 
 $test_cnt = count($test_files);
 $test_idx = 0;
-run_all_tests($test_files);
+run_all_tests($test_files, $environment);
 $end_time = time();
 if ($failed_tests_file) {
        fclose($failed_tests_file);
@@ -805,7 +808,7 @@
        }
 }
 
-function system_with_timeout($commandline)
+function system_with_timeout($commandline, $env = null)
 {
        global $leak_check;
 
@@ -815,7 +818,7 @@
                0 => array('pipe', 'r'),
                1 => array('pipe', 'w'),
                2 => array('pipe', 'w')
-               ), $pipes, null, null, array("suppress_errors" => true));
+               ), $pipes, null, $env, array("suppress_errors" => true));
 
        if (!$proc)
                return false;
@@ -851,7 +854,7 @@
        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;
 
@@ -859,7 +862,7 @@
        {
                $index = is_array($name) ? $name[0] : $name;
                $test_idx++;
-               $result = run_test($php, $name);
+               $result = run_test($php, $name, $env);
                if (!is_array($name) && $result != 'REDIR')
                {
                        $test_results[$index] = $result;
@@ -879,9 +882,11 @@
 //
 //  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;
        $org_file = $file;
@@ -1058,13 +1063,21 @@
        @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=");
+       $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", $section_text['ENV']) as $e) {
+                       $e = explode('=',trim($e));
+                       if (count($e) == 2) {
+                               $env[$e[0]] = $e[1];
+                       }
+               }
+       }
 
        // Check if test should be skipped.
        $info = '';
@@ -1083,7 +1096,7 @@
                        save_text($test_skipif, $section_text['SKIPIF'], 
$temp_skipif);
                        $extra = substr(PHP_OS, 0, 3) !== "WIN" ?
                                "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);
                        if (!strncasecmp('skip', trim($output), 4)) {
                                $reason = (eregi("^skip[[:space:]]*(.+)\$", 
trim($output))) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", 
trim($output)) : FALSE;
@@ -1138,22 +1151,14 @@
                        show_redirect_start($IN_REDIRECT['TESTS'], $tested, 
$tested_file);
 
                        // set up environment
-                       foreach ($IN_REDIRECT['ENV'] as $k => $v) {
-                               putenv("$k=$v");
-                       }
-                       putenv("REDIR_TEST_DIR=" . 
realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR);
+                       $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, $tested);
+                       run_all_tests($test_files, $redirenv, $tested);
        
                        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
                        $IN_REDIRECT = false;
                        return 'REDIR';
@@ -1205,16 +1210,10 @@
                $query_string = '';
        }
 
-       if (!empty($section_text['ENV'])) {
-               foreach (explode("\n", $section_text['ENV']) as $env) {
-                       ($env = trim($env)) and putenv($env);
-               }
-       }
-
-       putenv("REDIRECT_STATUS=1");
-       putenv("QUERY_STRING=$query_string");
-       putenv("PATH_TRANSLATED=$test_file");
-       putenv("SCRIPT_FILENAME=$test_file");
+       $env['REDIRECT_STATUS'] = '1';
+       $env['QUERY_STRING']    = $query_string;
+       $env['PATH_TRANSLATED'] = $test_file;
+       $env['SCRIPT_FILENAME'] = $test_file;
 
        $args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
 
@@ -1224,23 +1223,19 @@
                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");
+               $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 {
 
-               putenv("REQUEST_METHOD=GET");
-               putenv("CONTENT_TYPE=");
-               putenv("CONTENT_LENGTH=");
+               $env['REQUEST_METHOD'] = 'GET';
+               $env['CONTENT_TYPE']   = '';
+               $env['CONTENT_LENGTH'] = '';
 
-               if (empty($section_text['ENV'])) {
-                       $cmd = "$php$pass_options$ini_settings -f 
\"$test_file\" $args 2>&1";
-               } else {
-                       $cmd = "$php$pass_options$ini_settings < \"$test_file\" 
$args 2>&1";
-               }
+               $cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 
2>&1";
        }
 
        if ($leak_check) {
@@ -1248,25 +1243,17 @@
        }
 
        if ($DETAILED) echo "
-CONTENT_LENGTH  = " . getenv("CONTENT_LENGTH") . "
-CONTENT_TYPE    = " . getenv("CONTENT_TYPE") . "
-PATH_TRANSLATED = " . getenv("PATH_TRANSLATED") . "
-QUERY_STRING    = " . getenv("QUERY_STRING") . "
-REDIRECT_STATUS = " . getenv("REDIRECT_STATUS") . "
-REQUEST_METHOD  = " . getenv("REQUEST_METHOD") . "
-SCRIPT_FILENAME = " . getenv("SCRIPT_FILENAME") . "
+CONTENT_LENGTH  = " . $env['CONTENT_LENGTH'] . "
+CONTENT_TYPE    = " . $env['CONTENT_TYPE'] . "
+PATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "
+QUERY_STRING    = " . $env['QUERY_STRING'] . "
+REDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "
+REQUEST_METHOD  = " . $env['REQUEST_METHOD'] . "
+SCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "
 COMMAND $cmd
 ";
 
-//     $out = `$cmd`;
-       $out = system_with_timeout($cmd);
-
-       if (!empty($section_text['ENV'])) {
-               foreach (explode("\n", $section_text['ENV']) as $env) {
-                       $env = explode('=', $env);
-                       putenv($env[0] .'=');
-               }
-       }
+       $out = system_with_timeout($cmd, $env);
 
        @unlink($tmp_post);
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to