summaryrefslogtreecommitdiff
path: root/run-tests.php
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-07-31 19:02:59 +0100
committerGeorge Peter Banyard <girgias@php.net>2020-08-07 18:17:34 +0200
commit5d72e40dfb3b9d2c5cc64e0596d1a644a421b299 (patch)
tree0aba163eab214507410dc8222f6a99caee9f8ef7 /run-tests.php
parentc74001997f996e9a3d0e557226b125132d6993ef (diff)
downloadphp-git-5d72e40dfb3b9d2c5cc64e0596d1a644a421b299.tar.gz
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
Diffstat (limited to 'run-tests.php')
-rwxr-xr-xrun-tests.php32
1 files changed, 29 insertions, 3 deletions
diff --git a/run-tests.php b/run-tests.php
index a575f93cd4..5839c7e90f 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -114,6 +114,8 @@ Options:
--no-clean Do not execute clean section if any.
+ --no-color Do not colorize the result type in the test result
+
HELP;
}
@@ -133,7 +135,7 @@ function main(): void
global $DETAILED, $PHP_FAILED_TESTS, $SHOW_ONLY_GROUPS, $argc, $argv, $cfg,
$cfgfiles, $cfgtypes, $conf_passed, $end_time, $environment,
$exts_skipped, $exts_tested, $exts_to_test, $failed_tests_file,
- $ignored_by_ext, $ini_overwrites, $is_switch,
+ $ignored_by_ext, $ini_overwrites, $is_switch, $colorize,
$just_save_results, $log_format, $matches, $no_clean, $no_file_cache,
$optionals, $output_file, $pass_option_n, $pass_options,
$pattern_match, $php, $php_cgi, $phpdbg, $preload, $redir_tests,
@@ -384,6 +386,10 @@ function main(): void
$temp_urlbase = null;
$conf_passed = null;
$no_clean = false;
+ $colorize = true;
+ if (function_exists('sapi_windows_vt100_support') && !sapi_windows_vt100_support(STDOUT, true)) {
+ $colorize = false;
+ }
$selected_tests = false;
$slow_min_ms = INF;
$preload = false;
@@ -530,6 +536,9 @@ function main(): void
case '--no-clean':
$no_clean = true;
break;
+ case '--no-color':
+ $colorize = false;
+ break;
case 'p':
$php = $argv[++$i];
putenv("TEST_PHP_EXECUTABLE=$php");
@@ -3266,10 +3275,27 @@ function show_result(
string $extra = '',
?array $temp_filenames = null
): void {
- global $temp_target, $temp_urlbase, $line_length, $SHOW_ONLY_GROUPS;
+ global $SHOW_ONLY_GROUPS, $colorize;
if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
- echo "$result $tested [$tested_file] $extra\n";
+ if ($colorize) {
+ /* Use ANSI escape codes for coloring test result */
+ switch ( $result ) {
+ case 'PASS': // Light Green
+ $color = "\e[1;32m{$result}\e[0m"; break;
+ case 'FAIL':
+ case 'BORK':
+ case 'LEAK':
+ // Light Red
+ $color = "\e[1;31m{$result}\e[0m"; break;
+ default: // Yellow
+ $color = "\e[1;33m{$result}\e[0m"; break;
+ }
+
+ echo "$color $tested [$tested_file] $extra\n";
+ } else {
+ echo "$result $tested [$tested_file] $extra\n";
+ }
} elseif (!$SHOW_ONLY_GROUPS) {
clear_show_test();
}