CI tests now colorless & fast

dev
gravel 2 years ago
parent 2c1a4973bb
commit 9d3c2c29f6
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -11,7 +11,7 @@
include_once "$PROJECT_ROOT/php/utils/logging.php";
// Read the -v|--verbose option increasing logging verbosity to debug.
$options = getopt("v", ["verbose", "fast"]);
$options = getopt("v", ["verbose", "fast", "no-color"]);
if (isset($options["v"]) or isset($options["verbose"])) {
$LOGGING_VERBOSITY = LoggingVerbosity::Debug;
}
@ -20,6 +20,10 @@
$FAST_FETCH_MODE = true;
}
if (isset($options["no-color"])) {
LoggingVerbosity::$showColor = false;
}
// set timeout for file_get_contents()
ini_set('default_socket_timeout', 6); // in seconds, default is 60

@ -72,7 +72,8 @@ test-noninteractive: FLAGS = --verbose
test-noninteractive: clean all
# Run Continuous Integration tests.
test-ci: test-noninteractive
test-ci: FLAGS = --verbose --fast --no-color
test-ci: clean all
# -- Aliases --
serve: server

@ -40,15 +40,23 @@
/**
* Terminal escape sequence to clear formatting.
*/
const COLOR_RESET = "\033[0m";
private const COLOR_RESET = "\033[0m";
/**
* Returns the color marker for the given logging verbosity.
* Specifies whether to enable terminal colors.
*/
public static bool $showColor = true;
/**
* Returns the color marker for the given logging verbosity if colors are enabled.
* @param int $verbosity Logging verbosity to used for printing.
* @return ?string Terminal escape sequence to color foreground text.
*/
static function getVerbosityColorMarker(int $verbosity): ?string {
// See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors for reference.
if (!LoggingVerbosity::$showColor) {
return '';
}
return match($verbosity) {
LoggingVerbosity::Error => "\033[31m",
LoggingVerbosity::Warning => "\033[93m",
@ -57,6 +65,16 @@
};
}
/**
* @return ?string Terminal escape sequence to turn off color if colors are enabled.
*/
static function getColorResetMarker(): ?string {
if (!LoggingVerbosity::$showColor) {
return '';
}
return LoggingVerbosity::COLOR_RESET;
}
/**
* Returns a pair of optíons trigerring the given verbosity.
* @param int $verbosity Logging verbosity to set using flag.
@ -101,7 +119,7 @@
$runtime = runtime_str();
$marker = LoggingVerbosity::getVerbosityMarker($message_verbosity);
$color_marker = LoggingVerbosity::getVerbosityColorMarker($message_verbosity);
$color_reset = LoggingVerbosity::COLOR_RESET;
$color_reset = LoggingVerbosity::getColorResetMarker();
// Need to concatenate marker to avoid interpolated array member syntax.
fwrite(STDERR, $color_marker . "[$runtime] [$marker] $msg$color_reset" . PHP_EOL);
}

Loading…
Cancel
Save