Skip to content

Commit 3b4fb2e

Browse files
committed
Determine run-tests executables consistently
1 parent 6fdc988 commit 3b4fb2e

File tree

1 file changed

+44
-78
lines changed

1 file changed

+44
-78
lines changed

run-tests.php

Lines changed: 44 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -234,65 +234,6 @@ function main(): void
234234
$php_cgi = null;
235235
$phpdbg = null;
236236

237-
if (getenv('TEST_PHP_EXECUTABLE')) {
238-
$php = getenv('TEST_PHP_EXECUTABLE');
239-
240-
if ($php == 'auto') {
241-
$php = TEST_PHP_SRCDIR . '/sapi/cli/php';
242-
putenv("TEST_PHP_EXECUTABLE=$php");
243-
244-
if (!getenv('TEST_PHP_CGI_EXECUTABLE')) {
245-
$php_cgi = TEST_PHP_SRCDIR . '/sapi/cgi/php-cgi';
246-
247-
if (file_exists($php_cgi)) {
248-
putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
249-
} else {
250-
$php_cgi = null;
251-
}
252-
}
253-
}
254-
$environment['TEST_PHP_EXECUTABLE'] = $php;
255-
}
256-
257-
if (getenv('TEST_PHP_CGI_EXECUTABLE')) {
258-
$php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE');
259-
260-
if ($php_cgi == 'auto') {
261-
$php_cgi = TEST_PHP_SRCDIR . '/sapi/cgi/php-cgi';
262-
putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
263-
}
264-
265-
$environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
266-
}
267-
268-
if (!getenv('TEST_PHPDBG_EXECUTABLE')) {
269-
if (IS_WINDOWS && file_exists(dirname($php) . "/phpdbg.exe")) {
270-
$phpdbg = realpath(dirname($php) . "/phpdbg.exe");
271-
} elseif (file_exists(dirname($php) . "/../../sapi/phpdbg/phpdbg")) {
272-
$phpdbg = realpath(dirname($php) . "/../../sapi/phpdbg/phpdbg");
273-
} elseif (file_exists("./sapi/phpdbg/phpdbg")) {
274-
$phpdbg = realpath("./sapi/phpdbg/phpdbg");
275-
} elseif (file_exists(dirname($php) . "/phpdbg")) {
276-
$phpdbg = realpath(dirname($php) . "/phpdbg");
277-
} else {
278-
$phpdbg = null;
279-
}
280-
if ($phpdbg) {
281-
putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg");
282-
}
283-
}
284-
285-
if (getenv('TEST_PHPDBG_EXECUTABLE')) {
286-
$phpdbg = getenv('TEST_PHPDBG_EXECUTABLE');
287-
288-
if ($phpdbg == 'auto') {
289-
$phpdbg = TEST_PHP_SRCDIR . '/sapi/phpdbg/phpdbg';
290-
putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg");
291-
}
292-
293-
$environment['TEST_PHPDBG_EXECUTABLE'] = $phpdbg;
294-
}
295-
296237
if (getenv('TEST_PHP_LOG_FORMAT')) {
297238
$log_format = strtoupper(getenv('TEST_PHP_LOG_FORMAT'));
298239
} else {
@@ -692,13 +633,34 @@ function main(): void
692633
return;
693634
}
694635

695-
// Default to PHP_BINARY as executable
696-
if (!isset($environment['TEST_PHP_EXECUTABLE'])) {
636+
if (!$php) {
637+
$php = getenv('TEST_PHP_EXECUTABLE');
638+
}
639+
if (!$php) {
697640
$php = PHP_BINARY;
698-
putenv("TEST_PHP_EXECUTABLE=$php");
699-
$environment['TEST_PHP_EXECUTABLE'] = $php;
700641
}
701642

643+
if (!$php_cgi) {
644+
$php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE');
645+
}
646+
if (!$php_cgi) {
647+
$php_cgi = get_binary($php, 'php-cgi', 'sapi/cgi/php-cgi');
648+
}
649+
650+
if (!$phpdbg) {
651+
$phpdbg = getenv('TEST_PHPDBG_EXECUTABLE');
652+
}
653+
if (!$phpdbg) {
654+
$phpdbg = get_binary($php, 'phpdbg', 'sapi/phpdbg/phpdbg');
655+
}
656+
657+
putenv("TEST_PHP_EXECUTABLE=$php");
658+
$environment['TEST_PHP_EXECUTABLE'] = $php;
659+
putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
660+
$environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
661+
putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg");
662+
$environment['TEST_PHPDBG_EXECUTABLE'] = $phpdbg;
663+
702664
if ($conf_passed !== null) {
703665
if (IS_WINDOWS) {
704666
$pass_options .= " -c " . escapeshellarg($conf_passed);
@@ -1058,6 +1020,21 @@ function save_or_mail_results(): void
10581020
}
10591021
}
10601022

1023+
function get_binary(string $php, string $sapi, string $sapi_path): ?string
1024+
{
1025+
$dir = dirname($php);
1026+
if (IS_WINDOWS && file_exists("$dir/$sapi.exe")) {
1027+
return realpath("$dir/$sapi.exe");
1028+
}
1029+
if (file_exists("$dir/../../$sapi_path")) {
1030+
return realpath("$dir/../../$sapi_path");
1031+
}
1032+
if (file_exists("$dir/$sapi")) {
1033+
return realpath("$dir/$sapi");
1034+
}
1035+
return null;
1036+
}
1037+
10611038
function find_files(string $dir, bool $is_ext_dir = false, bool $ignore = false): void
10621039
{
10631040
global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped;
@@ -2007,25 +1984,14 @@ function run_test(string $php, $file, array $env): string
20071984

20081985
/* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */
20091986
if (array_key_exists('CGI', $section_text) || !empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['GZIP_POST']) || !empty($section_text['DEFLATE_POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['PUT']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) {
2010-
if (isset($php_cgi)) {
2011-
$php = $php_cgi . ' -C ';
2012-
} elseif (IS_WINDOWS && file_exists(dirname($php) . "/php-cgi.exe")) {
2013-
$php = realpath(dirname($php) . "/php-cgi.exe") . ' -C ';
2014-
} else {
2015-
if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) {
2016-
$php = realpath(dirname($php) . "/../../sapi/cgi/php-cgi") . ' -C ';
2017-
} elseif (file_exists("./sapi/cgi/php-cgi")) {
2018-
$php = realpath("./sapi/cgi/php-cgi") . ' -C ';
2019-
} elseif (file_exists(dirname($php) . "/php-cgi")) {
2020-
$php = realpath(dirname($php) . "/php-cgi") . ' -C ';
2021-
} else {
2022-
return skip_test($tested, $tested_file, $shortname, 'CGI not available');
2023-
}
1987+
if (!$php_cgi) {
1988+
return skip_test($tested, $tested_file, $shortname, 'CGI not available');
20241989
}
1990+
$php = $php_cgi . ' -C ';
1991+
$uses_cgi = true;
20251992
if ($num_repeats > 1) {
20261993
return skip_test($tested, $tested_file, $shortname, 'CGI does not support --repeat');
20271994
}
2028-
$uses_cgi = true;
20291995
}
20301996

20311997
/* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */

0 commit comments

Comments
 (0)