Skip to contentSkip to conversation

tests/shell: honor CLICOLOR_FORCE to force coloring in run-tests.sh

PATCH New Thomas Haller 1 participant 1 message Sep 14, 2023 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/shell: honor CLICOLOR_FORCE to force coloring in run-tests.sh

We honor NO_COLOR= to disable coloring, let's also honor CLICOLOR_FORCE= to enable it.

The purpose will be for make calling the script and redirecting to a file, while enabling colors.

See-also: https://bixense.com/clicolors/

---
 tests/shell/run-tests.sh | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
tests/shell/run-tests.sh +10 -5
index f75505f7f1b4..bf5fc382ac04 100755
@@ -4,11 +4,16 @@ GREEN=""
 YELLOW=""
 RED=""
 RESET=""
-if [[ -t 1 && -z "$NO_COLOR" ]] ; then
-	GREEN=$'\e[32m'
-	YELLOW=$'\e[33m'
-	RED=$'\e[31m'
-	RESET=$'\e[0m'
+if [ -z "$NO_COLOR" ] ; then
+	if [ -n "$CLICOLOR_FORCE" ] || [[ -t 1 ]] ; then
+		# See https://bixense.com/clicolors/ . We only check isatty() on
+		# file descriptor 1, to decide whether colorizing happens (although,
+		# we might also colorize on other places/FDs).
+		GREEN=$'\e[32m'
+		YELLOW=$'\e[33m'
+		RED=$'\e[31m'
+		RESET=$'\e[0m'
+	fi
 fi
 
 array_contains() {
Signature · 1 line
2.41.0