unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test-lib.sh: colors to test output when parallel(1) is run on tty
@ 2019-05-08 18:51 Tomi Ollila
  2019-05-23 11:40 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: Tomi Ollila @ 2019-05-08 18:51 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

Done via $COLORS_WITHOUT_TTY environment variable as passing options
to commands through parallel(1) does not look trivial.

Reorganized color checking in test-lib.sh a bit for this (perhaps
were not fully necessary but rest still an improvement):

  - color checking commands in subshell are not run before arg parsing
    (args may disable colors with --no-color)

  - [ -t 1 ] is checked before forking subshell
---
 test/notmuch-test |  1 +
 test/test-lib.sh  | 25 ++++++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/test/notmuch-test b/test/notmuch-test
index bd3e080af01e..df10ccf22b04 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -41,6 +41,7 @@ fi
 trap 'e=$?; kill $!; exit $e' HUP INT TERM
 # Run the tests
 if test -z "$NOTMUCH_TEST_SERIALIZE" && command -v parallel >/dev/null ; then
+    test -t 1 && export COLORS_WITHOUT_TTY=t || :
     if parallel -h | grep -q GNU ; then
         echo "INFO: running tests with GNU parallel"
         printf '%s\n' $TESTS | $TEST_TIMEOUT_CMD parallel
diff --git a/test/test-lib.sh b/test/test-lib.sh
index f5d367aae2d7..0a0004a5c7a3 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -131,15 +131,7 @@ add_gnupg_home ()
 # '
 # . ./test-lib.sh || exit 1
 
-[ "x$ORIGINAL_TERM" != "xdumb" ] && (
-		TERM=$ORIGINAL_TERM &&
-		export TERM &&
-		[ -t 1 ] &&
-		tput bold >/dev/null 2>&1 &&
-		tput setaf 1 >/dev/null 2>&1 &&
-		tput sgr0 >/dev/null 2>&1
-	) &&
-	color=t
+color=maybe
 
 while test "$#" -ne 0
 do
@@ -180,6 +172,21 @@ else
     }
 fi
 
+test -n "$COLORS_WITHOUT_TTY" || [ -t 1 ] || color=
+
+if [ -n "$color" ] && [ "$ORIGINAL_TERM" != 'dumb' ] && (
+		TERM=$ORIGINAL_TERM &&
+		export TERM &&
+		tput bold
+		tput setaf
+		tput sgr0
+	) >/dev/null 2>&1
+then
+	color=t
+else
+	color=
+fi
+
 if test -n "$color"; then
 	say_color () {
 		(
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] test-lib.sh: colors to test output when parallel(1) is run on tty
  2019-05-08 18:51 [PATCH] test-lib.sh: colors to test output when parallel(1) is run on tty Tomi Ollila
@ 2019-05-23 11:40 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2019-05-23 11:40 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> Done via $COLORS_WITHOUT_TTY environment variable as passing options
> to commands through parallel(1) does not look trivial.

pushed to master

d

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-23 11:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 18:51 [PATCH] test-lib.sh: colors to test output when parallel(1) is run on tty Tomi Ollila
2019-05-23 11:40 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).