Re: Avoiding the "huge INBOX of death"
[notmuch-archives.git] / dc / 773f0de7af77632cdc520c00d959ecc3de126e
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 5129D431FB6\r
6         for <notmuch@notmuchmail.org>; Sun, 20 Jan 2013 19:02:03 -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 XUsXVkNrAHZ9 for <notmuch@notmuchmail.org>;\r
16         Sun, 20 Jan 2013 19:02:01 -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 4E70A431FAF\r
19         for <notmuch@notmuchmail.org>; Sun, 20 Jan 2013 19:02:01 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id EF1E7100093; Mon, 21 Jan 2013 05:01:47 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: notmuch@notmuchmail.org\r
24 Subject: [PATCH 1/2] test/test-lib.sh: use $test_subtest_name in all tests\r
25 Date: Mon, 21 Jan 2013 05:01:45 +0200\r
26 Message-Id: <1358737306-21744-1-git-send-email-tomi.ollila@iki.fi>\r
27 X-Mailer: git-send-email 1.8.0\r
28 In-Reply-To: <id:1358717493-11231-1-git-send-email-tomi.ollila@iki.fi>\r
29 References: <id:1358717493-11231-1-git-send-email-tomi.ollila@iki.fi>\r
30 Cc: tomi.ollila@iki.fi\r
31 X-BeenThere: notmuch@notmuchmail.org\r
32 X-Mailman-Version: 2.1.13\r
33 Precedence: list\r
34 List-Id: "Use and development of the notmuch mail system."\r
35         <notmuch.notmuchmail.org>\r
36 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
37         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
38 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
39 List-Post: <mailto:notmuch@notmuchmail.org>\r
40 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
41 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
43 X-List-Received-Date: Mon, 21 Jan 2013 03:02:03 -0000\r
44 \r
45 Set the variable '$test_subtest_name' in all functions which starts\r
46 a new test and use that variable in all functions that output\r
47 test results.\r
48 \r
49 Additionally output the latest '$test_subtest_name' in case of\r
50 abnormal exit, to avoid confusion.\r
51 ---\r
52 \r
53 This obsoletes id:1358717806-11376-1-git-send-email-tomi.ollila@iki.fi\r
54 which had fd:s in function 'die' wrong order in 'exec [1]>&5' line.\r
55 I did plenty of (ad hoc) hand-testing for this but failed to notice that\r
56 messages weren't always as verbose as those should have been. The wip\r
57 patch set mentioned below has it right but this was hand-rewritten as\r
58 this is somewhat different here...\r
59 \r
60 The main reason to do this change is to get latest '$test_subtest_name'\r
61 printed in case of abnormal exit. I cherry-picked this change from a\r
62 larger work-in-progress patch set that adds 'set -e -o pipefail' support...\r
63 \r
64 I am pretty sure I got all the cases covered. If not, we'll notice\r
65 it later when some test fail in a way I could not anticipate.\r
66 Anyway, tests success & fail as they used to be.\r
67 \r
68  test/test-lib.sh | 52 +++++++++++++++++++++++++++++-----------------------\r
69  1 file changed, 29 insertions(+), 23 deletions(-)\r
70 \r
71 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
72 index 6ce3b31..0098bfd 100644\r
73 --- a/test/test-lib.sh\r
74 +++ b/test/test-lib.sh\r
75 @@ -197,7 +197,11 @@ die () {\r
76         then\r
77                 exit $code\r
78         else\r
79 -               echo >&5 "FATAL: Unexpected exit with code $code"\r
80 +               exec >&5\r
81 +               say_color error '%-6s' FATAL\r
82 +               echo " $test_subtest_name"\r
83 +               echo\r
84 +               echo "Unexpected exit while executing $0. Exit code $code."\r
85                 exit 1\r
86         fi\r
87  }\r
88 @@ -494,12 +498,12 @@ test_expect_equal ()\r
89         if ! test_skip "$test_subtest_name"\r
90         then\r
91                 if [ "$output" = "$expected" ]; then\r
92 -                       test_ok_ "$test_subtest_name"\r
93 +                       test_ok_\r
94                 else\r
95                         testname=$this_test.$test_count\r
96                         echo "$expected" > $testname.expected\r
97                         echo "$output" > $testname.output\r
98 -                       test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"\r
99 +                       test_failure_ "$(diff -u $testname.expected $testname.output)"\r
100                 fi\r
101      fi\r
102  }\r
103 @@ -520,12 +524,12 @@ test_expect_equal_file ()\r
104         if ! test_skip "$test_subtest_name"\r
105         then\r
106                 if diff -q "$file1" "$file2" >/dev/null ; then\r
107 -                       test_ok_ "$test_subtest_name"\r
108 +                       test_ok_\r
109                 else\r
110                         testname=$this_test.$test_count\r
111                         cp "$file1" "$testname.$basename1"\r
112                         cp "$file2" "$testname.$basename2"\r
113 -                       test_failure_ "$test_subtest_name" "$(diff -u "$testname.$basename1" "$testname.$basename2")"\r
114 +                       test_failure_ "$(diff -u "$testname.$basename1" "$testname.$basename2")"\r
115                 fi\r
116      fi\r
117  }\r
118 @@ -563,9 +567,9 @@ test_emacs_expect_t () {\r
119                 result=$(cat OUTPUT)\r
120                 if [ "$result" = t ]\r
121                 then\r
122 -                       test_ok_ "$test_subtest_name"\r
123 +                       test_ok_\r
124                 else\r
125 -                       test_failure_ "$test_subtest_name" "${result}"\r
126 +                       test_failure_ "${result}"\r
127                 fi\r
128         else\r
129                 # Restore state after the (non) test.\r
130 @@ -666,12 +670,12 @@ test_require_external_prereq () {\r
131  \r
132  test_ok_ () {\r
133         if test "$test_subtest_known_broken_" = "t"; then\r
134 -               test_known_broken_ok_ "$@"\r
135 +               test_known_broken_ok_\r
136                 return\r
137         fi\r
138         test_success=$(($test_success + 1))\r
139         say_color pass "%-6s" "PASS"\r
140 -       echo " $@"\r
141 +       echo " $test_subtest_name"\r
142  }\r
143  \r
144  test_failure_ () {\r
145 @@ -680,7 +684,7 @@ test_failure_ () {\r
146                 return\r
147         fi\r
148         test_failure=$(($test_failure + 1))\r
149 -       test_failure_message_ "FAIL" "$@"\r
150 +       test_failure_message_ "FAIL" "$test_subtest_name" "$@"\r
151         test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }\r
152         return 1\r
153  }\r
154 @@ -697,13 +701,13 @@ test_known_broken_ok_ () {\r
155         test_reset_state_\r
156         test_fixed=$(($test_fixed+1))\r
157         say_color pass "%-6s" "FIXED"\r
158 -       echo " $@"\r
159 +       echo " $test_subtest_name"\r
160  }\r
161  \r
162  test_known_broken_failure_ () {\r
163         test_reset_state_\r
164         test_broken=$(($test_broken+1))\r
165 -       test_failure_message_ "BROKEN" "$@"\r
166 +       test_failure_message_ "BROKEN" "$test_subtest_name" "$@"\r
167         return 1\r
168  }\r
169  \r
170 @@ -771,6 +775,7 @@ test_expect_success () {\r
171         test "$#" = 3 && { prereq=$1; shift; } || prereq=\r
172         test "$#" = 2 ||\r
173         error "bug in the test script: not 2 or 3 parameters to test-expect-success"\r
174 +       test_subtest_name="$1"\r
175         test_reset_state_\r
176         if ! test_skip "$@"\r
177         then\r
178 @@ -780,9 +785,9 @@ test_expect_success () {\r
179                 test_check_missing_external_prereqs_ "$@" ||\r
180                 if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]\r
181                 then\r
182 -                       test_ok_ "$1"\r
183 +                       test_ok_\r
184                 else\r
185 -                       test_failure_ "$@"\r
186 +                       test_failure_ "$2"\r
187                 fi\r
188         fi\r
189  }\r
190 @@ -791,6 +796,7 @@ test_expect_code () {\r
191         test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
192         test "$#" = 3 ||\r
193         error "bug in the test script: not 3 or 4 parameters to test-expect-code"\r
194 +       test_subtest_name="$2"\r
195         test_reset_state_\r
196         if ! test_skip "$@"\r
197         then\r
198 @@ -800,9 +806,9 @@ test_expect_code () {\r
199                 test_check_missing_external_prereqs_ "$@" ||\r
200                 if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]\r
201                 then\r
202 -                       test_ok_ "$2"\r
203 +                       test_ok_\r
204                 else\r
205 -                       test_failure_ "$@"\r
206 +                       test_failure_ "exit code $eval_ret, expected $1" "$3"\r
207                 fi\r
208         fi\r
209  }\r
210 @@ -819,10 +825,10 @@ test_external () {\r
211         test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
212         test "$#" = 3 ||\r
213         error >&5 "bug in the test script: not 3 or 4 parameters to test_external"\r
214 -       descr="$1"\r
215 +       test_subtest_name="$1"\r
216         shift\r
217         test_reset_state_\r
218 -       if ! test_skip "$descr" "$@"\r
219 +       if ! test_skip "$test_subtest_name" "$@"\r
220         then\r
221                 # Announce the script to reduce confusion about the\r
222                 # test output that follows.\r
223 @@ -833,9 +839,9 @@ test_external () {\r
224                 "$@" 2>&4\r
225                 if [ "$?" = 0 ]\r
226                 then\r
227 -                       test_ok_ "$descr"\r
228 +                       test_ok_\r
229                 else\r
230 -                       test_failure_ "$descr" "$@"\r
231 +                       test_failure_ "$@"\r
232                 fi\r
233         fi\r
234  }\r
235 @@ -849,11 +855,11 @@ test_external_without_stderr () {\r
236         stderr="$tmp/git-external-stderr.$$.tmp"\r
237         test_external "$@" 4> "$stderr"\r
238         [ -f "$stderr" ] || error "Internal error: $stderr disappeared."\r
239 -       descr="no stderr: $1"\r
240 +       test_subtest_name="no stderr: $1"\r
241         shift\r
242         if [ ! -s "$stderr" ]; then\r
243                 rm "$stderr"\r
244 -               test_ok_ "$descr"\r
245 +               test_ok_\r
246         else\r
247                 if [ "$verbose" = t ]; then\r
248                         output=`echo; echo Stderr is:; cat "$stderr"`\r
249 @@ -862,7 +868,7 @@ test_external_without_stderr () {\r
250                 fi\r
251                 # rm first in case test_failure exits.\r
252                 rm "$stderr"\r
253 -               test_failure_ "$descr" "$@" "$output"\r
254 +               test_failure_ "$@" "$output"\r
255         fi\r
256  }\r
257  \r
258 -- \r
259 1.8.0\r
260 \r