Skip to content

Commit d1dde09

Browse files
gerardrochenikic
authored andcommitted
run-tests: refactor
1 parent 2ef88f5 commit d1dde09

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

run-tests.php

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,14 @@ function main()
159159

160160
define('INIT_DIR', getcwd());
161161

162-
// change into the PHP source directory.
162+
// Change into the PHP source directory.
163163
if (getenv('TEST_PHP_SRCDIR')) {
164164
@chdir(getenv('TEST_PHP_SRCDIR'));
165165
}
166-
define('TEST_PHP_SRCDIR', getcwd());
167166

168-
if (!function_exists('proc_open')) {
169-
echo <<<NO_PROC_OPEN_ERROR
167+
define('TEST_PHP_SRCDIR', getcwd());
170168

171-
+-----------------------------------------------------------+
172-
| ! ERROR ! |
173-
| The test-suite requires that proc_open() is available. |
174-
| Please check if you disabled it in php.ini. |
175-
+-----------------------------------------------------------+
176-
177-
NO_PROC_OPEN_ERROR;
178-
exit(1);
179-
}
169+
check_proc_open_function_exists();
180170

181171
// If timezone is not set, use UTC.
182172
if (ini_get('date.timezone') == '') {
@@ -193,35 +183,36 @@ function main()
193183

194184
ini_set('pcre.backtrack_limit', PHP_INT_MAX);
195185

196-
// delete as much output buffers as possible
197-
while (@ob_end_clean()) {
198-
}
199-
if (ob_get_level()) {
200-
echo "Not all buffers were deleted.\n";
201-
}
186+
init_output_buffers();
202187

203188
error_reporting(E_ALL);
204189

205190
$environment = $_ENV ?? array();
206-
// Note: php.ini-development sets variables_order="GPCS" not "EGPCS", in which case $_ENV is NOT populated.
207-
// detect and handle this case, or die or warn
191+
192+
// Some configurations like php.ini-development set variables_order="GPCS"
193+
// not "EGPCS", in which case $_ENV is NOT populated. Detect if the $_ENV
194+
// was empty and handle it by explicitly populating through getenv().
208195
if (empty($environment)) {
209-
// not documented, but returns array of all environment variables
210196
$environment = getenv();
211197
}
198+
212199
if (empty($environment['TEMP'])) {
213200
$environment['TEMP'] = sys_get_temp_dir();
214201

215202
if (empty($environment['TEMP'])) {
216-
// for example, OpCache on Windows will fail in this case because child processes (for tests) will not get
217-
// a TEMP variable, so GetTempPath() will fallback to c:\windows, while GetTempPath() will return %TEMP% for parent
218-
// (likely a different path). The parent will initialize the OpCache in that path, and child will fail to reattach to
219-
// the OpCache because it will be using the wrong path.
203+
// For example, OpCache on Windows will fail in this case because
204+
// child processes (for tests) will not get a TEMP variable, so
205+
// GetTempPath() will fallback to c:\windows, while GetTempPath()
206+
// will return %TEMP% for parent (likely a different path). The
207+
// parent will initialize the OpCache in that path, and child will
208+
// fail to reattach to the OpCache because it will be using the
209+
// wrong path.
220210
die("TEMP environment is NOT set");
221211
} else {
222212
if (count($environment) == 1) {
223-
// not having other environment variables, only having TEMP, is probably ok, but strange and may make a
224-
// difference in the test pass rate, so warn the user.
213+
// Not having other environment variables, only having TEMP, is
214+
// probably ok, but strange and may make a difference in the
215+
// test pass rate, so warn the user.
225216
echo "WARNING: Only 1 environment variable will be available to tests(TEMP environment variable)" . PHP_EOL;
226217
}
227218
}
@@ -1417,7 +1408,8 @@ function run_all_tests_parallel($test_files, $env, $redir_tested)
14171408
if ($shuffle) {
14181409
shuffle($test_files);
14191410
}
1420-
/* Don't start more workers than test files */
1411+
1412+
// Don't start more workers than test files.
14211413
$workers = max(1, min($workers, count($test_files)));
14221414

14231415
echo "Spawning workers… ";
@@ -3700,4 +3692,31 @@ public function wrapCommand($cmd, $memcheck_filename, $check_all)
37003692
}
37013693
}
37023694

3695+
function init_output_buffers()
3696+
{
3697+
// Delete as much output buffers as possible.
3698+
while (@ob_end_clean()) {
3699+
}
3700+
3701+
if (ob_get_level()) {
3702+
echo "Not all buffers were deleted.\n";
3703+
}
3704+
}
3705+
3706+
function check_proc_open_function_exists()
3707+
{
3708+
if (!function_exists('proc_open')) {
3709+
echo <<<NO_PROC_OPEN_ERROR
3710+
3711+
+-----------------------------------------------------------+
3712+
| ! ERROR ! |
3713+
| The test-suite requires that proc_open() is available. |
3714+
| Please check if you disabled it in php.ini. |
3715+
+-----------------------------------------------------------+
3716+
3717+
NO_PROC_OPEN_ERROR;
3718+
exit(1);
3719+
}
3720+
}
3721+
37033722
main();

0 commit comments

Comments
 (0)