Re: Hi all
[notmuch-archives.git] / e5 / 54ee15c0a4d3ca58a4ee658fa6431a4fac8c6b
1 Return-Path: <too@guru-group.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1CA67431FBD\r
6         for <notmuch@notmuchmail.org>; Sat, 24 Aug 2013 06:31:33 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id b-QCM0JgvVzo for <notmuch@notmuchmail.org>;\r
16         Sat, 24 Aug 2013 06:31:23 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id C4F20431FDC\r
19         for <notmuch@notmuchmail.org>; Sat, 24 Aug 2013 06:31:22 -0700 (PDT)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id C2B4710009D; Sat, 24 Aug 2013 16:31:14 +0300 (EEST)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH 1/1] test: pre-set terminal capabilities (colors, boldness)\r
25 Date: Sat, 24 Aug 2013 16:31:13 +0300\r
26 Message-Id: <1377351073-4076-1-git-send-email-tomi.ollila@iki.fi>\r
27 X-Mailer: git-send-email 1.8.0\r
28 Cc: tomi.ollila@iki.fi\r
29 X-BeenThere: notmuch@notmuchmail.org\r
30 X-Mailman-Version: 2.1.13\r
31 Precedence: list\r
32 List-Id: "Use and development of the notmuch mail system."\r
33         <notmuch.notmuchmail.org>\r
34 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
35         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
36 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
37 List-Post: <mailto:notmuch@notmuchmail.org>\r
38 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
39 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
41 X-List-Received-Date: Sat, 24 Aug 2013 13:31:33 -0000\r
42 \r
43 By pre-setting terminal capabilities (colors, boldness) to shell\r
44 variables we avoid the overhead of running external commands (in\r
45 separate subshell) each time colored text is printed to screen.\r
46 ---\r
47  test/test-lib.sh | 84 ++++++++++++++++++++++++++++----------------------------\r
48  1 file changed, 42 insertions(+), 42 deletions(-)\r
49 \r
50 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
51 index ffab1bb..8be2065 100644\r
52 --- a/test/test-lib.sh\r
53 +++ b/test/test-lib.sh\r
54 @@ -38,9 +38,6 @@ done,*)\r
55         ;;\r
56  esac\r
57  \r
58 -# Keep the original TERM for say_color and test_emacs\r
59 -ORIGINAL_TERM=$TERM\r
60 -\r
61  # dtach(1) provides more capable terminal environment to anything\r
62  # that requires more than dumb terminal...\r
63  [ x"${TERM:-dumb}" = xdumb ] && DTACH_TERM=vt100 || DTACH_TERM=$TERM\r
64 @@ -50,8 +47,49 @@ LANG=C\r
65  LC_ALL=C\r
66  PAGER=cat\r
67  TZ=UTC\r
68 +export LANG LC_ALL PAGER TZ\r
69 +\r
70 +if [ x"${TERM:-dumb}" != xdumb ]; then\r
71 +       [ -t 1 ] &&\r
72 +       # http://en.wikipedia.org/wiki/Tput\r
73 +       TC_BOLD=`tput bold 2>/dev/null` &&\r
74 +       TC_RED=`tput setaf 1 2>/dev/null` &&\r
75 +       TC_GREEN=`tput setaf 2 2>/dev/null` &&\r
76 +       TC_YELLOW=`tput setaf 3 2>/dev/null` &&\r
77 +       TC_RESET=`tput sgr0 2>/dev/null` ||\r
78 +       TC_BOLD=\r
79 +else\r
80 +       TC_BOLD=\r
81 +fi\r
82 +\r
83 +if test -n "$TC_BOLD"; then\r
84 +       say_color () {\r
85 +               case "$1" in\r
86 +                       error) printf '%s%s' "$TC_BOLD" "$TC_RED" ;;\r
87 +                       skip)  printf '%s%s' "$TC_BOLD" "$TC_GREEN" ;;\r
88 +                       pass)  printf '%s' "$TC_GREEN" ;;\r
89 +                       info)  printf '%s' "$TC_YELLOW" ;;\r
90 +                       *) test -n "$quiet" && return;;\r
91 +               esac\r
92 +               shift\r
93 +               printf " "\r
94 +               printf "$@"\r
95 +               printf '%s' "$TC_RESET"\r
96 +               print_subtest\r
97 +       }\r
98 +else\r
99 +       say_color() {\r
100 +               test -z "$1" && test -n "$quiet" && return\r
101 +               shift\r
102 +               printf " "\r
103 +               printf "$@"\r
104 +               print_subtest\r
105 +       }\r
106 +fi\r
107 +\r
108  TERM=dumb\r
109 -export LANG LC_ALL PAGER TERM TZ\r
110 +export TERM\r
111 +\r
112  GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\r
113  if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \\r
114        ( -z "$TEST_EMACS" && -n "$TEST_EMACSCLIENT" ) ]]; then\r
115 @@ -82,15 +120,6 @@ _x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"\r
116  # This test checks if command xyzzy does the right thing...\r
117  # '\r
118  # . ./test-lib.sh\r
119 -[ "x$ORIGINAL_TERM" != "xdumb" ] && (\r
120 -               TERM=$ORIGINAL_TERM &&\r
121 -               export TERM &&\r
122 -               [ -t 1 ] &&\r
123 -               tput bold >/dev/null 2>&1 &&\r
124 -               tput setaf 1 >/dev/null 2>&1 &&\r
125 -               tput sgr0 >/dev/null 2>&1\r
126 -       ) &&\r
127 -       color=t\r
128  \r
129  while test "$#" -ne 0\r
130  do\r
131 @@ -136,35 +165,6 @@ else\r
132      }\r
133  fi\r
134  \r
135 -if test -n "$color"; then\r
136 -       say_color () {\r
137 -               (\r
138 -               TERM=$ORIGINAL_TERM\r
139 -               export TERM\r
140 -               case "$1" in\r
141 -                       error) tput bold; tput setaf 1;; # bold red\r
142 -                       skip)  tput bold; tput setaf 2;; # bold green\r
143 -                       pass)  tput setaf 2;;            # green\r
144 -                       info)  tput setaf 3;;            # brown\r
145 -                       *) test -n "$quiet" && return;;\r
146 -               esac\r
147 -               shift\r
148 -               printf " "\r
149 -               printf "$@"\r
150 -               tput sgr0\r
151 -               print_subtest\r
152 -               )\r
153 -       }\r
154 -else\r
155 -       say_color() {\r
156 -               test -z "$1" && test -n "$quiet" && return\r
157 -               shift\r
158 -               printf " "\r
159 -               printf "$@"\r
160 -               print_subtest\r
161 -       }\r
162 -fi\r
163 -\r
164  error () {\r
165         say_color error "error: $*\n"\r
166         GIT_EXIT_OK=t\r
167 -- \r
168 1.8.0\r
169 \r