Skip to content

Commit ad15508

Browse files
committed
Modernization of run-tests.php
1 parent d5d91ae commit ad15508

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

run-tests.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,7 @@ function main()
443443

444444
switch ($switch) {
445445
case 'j':
446-
$workers = substr($argv[$i], 2);
447-
if (!preg_match('/^\d+$/', $workers) || $workers == 0) {
448-
error("'$workers' is not a valid number of workers, try e.g. -j16 for 16 workers");
449-
}
450-
$workers = intval($workers, 10);
451-
// Don't use parallel testing infrastructure if there is only one worker.
452-
if ($workers === 1) {
453-
$workers = null;
454-
}
446+
$workers = getNumberOfWorkers($argv[$i]);
455447
break;
456448
case 'r':
457449
case 'l':
@@ -3612,4 +3604,28 @@ function check_proc_open_function_exists()
36123604
}
36133605
}
36143606

3607+
3608+
3609+
3610+
function getNumberOfWorkers($workers): int
3611+
{
3612+
$cleanWorkers = substr($workers, 2);
3613+
if (!preg_match('/^\d+$/', $cleanWorkers) || $cleanWorkers == 0) {
3614+
error("'$workers' is not a valid number of workers, try e.g. -j16 for 16 workers");
3615+
}
3616+
$cleanWorkers = intval($cleanWorkers, 10);
3617+
// Don't use parallel testing infrastructure if there is only one worker.
3618+
if ($cleanWorkers === 1) {
3619+
$cleanWorkers = null;
3620+
}
3621+
3622+
return $cleanWorkers;
3623+
}
3624+
3625+
function getMaxWorkersFromTestFiles($workers, $testFiles)
3626+
{
3627+
return max(1, min($workers, count($test_files)))
3628+
}
3629+
3630+
36153631
main();

0 commit comments

Comments
 (0)