Skip to content

Add colours to run-test #5901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ function show_usage(): void

--no-clean Do not execute clean section if any.

--no-color Do not colorize the result type in the test result


HELP;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch ( $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();
}
Expand Down