[PATCH v2 03/16] make shared crypto code behave library-like
[notmuch-archives.git] / d5 / 11d0fa3c9bcb26e1e8226d266b3fafc1b17872
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 65690431FB6\r
6         for <notmuch@notmuchmail.org>; Sun, 20 Jan 2013 13:31:49 -0800 (PST)\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 RAWc-zT7a3OS for <notmuch@notmuchmail.org>;\r
16         Sun, 20 Jan 2013 13:31:48 -0800 (PST)\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 07912431FAF\r
19         for <notmuch@notmuchmail.org>; Sun, 20 Jan 2013 13:31:48 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id A6949100093; Sun, 20 Jan 2013 23:31:36 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH 1/1] test/test-lib.sh: use $test_subtest_name in all tests\r
25 Date: Sun, 20 Jan 2013 23:31:33 +0200\r
26 Message-Id: <1358717493-11231-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: Sun, 20 Jan 2013 21:31:49 -0000\r
42 \r
43 Set the variable '$test_subtest_name' in all functions which starts\r
44 a new test and use that variable in all functions that output\r
45 test results.\r
46 \r
47 Additionally output the latest '$test_subtest_name' in case of\r
48 abnormal exit, to avoid confusion.\r
49 ---\r
50 \r
51 The main reason to do this change is to get latest '$test_subtest_name'\r
52 printed in case of abnormal exit. I cherry-picked this change from a\r
53 larger work-in-progress patch set that adds 'set -e -o pipefail' support...\r
54 \r
55 I am pretty sure I got all the cases covered. If not, we'll notice\r
56 it later when some test fail in a way I could not anticipate.\r
57 Anyway, tests success & fail as they used to be.\r
58 \r
59  test/test-lib.sh | 52 +++++++++++++++++++++++++++++-----------------------\r
60  1 file changed, 29 insertions(+), 23 deletions(-)\r
61 \r
62 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
63 index 6ce3b31..58e7b93 100644\r
64 --- a/test/test-lib.sh\r
65 +++ b/test/test-lib.sh\r
66 @@ -197,7 +197,11 @@ die () {\r
67         then\r
68                 exit $code\r
69         else\r
70 -               echo >&5 "FATAL: Unexpected exit with code $code"\r
71 +               exec 5>&1\r
72 +               say_color error '%-6s' FATAL\r
73 +               echo " $test_subtest_name"\r
74 +               echo\r
75 +               echo "Unexpected exit while executing $0. Exit code $code."\r
76                 exit 1\r
77         fi\r
78  }\r
79 @@ -494,12 +498,12 @@ test_expect_equal ()\r
80         if ! test_skip "$test_subtest_name"\r
81         then\r
82                 if [ "$output" = "$expected" ]; then\r
83 -                       test_ok_ "$test_subtest_name"\r
84 +                       test_ok_\r
85                 else\r
86                         testname=$this_test.$test_count\r
87                         echo "$expected" > $testname.expected\r
88                         echo "$output" > $testname.output\r
89 -                       test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"\r
90 +                       test_failure_ "$(diff -u $testname.expected $testname.output)"\r
91                 fi\r
92      fi\r
93  }\r
94 @@ -520,12 +524,12 @@ test_expect_equal_file ()\r
95         if ! test_skip "$test_subtest_name"\r
96         then\r
97                 if diff -q "$file1" "$file2" >/dev/null ; then\r
98 -                       test_ok_ "$test_subtest_name"\r
99 +                       test_ok_\r
100                 else\r
101                         testname=$this_test.$test_count\r
102                         cp "$file1" "$testname.$basename1"\r
103                         cp "$file2" "$testname.$basename2"\r
104 -                       test_failure_ "$test_subtest_name" "$(diff -u "$testname.$basename1" "$testname.$basename2")"\r
105 +                       test_failure_ "$(diff -u "$testname.$basename1" "$testname.$basename2")"\r
106                 fi\r
107      fi\r
108  }\r
109 @@ -563,9 +567,9 @@ test_emacs_expect_t () {\r
110                 result=$(cat OUTPUT)\r
111                 if [ "$result" = t ]\r
112                 then\r
113 -                       test_ok_ "$test_subtest_name"\r
114 +                       test_ok_\r
115                 else\r
116 -                       test_failure_ "$test_subtest_name" "${result}"\r
117 +                       test_failure_ "${result}"\r
118                 fi\r
119         else\r
120                 # Restore state after the (non) test.\r
121 @@ -666,12 +670,12 @@ test_require_external_prereq () {\r
122  \r
123  test_ok_ () {\r
124         if test "$test_subtest_known_broken_" = "t"; then\r
125 -               test_known_broken_ok_ "$@"\r
126 +               test_known_broken_ok_\r
127                 return\r
128         fi\r
129         test_success=$(($test_success + 1))\r
130         say_color pass "%-6s" "PASS"\r
131 -       echo " $@"\r
132 +       echo " $test_subtest_name"\r
133  }\r
134  \r
135  test_failure_ () {\r
136 @@ -680,7 +684,7 @@ test_failure_ () {\r
137                 return\r
138         fi\r
139         test_failure=$(($test_failure + 1))\r
140 -       test_failure_message_ "FAIL" "$@"\r
141 +       test_failure_message_ "FAIL" "$test_subtest_name" "$@"\r
142         test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }\r
143         return 1\r
144  }\r
145 @@ -697,13 +701,13 @@ test_known_broken_ok_ () {\r
146         test_reset_state_\r
147         test_fixed=$(($test_fixed+1))\r
148         say_color pass "%-6s" "FIXED"\r
149 -       echo " $@"\r
150 +       echo " $test_subtest_name"\r
151  }\r
152  \r
153  test_known_broken_failure_ () {\r
154         test_reset_state_\r
155         test_broken=$(($test_broken+1))\r
156 -       test_failure_message_ "BROKEN" "$@"\r
157 +       test_failure_message_ "BROKEN" "$test_subtest_name" "$@"\r
158         return 1\r
159  }\r
160  \r
161 @@ -771,6 +775,7 @@ test_expect_success () {\r
162         test "$#" = 3 && { prereq=$1; shift; } || prereq=\r
163         test "$#" = 2 ||\r
164         error "bug in the test script: not 2 or 3 parameters to test-expect-success"\r
165 +       test_subtest_name="$1"\r
166         test_reset_state_\r
167         if ! test_skip "$@"\r
168         then\r
169 @@ -780,9 +785,9 @@ test_expect_success () {\r
170                 test_check_missing_external_prereqs_ "$@" ||\r
171                 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]\r
172                 then\r
173 -                       test_ok_ "$1"\r
174 +                       test_ok_\r
175                 else\r
176 -                       test_failure_ "$@"\r
177 +                       test_failure_ "$2"\r
178                 fi\r
179         fi\r
180  }\r
181 @@ -791,6 +796,7 @@ test_expect_code () {\r
182         test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
183         test "$#" = 3 ||\r
184         error "bug in the test script: not 3 or 4 parameters to test-expect-code"\r
185 +       test_subtest_name="$2"\r
186         test_reset_state_\r
187         if ! test_skip "$@"\r
188         then\r
189 @@ -800,9 +806,9 @@ test_expect_code () {\r
190                 test_check_missing_external_prereqs_ "$@" ||\r
191                 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]\r
192                 then\r
193 -                       test_ok_ "$2"\r
194 +                       test_ok_\r
195                 else\r
196 -                       test_failure_ "$@"\r
197 +                       test_failure_ "exit code $eval_ret, expected $1" "$3"\r
198                 fi\r
199         fi\r
200  }\r
201 @@ -819,10 +825,10 @@ test_external () {\r
202         test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
203         test "$#" = 3 ||\r
204         error >&5 "bug in the test script: not 3 or 4 parameters to test_external"\r
205 -       descr="$1"\r
206 +       test_subtest_name="$1"\r
207         shift\r
208         test_reset_state_\r
209 -       if ! test_skip "$descr" "$@"\r
210 +       if ! test_skip "$test_subtest_name" "$@"\r
211         then\r
212                 # Announce the script to reduce confusion about the\r
213                 # test output that follows.\r
214 @@ -833,9 +839,9 @@ test_external () {\r
215                 "$@" 2>&4\r
216                 if [ "$?" = 0 ]\r
217                 then\r
218 -                       test_ok_ "$descr"\r
219 +                       test_ok_\r
220                 else\r
221 -                       test_failure_ "$descr" "$@"\r
222 +                       test_failure_ "$@"\r
223                 fi\r
224         fi\r
225  }\r
226 @@ -849,11 +855,11 @@ test_external_without_stderr () {\r
227         stderr="$tmp/git-external-stderr.$$.tmp"\r
228         test_external "$@" 4> "$stderr"\r
229         [ -f "$stderr" ] || error "Internal error: $stderr disappeared."\r
230 -       descr="no stderr: $1"\r
231 +       test_subtest_name="no stderr: $1"\r
232         shift\r
233         if [ ! -s "$stderr" ]; then\r
234                 rm "$stderr"\r
235 -               test_ok_ "$descr"\r
236 +               test_ok_\r
237         else\r
238                 if [ "$verbose" = t ]; then\r
239                         output=`echo; echo Stderr is:; cat "$stderr"`\r
240 @@ -862,7 +868,7 @@ test_external_without_stderr () {\r
241                 fi\r
242                 # rm first in case test_failure exits.\r
243                 rm "$stderr"\r
244 -               test_failure_ "$descr" "$@" "$output"\r
245 +               test_failure_ "$@" "$output"\r
246         fi\r
247  }\r
248  \r
249 -- \r
250 1.8.0.2\r
251 \r