Skip to content

Commit ba1f5d7

Browse files
committed
Modernization of run-tests.php
1 parent 6bc375f commit ba1f5d7

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':
@@ -3613,4 +3605,28 @@ function check_proc_open_function_exists()
36133605
}
36143606
}
36153607

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

0 commit comments

Comments
 (0)