]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/shell: honor CLICOLOR_FORCE to force coloring in run-tests.sh
authorThomas Haller <thaller@redhat.com>
Thu, 14 Sep 2023 13:16:07 +0000 (15:16 +0200)
committerFlorian Westphal <fw@strlen.de>
Fri, 15 Sep 2023 14:29:45 +0000 (16:29 +0200)
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/

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/run-tests.sh

index 9114eba289afcbe26935fec4bce15785bd2d2125..c5d6307d067e2d7fef209c5b05750f1673893d8a 100755 (executable)
@@ -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() {