Skip to content

Commit e12a0b7

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 e12a0b7

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

run-tests.php

Lines changed: 37 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,22 @@ 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['APPVEYOR'])
656+
|| isset($_SERVER['BUILD_DEFINITIONVERSION']) // Azure pipelines
657+
|| isset($_SERVER['CIRCLECI'])
658+
|| isset($_SERVER['CIRRUS_CI'])
659+
|| isset($_SERVER['DRONE'])
660+
|| isset($_SERVER['GITHUB_WORKFLOW'])
661+
|| isset($_SERVER['GITLAB_CI'])
662+
|| isset($_SERVER['JENKINS_URL'])
663+
|| isset($_SERVER['SCRUTINIZER'])
664+
|| isset($_SERVER['TRAVIS']);
665+
666+
$show_progress = !$is_ci;
667+
}
642668
}
643669

644670
if ($selected_tests && count($test_files) === 0) {
@@ -1331,7 +1357,7 @@ function run_all_tests(array $test_files, array $env, $redir_tested = null): voi
13311357
*/
13321358
function run_all_tests_parallel(array $test_files, array $env, $redir_tested): void
13331359
{
1334-
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind;
1360+
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind, $show_progress;
13351361

13361362
global $junit;
13371363

@@ -1578,13 +1604,13 @@ function run_all_tests_parallel(array $test_files, array $env, $redir_tested): v
15781604
}
15791605
$test_idx++;
15801606

1581-
if (!$SHOW_ONLY_GROUPS) {
1607+
if ($show_progress) {
15821608
clear_show_test();
15831609
}
15841610

15851611
echo $resultText;
15861612

1587-
if (!$SHOW_ONLY_GROUPS) {
1613+
if ($show_progress) {
15881614
show_test($test_idx, count($workerProcs) . "/$workers concurrent test workers running");
15891615
}
15901616

@@ -1634,7 +1660,7 @@ function run_all_tests_parallel(array $test_files, array $env, $redir_tested): v
16341660
}
16351661
}
16361662

1637-
if (!$SHOW_ONLY_GROUPS) {
1663+
if ($show_progress) {
16381664
clear_show_test();
16391665
}
16401666

@@ -3223,22 +3249,22 @@ function show_summary(): void
32233249

32243250
function show_redirect_start(string $tests, string $tested, string $tested_file): void
32253251
{
3226-
global $SHOW_ONLY_GROUPS;
3252+
global $SHOW_ONLY_GROUPS, $show_progress;
32273253

32283254
if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) {
32293255
echo "REDIRECT $tests ($tested [$tested_file]) begin\n";
3230-
} else {
3256+
} elseif ($show_progress) {
32313257
clear_show_test();
32323258
}
32333259
}
32343260

32353261
function show_redirect_ends(string $tests, string $tested, string $tested_file): void
32363262
{
3237-
global $SHOW_ONLY_GROUPS;
3263+
global $SHOW_ONLY_GROUPS, $show_progress;
32383264

32393265
if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) {
32403266
echo "REDIRECT $tests ($tested [$tested_file]) done\n";
3241-
} else {
3267+
} elseif ($show_progress) {
32423268
clear_show_test();
32433269
}
32443270
}
@@ -3280,7 +3306,7 @@ function show_result(
32803306
string $extra = '',
32813307
?array $temp_filenames = null
32823308
): void {
3283-
global $SHOW_ONLY_GROUPS, $colorize;
3309+
global $SHOW_ONLY_GROUPS, $colorize, $show_progress;
32843310

32853311
if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
32863312
if ($colorize) {
@@ -3302,10 +3328,9 @@ function show_result(
33023328
} else {
33033329
echo "$result $tested [$tested_file] $extra\n";
33043330
}
3305-
} elseif (!$SHOW_ONLY_GROUPS) {
3331+
} elseif ($show_progress) {
33063332
clear_show_test();
33073333
}
3308-
33093334
}
33103335

33113336
class BorkageException extends Exception

0 commit comments

Comments
 (0)