[PATCH 1/1] test: pre-set terminal capabilities (colors, boldness)
authorTomi Ollila <tomi.ollila@iki.fi>
Sat, 24 Aug 2013 13:31:13 +0000 (16:31 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:56:37 +0000 (09:56 -0800)
e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b [new file with mode: 0644]

diff --git a/e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b b/e5/54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b
new file mode 100644 (file)
index 0000000..388a846
--- /dev/null
@@ -0,0 +1,169 @@
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1CA67431FBD\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Aug 2013 06:31:33 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id b-QCM0JgvVzo for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Aug 2013 06:31:23 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id C4F20431FDC\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Aug 2013 06:31:22 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id C2B4710009D; Sat, 24 Aug 2013 16:31:14 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/1] test: pre-set terminal capabilities (colors, boldness)\r
+Date: Sat, 24 Aug 2013 16:31:13 +0300\r
+Message-Id: <1377351073-4076-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.8.0\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 24 Aug 2013 13:31:33 -0000\r
+\r
+By pre-setting terminal capabilities (colors, boldness) to shell\r
+variables we avoid the overhead of running external commands (in\r
+separate subshell) each time colored text is printed to screen.\r
+---\r
+ test/test-lib.sh | 84 ++++++++++++++++++++++++++++----------------------------\r
+ 1 file changed, 42 insertions(+), 42 deletions(-)\r
+\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index ffab1bb..8be2065 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -38,9 +38,6 @@ done,*)\r
+       ;;\r
+ esac\r
\r
+-# Keep the original TERM for say_color and test_emacs\r
+-ORIGINAL_TERM=$TERM\r
+-\r
+ # dtach(1) provides more capable terminal environment to anything\r
+ # that requires more than dumb terminal...\r
+ [ x"${TERM:-dumb}" = xdumb ] && DTACH_TERM=vt100 || DTACH_TERM=$TERM\r
+@@ -50,8 +47,49 @@ LANG=C\r
+ LC_ALL=C\r
+ PAGER=cat\r
+ TZ=UTC\r
++export LANG LC_ALL PAGER TZ\r
++\r
++if [ x"${TERM:-dumb}" != xdumb ]; then\r
++      [ -t 1 ] &&\r
++      # http://en.wikipedia.org/wiki/Tput\r
++      TC_BOLD=`tput bold 2>/dev/null` &&\r
++      TC_RED=`tput setaf 1 2>/dev/null` &&\r
++      TC_GREEN=`tput setaf 2 2>/dev/null` &&\r
++      TC_YELLOW=`tput setaf 3 2>/dev/null` &&\r
++      TC_RESET=`tput sgr0 2>/dev/null` ||\r
++      TC_BOLD=\r
++else\r
++      TC_BOLD=\r
++fi\r
++\r
++if test -n "$TC_BOLD"; then\r
++      say_color () {\r
++              case "$1" in\r
++                      error) printf '%s%s' "$TC_BOLD" "$TC_RED" ;;\r
++                      skip)  printf '%s%s' "$TC_BOLD" "$TC_GREEN" ;;\r
++                      pass)  printf '%s' "$TC_GREEN" ;;\r
++                      info)  printf '%s' "$TC_YELLOW" ;;\r
++                      *) test -n "$quiet" && return;;\r
++              esac\r
++              shift\r
++              printf " "\r
++              printf "$@"\r
++              printf '%s' "$TC_RESET"\r
++              print_subtest\r
++      }\r
++else\r
++      say_color() {\r
++              test -z "$1" && test -n "$quiet" && return\r
++              shift\r
++              printf " "\r
++              printf "$@"\r
++              print_subtest\r
++      }\r
++fi\r
++\r
+ TERM=dumb\r
+-export LANG LC_ALL PAGER TERM TZ\r
++export TERM\r
++\r
+ GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\r
+ if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \\r
+       ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then\r
+@@ -82,15 +120,6 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"\r
+ # This test checks if command xyzzy does the right thing...\r
+ # '\r
+ # . ./test-lib.sh\r
+-[ "x$ORIGINAL_TERM" != "xdumb" ] && (\r
+-              TERM=$ORIGINAL_TERM &&\r
+-              export TERM &&\r
+-              [ -t 1 ] &&\r
+-              tput bold >/dev/null 2>&1 &&\r
+-              tput setaf 1 >/dev/null 2>&1 &&\r
+-              tput sgr0 >/dev/null 2>&1\r
+-      ) &&\r
+-      color=t\r
\r
+ while test "$#" -ne 0\r
+ do\r
+@@ -136,35 +165,6 @@ else\r
+     }\r
+ fi\r
\r
+-if test -n "$color"; then\r
+-      say_color () {\r
+-              (\r
+-              TERM=$ORIGINAL_TERM\r
+-              export TERM\r
+-              case "$1" in\r
+-                      error) tput bold; tput setaf 1;; # bold red\r
+-                      skip)  tput bold; tput setaf 2;; # bold green\r
+-                      pass)  tput setaf 2;;            # green\r
+-                      info)  tput setaf 3;;            # brown\r
+-                      *) test -n "$quiet" && return;;\r
+-              esac\r
+-              shift\r
+-              printf " "\r
+-              printf "$@"\r
+-              tput sgr0\r
+-              print_subtest\r
+-              )\r
+-      }\r
+-else\r
+-      say_color() {\r
+-              test -z "$1" && test -n "$quiet" && return\r
+-              shift\r
+-              printf " "\r
+-              printf "$@"\r
+-              print_subtest\r
+-      }\r
+-fi\r
+-\r
+ error () {\r
+       say_color error "error: $*\n"\r
+       GIT_EXIT_OK=t\r
+-- \r
+1.8.0\r
+\r