Skip to content

Commit 1c7fb6e

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-colour option is introduced to disable this feature.
1 parent 7575340 commit 1c7fb6e

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

run-tests.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ function show_usage()
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()
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()
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()
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");
@@ -3223,10 +3232,30 @@ function parse_conflicts(string $text): array
32233232

32243233
function show_result($result, $tested, $tested_file, $extra = '', $temp_filenames = null)
32253234
{
3226-
global $temp_target, $temp_urlbase, $line_length, $SHOW_ONLY_GROUPS;
3235+
global $SHOW_ONLY_GROUPS, $colorize;
32273236

32283237
if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
3229-
echo "$result $tested [$tested_file] $extra\n";
3238+
if ($colorize) {
3239+
/* Use ANSI escape codes for coloring test result */
3240+
switch ( $result ) {
3241+
case 'PASS': // Light Green
3242+
$color = "\e[1;32m{$result}\e[0m"; break;
3243+
case 'SKIP': // Light Gray
3244+
$color = "\e[0;37m{$result}\e[0m"; break;
3245+
case 'FAIL': // Light Red
3246+
$color = "\e[1;31m{$result}\e[0m"; break;
3247+
case 'BORK': // Purple
3248+
$color = "\e[0;35m{$result}\e[0m"; break;
3249+
case 'LEAK': // Dark Blue
3250+
$color = "\e[2;34m{$result}\e[0m"; break;
3251+
default: // Yellow
3252+
$color = "\e[1;33m{$result}\e[0m"; break;
3253+
}
3254+
3255+
echo "$color $tested [$tested_file] $extra\e[0m\n";
3256+
} else {
3257+
echo "$result $tested [$tested_file] $extra\n";
3258+
}
32303259
} elseif (!$SHOW_ONLY_GROUPS) {
32313260
clear_show_test();
32323261
}

0 commit comments

Comments
 (0)