Skip to content

Commit

Permalink
Add colours to test results in run-tests.php
Browse files Browse the repository at this point in the history
The test runner will attempt to colourise the result of each test

The --no-colour option is introduced to disable this feature.
  • Loading branch information
Girgias committed Jul 31, 2020
1 parent d92229d commit 3670358
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions run-tests.php
Expand Up @@ -114,6 +114,8 @@ function show_usage()
--no-clean Do not execute clean section if any.
--no-colour Do not colourise the result type in the test result
HELP;
}
Expand All @@ -133,7 +135,7 @@ function main()
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, $colourise,
$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,
Expand Down Expand Up @@ -384,6 +386,10 @@ function main()
$temp_urlbase = null;
$conf_passed = null;
$no_clean = false;
$colourise = true;
if (function_exists('sapi_windows_vt100_support') && !sapi_windows_vt100_support(STDOUT, true)) {
$colourise = false;
}
$selected_tests = false;
$slow_min_ms = INF;
$preload = false;
Expand Down Expand Up @@ -530,6 +536,9 @@ function main()
case '--no-clean':
$no_clean = true;
break;
case '--no-colour':
$colourise = false;
break;
case 'p':
$php = $argv[++$i];
putenv("TEST_PHP_EXECUTABLE=$php");
Expand Down Expand Up @@ -3223,10 +3232,30 @@ function parse_conflicts(string $text): array

function show_result($result, $tested, $tested_file, $extra = '', $temp_filenames = null)
{
global $temp_target, $temp_urlbase, $line_length, $SHOW_ONLY_GROUPS;
global $SHOW_ONLY_GROUPS, $colourise;

if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) {
echo "$result $tested [$tested_file] $extra\n";
if ($colourise) {
/* Use ANSI escape codes for colouring test result */
switch ( $result ) {
case 'PASS': // Light Green
$colour = "\e[1;32m{$result}\e[0m"; break;
case 'SKIP': // Light Gray
$colour = "\e[0;37m{$result}"; break;
case 'FAIL': // Light Red
$colour = "\e[1;31m{$result}\e[0m"; break;
case 'BORK': // Purple
$colour = "\e[0;35m{$result}\e[0m"; break;
case 'LEAK': // Dark Blue
$colour = "\e[2;34m{$result}\e[0m"; break;
default: // Yellow
$colour = "\e[1;33m{$result}\e[0m"; break;
}

echo "$colour $tested [$tested_file] $extra\e[0m\n";
} else {
echo "$result $tested [$tested_file] $extra\n";
}
} elseif (!$SHOW_ONLY_GROUPS) {
clear_show_test();
}
Expand Down

0 comments on commit 3670358

Please sign in to comment.