Skip to content

Commit 20d6240

Browse files
committed
Add --progress option to run-tests.php
The option is enabled in CLI but disabled in CI by default. Previously, adding the -g argument would disable progress, even locally.
1 parent f51fbf9 commit 20d6240

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

run-tests.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ function show_usage(): void
127127
--color
128128
--no-color Do/Don't colorize the result type in the test result.
129129
130+
--progress
131+
--no-progress Do/Don't show the current progress.
132+
130133
--repeat [n]
131134
Run the tests multiple times in the same process and check the
132135
output of the last execution (CLI SAPI only).
@@ -159,7 +162,7 @@ function main(): void
159162
$temp_source, $temp_target, $test_cnt, $test_dirs,
160163
$test_files, $test_idx, $test_list, $test_results, $testfile,
161164
$user_tests, $valgrind, $sum_results, $shuffle, $file_cache, $num_repeats,
162-
$bless;
165+
$bless, $show_progress;
163166
// Parallel testing
164167
global $workers, $workerID;
165168
global $context_line_count;
@@ -360,6 +363,7 @@ function main(): void
360363
$workers = null;
361364
$context_line_count = 3;
362365
$num_repeats = 1;
366+
$show_progress = null;
363367

364368
$cfgtypes = ['show', 'keep'];
365369
$cfgfiles = ['skip', 'php', 'clean', 'out', 'diff', 'exp', 'mem'];
@@ -600,6 +604,12 @@ function main(): void
600604
$repeat = true;
601605
}
602606
break;
607+
case '--progress':
608+
$show_progress = true;
609+
break;
610+
case '--no-progress':
611+
$show_progress = false;
612+
break;
603613
case '--version':
604614
echo '$Id$' . "\n";
605615
exit(1);
@@ -639,6 +649,20 @@ function main(): void
639649
die('Cannot find test file "' . $argv[$i] . '".' . PHP_EOL);
640650
}
641651
}
652+
653+
if ($show_progress === null) {
654+
// Taken from https://github.com/vimeo/psalm/blob/1ef3851580acef380d083d9b4044bd8c6204b780/src/Psalm/Internal/CliUtils.php#L656
655+
$is_ci = isset($_SERVER['TRAVIS'])
656+
|| isset($_SERVER['CIRCLECI'])
657+
|| isset($_SERVER['APPVEYOR'])
658+
|| isset($_SERVER['JENKINS_URL'])
659+
|| isset($_SERVER['SCRUTINIZER'])
660+
|| isset($_SERVER['GITLAB_CI'])
661+
|| isset($_SERVER['GITHUB_WORKFLOW'])
662+
|| isset($_SERVER['DRONE']);
663+
664+
$show_progress = !$is_ci;
665+
}
642666
}
643667

644668
if ($selected_tests && count($test_files) === 0) {
@@ -1331,7 +1355,7 @@ function run_all_tests(array $test_files, array $env, $redir_tested = null): voi
13311355
*/
13321356
function run_all_tests_parallel(array $test_files, array $env, $redir_tested): void
13331357
{
1334-
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind;
1358+
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind, $show_progress;
13351359

13361360
global $junit;
13371361

@@ -1578,13 +1602,13 @@ function run_all_tests_parallel(array $test_files, array $env, $redir_tested): v
15781602
}
15791603
$test_idx++;
15801604

1581-
if (!$SHOW_ONLY_GROUPS) {
1605+
if ($show_progress) {
15821606
clear_show_test();
15831607
}
15841608

15851609
echo $resultText;
15861610

1587-
if (!$SHOW_ONLY_GROUPS) {
1611+
if ($show_progress) {
15881612
show_test($test_idx, count($workerProcs) . "/$workers concurrent test workers running");
15891613
}
15901614

@@ -1634,7 +1658,7 @@ function run_all_tests_parallel(array $test_files, array $env, $redir_tested): v
16341658
}
16351659
}
16361660

1637-
if (!$SHOW_ONLY_GROUPS) {
1661+
if ($show_progress) {
16381662
clear_show_test();
16391663
}
16401664

@@ -3223,22 +3247,22 @@ function show_summary(): void
32233247

32243248
function show_redirect_start(string $tests, string $tested, string $tested_file): void
32253249
{
3226-
global $SHOW_ONLY_GROUPS;
3250+
global $SHOW_ONLY_GROUPS, $show_progress;
32273251

32283252
if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) {
32293253
echo "REDIRECT $tests ($tested [$tested_file]) begin\n";
3230-
} else {
3254+
} elseif ($show_progress) {
32313255
clear_show_test();
32323256
}
32333257
}
32343258

32353259
function show_redirect_ends(string $tests, string $tested, string $tested_file): void
32363260
{
3237-
global $SHOW_ONLY_GROUPS;
3261+
global $SHOW_ONLY_GROUPS, $show_progress;
32383262

32393263
if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) {
32403264
echo "REDIRECT $tests ($tested [$tested_file]) done\n";
3241-
} else {
3265+
} elseif ($show_progress) {
32423266
clear_show_test();
32433267
}
32443268
}
@@ -3280,7 +3304,7 @@ function show_result(
32803304
string $extra = '',
32813305
?array $temp_filenames = null
32823306
): void {
3283-
global $SHOW_ONLY_GROUPS, $colorize;
3307+
global $SHOW_ONLY_GROUPS, $colorize, $show_progress;
32843308

32853309
if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
32863310
if ($colorize) {
@@ -3302,10 +3326,9 @@ function show_result(
33023326
} else {
33033327
echo "$result $tested [$tested_file] $extra\n";
33043328
}
3305-
} elseif (!$SHOW_ONLY_GROUPS) {
3329+
} elseif ($show_progress) {
33063330
clear_show_test();
33073331
}
3308-
33093332
}
33103333

33113334
class BorkageException extends Exception

0 commit comments

Comments
 (0)