Skip to content

Commit 5d72e40

Browse files
committed
Add colours to test results in run-tests.php
The test runner will attempt to colourise the result of each test The --no-color option is introduced to disable this feature. Closes GH-5901
1 parent c740019 commit 5d72e40

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

run-tests.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ function show_usage(): void
114114
115115
--no-clean Do not execute clean section if any.
116116
117+
--no-color Do not colorize the result type in the test result
118+
117119
118120
HELP;
119121
}
@@ -133,7 +135,7 @@ function main(): void
133135
global $DETAILED, $PHP_FAILED_TESTS, $SHOW_ONLY_GROUPS, $argc, $argv, $cfg,
134136
$cfgfiles, $cfgtypes, $conf_passed, $end_time, $environment,
135137
$exts_skipped, $exts_tested, $exts_to_test, $failed_tests_file,
136-
$ignored_by_ext, $ini_overwrites, $is_switch,
138+
$ignored_by_ext, $ini_overwrites, $is_switch, $colorize,
137139
$just_save_results, $log_format, $matches, $no_clean, $no_file_cache,
138140
$optionals, $output_file, $pass_option_n, $pass_options,
139141
$pattern_match, $php, $php_cgi, $phpdbg, $preload, $redir_tests,
@@ -384,6 +386,10 @@ function main(): void
384386
$temp_urlbase = null;
385387
$conf_passed = null;
386388
$no_clean = false;
389+
$colorize = true;
390+
if (function_exists('sapi_windows_vt100_support') && !sapi_windows_vt100_support(STDOUT, true)) {
391+
$colorize = false;
392+
}
387393
$selected_tests = false;
388394
$slow_min_ms = INF;
389395
$preload = false;
@@ -530,6 +536,9 @@ function main(): void
530536
case '--no-clean':
531537
$no_clean = true;
532538
break;
539+
case '--no-color':
540+
$colorize = false;
541+
break;
533542
case 'p':
534543
$php = $argv[++$i];
535544
putenv("TEST_PHP_EXECUTABLE=$php");
@@ -3266,10 +3275,27 @@ function show_result(
32663275
string $extra = '',
32673276
?array $temp_filenames = null
32683277
): void {
3269-
global $temp_target, $temp_urlbase, $line_length, $SHOW_ONLY_GROUPS;
3278+
global $SHOW_ONLY_GROUPS, $colorize;
32703279

32713280
if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
3272-
echo "$result $tested [$tested_file] $extra\n";
3281+
if ($colorize) {
3282+
/* Use ANSI escape codes for coloring test result */
3283+
switch ( $result ) {
3284+
case 'PASS': // Light Green
3285+
$color = "\e[1;32m{$result}\e[0m"; break;
3286+
case 'FAIL':
3287+
case 'BORK':
3288+
case 'LEAK':
3289+
// Light Red
3290+
$color = "\e[1;31m{$result}\e[0m"; break;
3291+
default: // Yellow
3292+
$color = "\e[1;33m{$result}\e[0m"; break;
3293+
}
3294+
3295+
echo "$color $tested [$tested_file] $extra\n";
3296+
} else {
3297+
echo "$result $tested [$tested_file] $extra\n";
3298+
}
32733299
} elseif (!$SHOW_ONLY_GROUPS) {
32743300
clear_show_test();
32753301
}

0 commit comments

Comments
 (0)