Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / fb / 2c16aa0e218483d66cf965a0e9b045631da2fc
1 Return-Path: <sojkam1@fel.cvut.cz>\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 8261D431FC1\r
6         for <notmuch@notmuchmail.org>; Wed,  9 Jun 2010 23:49:12 -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: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\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 1ijT7qQYv8vC for <notmuch@notmuchmail.org>;\r
16         Wed,  9 Jun 2010 23:48:55 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 382BC4196F3\r
19         for <notmuch@notmuchmail.org>; Wed,  9 Jun 2010 23:48:36 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 892B219F33ED;\r
22         Thu, 10 Jun 2010 08:48:35 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id FTA238JKBtlT; Thu, 10 Jun 2010 08:48:33 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 33AC419F35DE;\r
30         Thu, 10 Jun 2010 08:48:32 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 2B3FE15C062;\r
34         Thu, 10 Jun 2010 08:48:32 +0200 (CEST)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.72)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1OMbZ1-0000JX-Py; Thu, 10 Jun 2010 08:48:31 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v3 2/5] Update test framework for use with notmuch\r
41 Date: Thu, 10 Jun 2010 08:48:01 +0200\r
42 Message-Id: <1276152484-1164-3-git-send-email-sojkam1@fel.cvut.cz>\r
43 X-Mailer: git-send-email 1.7.1.3.g75e44\r
44 In-Reply-To: <1276152484-1164-1-git-send-email-sojkam1@fel.cvut.cz>\r
45 References: <1276152484-1164-1-git-send-email-sojkam1@fel.cvut.cz>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Thu, 10 Jun 2010 06:49:12 -0000\r
59 \r
60 This removes Git specific things from the test-lib.sh and adds helper\r
61 functions for notmuch taken from Carl's notmuch-test script. README is\r
62 also slightly modified to reflect the current state.\r
63 \r
64 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
65 ---\r
66  test/Makefile       |    1 +\r
67  test/README         |   12 +-\r
68  test/t0000-basic.sh |  335 +++-------------------------------------------\r
69  test/test-lib.sh    |  374 +++++++++++++++++++++++++++++++--------------------\r
70  4 files changed, 256 insertions(+), 466 deletions(-)\r
71 \r
72 diff --git a/test/Makefile b/test/Makefile\r
73 index 25c559b..7a29eaa 100644\r
74 --- a/test/Makefile\r
75 +++ b/test/Makefile\r
76 @@ -6,6 +6,7 @@\r
77  -include ../config.mak\r
78  \r
79  #GIT_TEST_OPTS=--verbose --debug\r
80 +SHELL=/bin/bash\r
81  SHELL_PATH ?= $(SHELL)\r
82  TAR ?= $(TAR)\r
83  RM ?= rm -f\r
84 diff --git a/test/README b/test/README\r
85 index dcd3ebb..af27d60 100644\r
86 --- a/test/README\r
87 +++ b/test/README\r
88 @@ -165,10 +165,10 @@ Writing Tests\r
89  -------------\r
90  \r
91  The test script is written as a shell script.  It should start\r
92 -with the standard "#!/bin/sh" with copyright notices, and an\r
93 +with the standard "#!/bin/bash" with copyright notices, and an\r
94  assignment to variable 'test_description', like this:\r
95  \r
96 -       #!/bin/sh\r
97 +       #!/bin/bash\r
98         #\r
99         # Copyright (c) 2005 Junio C Hamano\r
100         #\r
101 @@ -192,9 +192,11 @@ This test harness library does the following things:\r
102   - If the script is invoked with command line argument --help\r
103     (or -h), it shows the test_description and exits.\r
104  \r
105 - - Creates an empty test directory with an empty .git/objects\r
106 -   database and chdir(2) into it.  This directory is 't/trash directory'\r
107 -   if you must know, but I do not think you care.\r
108 + - Creates a test directory with default notmuch-config and empty mail\r
109 +   store. This directory is 't/trash directory.<test-basename>' (note\r
110 +   the space) if you must know, but I do not think you care. The path\r
111 +   to notmuch-config is exported in NOTMUCH_CONFIG environment\r
112 +   variable and mail store path is stored in MAIL_DIR variable.\r
113  \r
114   - Defines standard test helper functions for your scripts to\r
115     use.  These functions are designed to make all scripts behave\r
116 diff --git a/test/t0000-basic.sh b/test/t0000-basic.sh\r
117 index 3ec9cbe..caade68 100755\r
118 --- a/test/t0000-basic.sh\r
119 +++ b/test/t0000-basic.sh\r
120 @@ -3,48 +3,39 @@\r
121  # Copyright (c) 2005 Junio C Hamano\r
122  #\r
123  \r
124 -test_description='Test the very basics part #1.\r
125 -\r
126 -The rest of the test suite does not check the basic operation of git\r
127 -plumbing commands to work very carefully.  Their job is to concentrate\r
128 -on tricky features that caused bugs in the past to detect regression.\r
129 -\r
130 -This test runs very basic features, like registering things in cache,\r
131 -writing tree, etc.\r
132 -\r
133 -Note that this test *deliberately* hard-codes many expected object\r
134 -IDs.  When object ID computation changes, like in the previous case of\r
135 -swapping compression and hashing order, the person who is making the\r
136 -modification *should* take notice and update the test vectors here.\r
137 -'\r
138 +test_description='Tests the test framework itself.'\r
139  \r
140  ################################################################\r
141  # It appears that people try to run tests without building...\r
142  \r
143 -../git >/dev/null\r
144 -if test $? != 1\r
145 +if ! test -x ../notmuch\r
146  then\r
147 -       echo >&2 'You do not seem to have built git yet.'\r
148 +       echo >&2 'You do not seem to have built notmuch yet.'\r
149         exit 1\r
150  fi\r
151  \r
152  . ./test-lib.sh\r
153  \r
154  ################################################################\r
155 -# git init has been done in an empty repository.\r
156 -# make sure it is empty.\r
157 +# Test mail store prepared in test-lib.sh\r
158  \r
159 -find .git/objects -type f -print >should-be-empty\r
160  test_expect_success \\r
161 -    '.git/objects should be empty after git init in an empty repo.' \\r
162 +    'test that mail store was created' \\r
163 +    'test -d "${MAIL_DIR}"'\r
164 +\r
165 +\r
166 +find "${MAIL_DIR}" -type f -print >should-be-empty\r
167 +test_expect_success \\r
168 +    'mail store should be empty' \\r
169      'cmp -s /dev/null should-be-empty'\r
170  \r
171 -# also it should have 2 subdirectories; no fan-out anymore, pack, and info.\r
172 -# 3 is counting "objects" itself\r
173 -find .git/objects -type d -print >full-of-directories\r
174  test_expect_success \\r
175 -    '.git/objects should have 3 subdirectories.' \\r
176 -    'test $(wc -l < full-of-directories) = 3'\r
177 +    'NOTMUCH_CONFIG is set and points to an existing file' \\r
178 +    'test -f "${NOTMUCH_CONFIG}"'\r
179 +\r
180 +test_expect_success \\r
181 +    'PATH is set to this repository' \\r
182 +    'test "`echo $PATH|cut -f1 -d:`" = "`dirname ${TEST_DIRECTORY}`"'\r
183  \r
184  ################################################################\r
185  # Test harness\r
186 @@ -94,296 +85,4 @@ test_expect_code 2 'failure to clean up causes the test to fail' '\r
187      test_when_finished "(exit 2)"\r
188  '\r
189  \r
190 -################################################################\r
191 -# Basics of the basics\r
192 -\r
193 -# updating a new file without --add should fail.\r
194 -test_expect_success 'git update-index without --add should fail adding.' '\r
195 -    test_must_fail git update-index should-be-empty\r
196 -'\r
197 -\r
198 -# and with --add it should succeed, even if it is empty (it used to fail).\r
199 -test_expect_success \\r
200 -    'git update-index with --add should succeed.' \\r
201 -    'git update-index --add should-be-empty'\r
202 -\r
203 -test_expect_success \\r
204 -    'writing tree out with git write-tree' \\r
205 -    'tree=$(git write-tree)'\r
206 -\r
207 -# we know the shape and contents of the tree and know the object ID for it.\r
208 -test_expect_success \\r
209 -    'validate object ID of a known tree.' \\r
210 -    'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'\r
211 -\r
212 -# Removing paths.\r
213 -rm -f should-be-empty full-of-directories\r
214 -test_expect_success 'git update-index without --remove should fail removing.' '\r
215 -    test_must_fail git update-index should-be-empty\r
216 -'\r
217 -\r
218 -test_expect_success \\r
219 -    'git update-index with --remove should be able to remove.' \\r
220 -    'git update-index --remove should-be-empty'\r
221 -\r
222 -# Empty tree can be written with recent write-tree.\r
223 -test_expect_success \\r
224 -    'git write-tree should be able to write an empty tree.' \\r
225 -    'tree=$(git write-tree)'\r
226 -\r
227 -test_expect_success \\r
228 -    'validate object ID of a known tree.' \\r
229 -    'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'\r
230 -\r
231 -# Various types of objects\r
232 -# Some filesystems do not support symblic links; on such systems\r
233 -# some expected values are different\r
234 -mkdir path2 path3 path3/subp3\r
235 -paths='path0 path2/file2 path3/file3 path3/subp3/file3'\r
236 -for p in $paths\r
237 -do\r
238 -    echo "hello $p" >$p\r
239 -done\r
240 -if test_have_prereq SYMLINKS\r
241 -then\r
242 -       for p in $paths\r
243 -       do\r
244 -               ln -s "hello $p" ${p}sym\r
245 -       done\r
246 -       expectfilter=cat\r
247 -       expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b\r
248 -       expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3\r
249 -       expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2\r
250 -else\r
251 -       expectfilter='grep -v sym'\r
252 -       expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46\r
253 -       expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325\r
254 -       expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f\r
255 -fi\r
256 -\r
257 -test_expect_success \\r
258 -    'adding various types of objects with git update-index --add.' \\r
259 -    'find path* ! -type d -print | xargs git update-index --add'\r
260 -\r
261 -# Show them and see that matches what we expect.\r
262 -test_expect_success \\r
263 -    'showing stage with git ls-files --stage' \\r
264 -    'git ls-files --stage >current'\r
265 -\r
266 -$expectfilter >expected <<\EOF\r
267 -100644 f87290f8eb2cbbea7857214459a0739927eab154 0      path0\r
268 -120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0      path0sym\r
269 -100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0      path2/file2\r
270 -120000 d8ce161addc5173867a3c3c730924388daedbc38 0      path2/file2sym\r
271 -100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0      path3/file3\r
272 -120000 8599103969b43aff7e430efea79ca4636466794f 0      path3/file3sym\r
273 -100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0      path3/subp3/file3\r
274 -120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0      path3/subp3/file3sym\r
275 -EOF\r
276 -test_expect_success \\r
277 -    'validate git ls-files output for a known tree.' \\r
278 -    'test_cmp expected current'\r
279 -\r
280 -test_expect_success \\r
281 -    'writing tree out with git write-tree.' \\r
282 -    'tree=$(git write-tree)'\r
283 -test_expect_success \\r
284 -    'validate object ID for a known tree.' \\r
285 -    'test "$tree" = "$expectedtree"'\r
286 -\r
287 -test_expect_success \\r
288 -    'showing tree with git ls-tree' \\r
289 -    'git ls-tree $tree >current'\r
290 -cat >expected <<\EOF\r
291 -100644 blob f87290f8eb2cbbea7857214459a0739927eab154   path0\r
292 -120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01   path0sym\r
293 -040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe   path2\r
294 -040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3   path3\r
295 -EOF\r
296 -test_expect_success SYMLINKS \\r
297 -    'git ls-tree output for a known tree.' \\r
298 -    'test_cmp expected current'\r
299 -\r
300 -# This changed in ls-tree pathspec change -- recursive does\r
301 -# not show tree nodes anymore.\r
302 -test_expect_success \\r
303 -    'showing tree with git ls-tree -r' \\r
304 -    'git ls-tree -r $tree >current'\r
305 -$expectfilter >expected <<\EOF\r
306 -100644 blob f87290f8eb2cbbea7857214459a0739927eab154   path0\r
307 -120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01   path0sym\r
308 -100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7   path2/file2\r
309 -120000 blob d8ce161addc5173867a3c3c730924388daedbc38   path2/file2sym\r
310 -100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376   path3/file3\r
311 -120000 blob 8599103969b43aff7e430efea79ca4636466794f   path3/file3sym\r
312 -100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f   path3/subp3/file3\r
313 -120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c   path3/subp3/file3sym\r
314 -EOF\r
315 -test_expect_success \\r
316 -    'git ls-tree -r output for a known tree.' \\r
317 -    'test_cmp expected current'\r
318 -\r
319 -# But with -r -t we can have both.\r
320 -test_expect_success \\r
321 -    'showing tree with git ls-tree -r -t' \\r
322 -    'git ls-tree -r -t $tree >current'\r
323 -cat >expected <<\EOF\r
324 -100644 blob f87290f8eb2cbbea7857214459a0739927eab154   path0\r
325 -120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01   path0sym\r
326 -040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe   path2\r
327 -100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7   path2/file2\r
328 -120000 blob d8ce161addc5173867a3c3c730924388daedbc38   path2/file2sym\r
329 -040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3   path3\r
330 -100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376   path3/file3\r
331 -120000 blob 8599103969b43aff7e430efea79ca4636466794f   path3/file3sym\r
332 -040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2   path3/subp3\r
333 -100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f   path3/subp3/file3\r
334 -120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c   path3/subp3/file3sym\r
335 -EOF\r
336 -test_expect_success SYMLINKS \\r
337 -    'git ls-tree -r output for a known tree.' \\r
338 -    'test_cmp expected current'\r
339 -\r
340 -test_expect_success \\r
341 -    'writing partial tree out with git write-tree --prefix.' \\r
342 -    'ptree=$(git write-tree --prefix=path3)'\r
343 -test_expect_success \\r
344 -    'validate object ID for a known tree.' \\r
345 -    'test "$ptree" = "$expectedptree1"'\r
346 -\r
347 -test_expect_success \\r
348 -    'writing partial tree out with git write-tree --prefix.' \\r
349 -    'ptree=$(git write-tree --prefix=path3/subp3)'\r
350 -test_expect_success \\r
351 -    'validate object ID for a known tree.' \\r
352 -    'test "$ptree" = "$expectedptree2"'\r
353 -\r
354 -cat >badobjects <<EOF\r
355 -100644 blob 1000000000000000000000000000000000000000   dir/file1\r
356 -100644 blob 2000000000000000000000000000000000000000   dir/file2\r
357 -100644 blob 3000000000000000000000000000000000000000   dir/file3\r
358 -100644 blob 4000000000000000000000000000000000000000   dir/file4\r
359 -100644 blob 5000000000000000000000000000000000000000   dir/file5\r
360 -EOF\r
361 -\r
362 -rm .git/index\r
363 -test_expect_success \\r
364 -    'put invalid objects into the index.' \\r
365 -    'git update-index --index-info < badobjects'\r
366 -\r
367 -test_expect_success 'writing this tree without --missing-ok.' '\r
368 -    test_must_fail git write-tree\r
369 -'\r
370 -\r
371 -test_expect_success \\r
372 -    'writing this tree with --missing-ok.' \\r
373 -    'git write-tree --missing-ok'\r
374 -\r
375 -\r
376 -################################################################\r
377 -rm .git/index\r
378 -test_expect_success \\r
379 -    'git read-tree followed by write-tree should be idempotent.' \\r
380 -    'git read-tree $tree &&\r
381 -     test -f .git/index &&\r
382 -     newtree=$(git write-tree) &&\r
383 -     test "$newtree" = "$tree"'\r
384 -\r
385 -$expectfilter >expected <<\EOF\r
386 -:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M     path0\r
387 -:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M     path0sym\r
388 -:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M     path2/file2\r
389 -:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M     path2/file2sym\r
390 -:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M     path3/file3\r
391 -:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M     path3/file3sym\r
392 -:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M     path3/subp3/file3\r
393 -:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M     path3/subp3/file3sym\r
394 -EOF\r
395 -test_expect_success \\r
396 -    'validate git diff-files output for a know cache/work tree state.' \\r
397 -    'git diff-files >current && diff >/dev/null -b current expected'\r
398 -\r
399 -test_expect_success \\r
400 -    'git update-index --refresh should succeed.' \\r
401 -    'git update-index --refresh'\r
402 -\r
403 -test_expect_success \\r
404 -    'no diff after checkout and git update-index --refresh.' \\r
405 -    'git diff-files >current && cmp -s current /dev/null'\r
406 -\r
407 -################################################################\r
408 -P=$expectedtree\r
409 -test_expect_success \\r
410 -    'git commit-tree records the correct tree in a commit.' \\r
411 -    'commit0=$(echo NO | git commit-tree $P) &&\r
412 -     tree=$(git show --pretty=raw $commit0 |\r
413 -        sed -n -e "s/^tree //p" -e "/^author /q") &&\r
414 -     test "z$tree" = "z$P"'\r
415 -\r
416 -test_expect_success \\r
417 -    'git commit-tree records the correct parent in a commit.' \\r
418 -    'commit1=$(echo NO | git commit-tree $P -p $commit0) &&\r
419 -     parent=$(git show --pretty=raw $commit1 |\r
420 -        sed -n -e "s/^parent //p" -e "/^author /q") &&\r
421 -     test "z$commit0" = "z$parent"'\r
422 -\r
423 -test_expect_success \\r
424 -    'git commit-tree omits duplicated parent in a commit.' \\r
425 -    'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&\r
426 -     parent=$(git show --pretty=raw $commit2 |\r
427 -        sed -n -e "s/^parent //p" -e "/^author /q" |\r
428 -        sort -u) &&\r
429 -     test "z$commit0" = "z$parent" &&\r
430 -     numparent=$(git show --pretty=raw $commit2 |\r
431 -        sed -n -e "s/^parent //p" -e "/^author /q" |\r
432 -        wc -l) &&\r
433 -     test $numparent = 1'\r
434 -\r
435 -test_expect_success 'update-index D/F conflict' '\r
436 -       mv path0 tmp &&\r
437 -       mv path2 path0 &&\r
438 -       mv tmp path2 &&\r
439 -       git update-index --add --replace path2 path0/file2 &&\r
440 -       numpath0=$(git ls-files path0 | wc -l) &&\r
441 -       test $numpath0 = 1\r
442 -'\r
443 -\r
444 -test_expect_success SYMLINKS 'absolute path works as expected' '\r
445 -       mkdir first &&\r
446 -       ln -s ../.git first/.git &&\r
447 -       mkdir second &&\r
448 -       ln -s ../first second/other &&\r
449 -       mkdir third &&\r
450 -       dir="$(cd .git; pwd -P)" &&\r
451 -       dir2=third/../second/other/.git &&\r
452 -       test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&\r
453 -       file="$dir"/index &&\r
454 -       test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&\r
455 -       basename=blub &&\r
456 -       test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&\r
457 -       ln -s ../first/file .git/syml &&\r
458 -       sym="$(cd first; pwd -P)"/file &&\r
459 -       test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"\r
460 -'\r
461 -\r
462 -test_expect_success 'very long name in the index handled sanely' '\r
463 -\r
464 -       a=a && # 1\r
465 -       a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16\r
466 -       a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256\r
467 -       a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096\r
468 -       a=${a}q &&\r
469 -\r
470 -       >path4 &&\r
471 -       git update-index --add path4 &&\r
472 -       (\r
473 -               git ls-files -s path4 |\r
474 -               sed -e "s/      .*/     /" |\r
475 -               tr -d "\012"\r
476 -               echo "$a"\r
477 -       ) | git update-index --index-info &&\r
478 -       len=$(git ls-files "a*" | wc -c) &&\r
479 -       test $len = 4098\r
480 -'\r
481 -\r
482  test_done\r
483 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
484 index 7422bba..7684c2e 100644\r
485 --- a/test/test-lib.sh\r
486 +++ b/test/test-lib.sh\r
487 @@ -1,4 +1,4 @@\r
488 -#!/bin/sh\r
489 +#!/bin/bash\r
490  #\r
491  # Copyright (c) 2005 Junio C Hamano\r
492  #\r
493 @@ -41,40 +41,6 @@ PAGER=cat\r
494  TZ=UTC\r
495  TERM=dumb\r
496  export LANG LC_ALL PAGER TERM TZ\r
497 -EDITOR=:\r
498 -unset VISUAL\r
499 -unset GIT_EDITOR\r
500 -unset AUTHOR_DATE\r
501 -unset AUTHOR_EMAIL\r
502 -unset AUTHOR_NAME\r
503 -unset COMMIT_AUTHOR_EMAIL\r
504 -unset COMMIT_AUTHOR_NAME\r
505 -unset EMAIL\r
506 -unset GIT_ALTERNATE_OBJECT_DIRECTORIES\r
507 -unset GIT_AUTHOR_DATE\r
508 -GIT_AUTHOR_EMAIL=author@example.com\r
509 -GIT_AUTHOR_NAME='A U Thor'\r
510 -unset GIT_COMMITTER_DATE\r
511 -GIT_COMMITTER_EMAIL=committer@example.com\r
512 -GIT_COMMITTER_NAME='C O Mitter'\r
513 -unset GIT_DIFF_OPTS\r
514 -unset GIT_DIR\r
515 -unset GIT_WORK_TREE\r
516 -unset GIT_EXTERNAL_DIFF\r
517 -unset GIT_INDEX_FILE\r
518 -unset GIT_OBJECT_DIRECTORY\r
519 -unset GIT_CEILING_DIRECTORIES\r
520 -unset SHA1_FILE_DIRECTORIES\r
521 -unset SHA1_FILE_DIRECTORY\r
522 -unset GIT_NOTES_REF\r
523 -unset GIT_NOTES_DISPLAY_REF\r
524 -unset GIT_NOTES_REWRITE_REF\r
525 -unset GIT_NOTES_REWRITE_MODE\r
526 -GIT_MERGE_VERBOSITY=5\r
527 -export GIT_MERGE_VERBOSITY\r
528 -export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\r
529 -export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\r
530 -export EDITOR\r
531  GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\r
532  \r
533  # Protect ourselves from common misconfiguration to export\r
534 @@ -98,6 +64,9 @@ esac\r
535  _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\r
536  _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"\r
537  \r
538 +_x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\r
539 +_x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"\r
540 +\r
541  # Each test should start with something like this, after copyright notices:\r
542  #\r
543  # test_description='Description of this test...\r
544 @@ -221,22 +190,6 @@ die () {\r
545  GIT_EXIT_OK=\r
546  trap 'die' EXIT\r
547  \r
548 -# The semantics of the editor variables are that of invoking\r
549 -# sh -c "$EDITOR \"$@\"" files ...\r
550 -#\r
551 -# If our trash directory contains shell metacharacters, they will be\r
552 -# interpreted if we just set $EDITOR directly, so do a little dance with\r
553 -# environment variables to work around this.\r
554 -#\r
555 -# In particular, quoting isn't enough, as the path may contain the same quote\r
556 -# that we're using.\r
557 -test_set_editor () {\r
558 -       FAKE_EDITOR="$1"\r
559 -       export FAKE_EDITOR\r
560 -       EDITOR='"$FAKE_EDITOR"'\r
561 -       export EDITOR\r
562 -}\r
563 -\r
564  test_decode_color () {\r
565         sed     -e 's/.\[1m/<WHITE>/g' \\r
566                 -e 's/.\[31m/<RED>/g' \\r
567 @@ -264,52 +217,205 @@ remove_cr () {\r
568         tr '\015' Q | sed -e 's/Q$//'\r
569  }\r
570  \r
571 -test_tick () {\r
572 -       if test -z "${test_tick+set}"\r
573 -       then\r
574 -               test_tick=1112911993\r
575 -       else\r
576 -               test_tick=$(($test_tick + 60))\r
577 -       fi\r
578 -       GIT_COMMITTER_DATE="$test_tick -0700"\r
579 -       GIT_AUTHOR_DATE="$test_tick -0700"\r
580 -       export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\r
581 +# Notmuch helper functions\r
582 +increment_mtime_amount=0\r
583 +increment_mtime ()\r
584 +{\r
585 +    dir=$1\r
586 +\r
587 +    increment_mtime_amount=$((increment_mtime_amount + 1))\r
588 +    touch -d "+${increment_mtime_amount} seconds" $dir\r
589  }\r
590  \r
591 -# Call test_commit with the arguments "<message> [<file> [<contents>]]"\r
592 +# Generate a new message in the mail directory, with a unique message\r
593 +# ID and subject. The message is not added to the index.\r
594 +#\r
595 +# After this function returns, the filename of the generated message\r
596 +# is available as $gen_msg_filename and the message ID is available as\r
597 +# $gen_msg_id .\r
598 +#\r
599 +# This function supports named parameters with the bash syntax for\r
600 +# assigning a value to an associative array ([name]=value). The\r
601 +# supported parameters are:\r
602 +#\r
603 +#  [dir]=directory/of/choice\r
604 +#\r
605 +#      Generate the message in directory 'directory/of/choice' within\r
606 +#      the mail store. The directory will be created if necessary.\r
607  #\r
608 -# This will commit a file with the given contents and the given commit\r
609 -# message.  It will also add a tag with <message> as name.\r
610 +#  [body]=text\r
611  #\r
612 -# Both <file> and <contents> default to <message>.\r
613 +#      Text to use as the body of the email message\r
614 +#\r
615 +#  '[from]="Some User <user@example.com>"'\r
616 +#  '[to]="Some User <user@example.com>"'\r
617 +#  '[subject]="Subject of email message"'\r
618 +#  '[date]="RFC 822 Date"'\r
619 +#\r
620 +#      Values for email headers. If not provided, default values will\r
621 +#      be generated instead.\r
622 +#\r
623 +#  '[cc]="Some User <user@example.com>"'\r
624 +#  [reply-to]=some-address\r
625 +#  [in-reply-to]=<message-id>\r
626 +#  [references]=<message-id>\r
627 +#  [content-type]=content-type-specification\r
628 +#  '[header]=full header line, including keyword'\r
629 +#\r
630 +#      Additional values for email headers. If these are not provided\r
631 +#      then the relevant headers will simply not appear in the\r
632 +#      message.\r
633 +#\r
634 +#  '[id]=message-id'\r
635 +#\r
636 +#      Controls the message-id of the created message.\r
637 +gen_msg_cnt=0\r
638 +gen_msg_filename=""\r
639 +gen_msg_id=""\r
640 +generate_message ()\r
641 +{\r
642 +    # This is our (bash-specific) magic for doing named parameters\r
643 +    local -A template="($@)"\r
644 +    local additional_headers\r
645 +\r
646 +    gen_msg_cnt=$((gen_msg_cnt + 1))\r
647 +    gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)\r
648 +\r
649 +    if [ -z "${template[id]}" ]; then\r
650 +       gen_msg_id="${gen_msg_name}@notmuch-test-suite"\r
651 +    else\r
652 +       gen_msg_id="${template[id]}"\r
653 +    fi\r
654 +\r
655 +    if [ -z "${template[dir]}" ]; then\r
656 +       gen_msg_filename="${MAIL_DIR}/$gen_msg_name"\r
657 +    else\r
658 +       gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"\r
659 +       mkdir -p $(dirname $gen_msg_filename)\r
660 +    fi\r
661 +\r
662 +    if [ -z "${template[body]}" ]; then\r
663 +       template[body]="This is just a test message (#${gen_msg_cnt})"\r
664 +    fi\r
665 +\r
666 +    if [ -z "${template[from]}" ]; then\r
667 +       template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"\r
668 +    fi\r
669 +\r
670 +    if [ -z "${template[to]}" ]; then\r
671 +       template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"\r
672 +    fi\r
673 +\r
674 +    if [ -z "${template[subject]}" ]; then\r
675 +       template[subject]="Test message #${gen_msg_cnt}"\r
676 +    fi\r
677 +\r
678 +    if [ -z "${template[date]}" ]; then\r
679 +       template[date]="Tue, 05 Jan 2001 15:43:57 -0800"\r
680 +    fi\r
681 +\r
682 +    additional_headers=""\r
683 +    if [ ! -z "${template[header]}" ]; then\r
684 +       additional_headers="${template[header]}\r
685 +${additional_headers}"\r
686 +    fi\r
687 +\r
688 +    if [ ! -z "${template[reply-to]}" ]; then\r
689 +       additional_headers="Reply-To: ${template[reply-to]}\r
690 +${additional_headers}"\r
691 +    fi\r
692 +\r
693 +    if [ ! -z "${template[in-reply-to]}" ]; then\r
694 +       additional_headers="In-Reply-To: ${template[in-reply-to]}\r
695 +${additional_headers}"\r
696 +    fi\r
697 +\r
698 +    if [ ! -z "${template[cc]}" ]; then\r
699 +       additional_headers="Cc: ${template[cc]}\r
700 +${additional_headers}"\r
701 +    fi\r
702 +\r
703 +    if [ ! -z "${template[references]}" ]; then\r
704 +       additional_headers="References: ${template[references]}\r
705 +${additional_headers}"\r
706 +    fi\r
707 +\r
708 +    if [ ! -z "${template[content-type]}" ]; then\r
709 +       additional_headers="Content-Type: ${template[content-type]}\r
710 +${additional_headers}"\r
711 +    fi\r
712 +\r
713 +\r
714 +cat <<EOF >$gen_msg_filename\r
715 +From: ${template[from]}\r
716 +To: ${template[to]}\r
717 +Message-Id: <${gen_msg_id}>\r
718 +Subject: ${template[subject]}\r
719 +Date: ${template[date]}\r
720 +${additional_headers}\r
721 +${template[body]}\r
722 +EOF\r
723 +\r
724 +    # Ensure that the mtime of the containing directory is updated\r
725 +    increment_mtime $(dirname ${gen_msg_filename})\r
726 +}\r
727 +\r
728 +# Generate a new message and add it to the index.\r
729 +#\r
730 +# All of the arguments and return values supported by generate_message\r
731 +# are also supported here, so see that function for details.\r
732 +add_message ()\r
733 +{\r
734 +    generate_message "$@"\r
735  \r
736 -test_commit () {\r
737 -       file=${2:-"$1.t"}\r
738 -       echo "${3-$1}" > "$file" &&\r
739 -       git add "$file" &&\r
740 -       test_tick &&\r
741 -       git commit -m "$1" &&\r
742 -       git tag "$1"\r
743 +    $NOTMUCH new > /dev/null\r
744  }\r
745  \r
746 -# Call test_merge with the arguments "<message> <commit>", where <commit>\r
747 -# can be a tag pointing to the commit-to-merge.\r
748 +tests=0\r
749 +test_failures=0\r
750  \r
751 -test_merge () {\r
752 -       test_tick &&\r
753 -       git merge -m "$1" "$2" &&\r
754 -       git tag "$1"\r
755 +pass_if_equal ()\r
756 +{\r
757 +    output=$1\r
758 +    expected=$2\r
759 +\r
760 +    tests=$((tests + 1))\r
761 +\r
762 +    if [ "$output" = "$expected" ]; then\r
763 +       echo "  PASS"\r
764 +    else\r
765 +       echo "  FAIL"\r
766 +       testname=test-$(printf "%03d" $tests)\r
767 +       echo "$expected" > $testname.expected\r
768 +       echo "$output" > $testname.output\r
769 +       diff -u $testname.expected $testname.output || true\r
770 +       test_failures=$((test_failures + 1))\r
771 +    fi\r
772 +}\r
773 +\r
774 +TEST_DIR=$(pwd)/test.$$\r
775 +MAIL_DIR=${TEST_DIR}/mail\r
776 +export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config\r
777 +NOTMUCH=$(find_notmuch_binary $(pwd))\r
778 +\r
779 +NOTMUCH_NEW ()\r
780 +{\r
781 +    $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'\r
782  }\r
783  \r
784 -# This function helps systems where core.filemode=false is set.\r
785 -# Use it instead of plain 'chmod +x' to set or unset the executable bit\r
786 -# of a file in the working directory and add it to the index.\r
787 +notmuch_search_sanitize ()\r
788 +{\r
789 +    sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'\r
790 +}\r
791  \r
792 -test_chmod () {\r
793 -       chmod "$@" &&\r
794 -       git update-index --add "--chmod=$@"\r
795 +NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'\r
796 +notmuch_show_sanitize ()\r
797 +{\r
798 +    sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"\r
799  }\r
800  \r
801 +# End of notmuch helper functions\r
802 +\r
803  # Use test_set_prereq to tell that a particular prerequisite is available.\r
804  # The prerequisite can later be checked for in two ways:\r
805  #\r
806 @@ -572,21 +678,6 @@ test_when_finished () {\r
807                 } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"\r
808  }\r
809  \r
810 -# Most tests can use the created repository, but some may need to create more.\r
811 -# Usage: test_create_repo <directory>\r
812 -test_create_repo () {\r
813 -       test "$#" = 1 ||\r
814 -       error "bug in the test script: not 1 parameter to test-create-repo"\r
815 -       owd=`pwd`\r
816 -       repo="$1"\r
817 -       mkdir -p "$repo"\r
818 -       cd "$repo" || error "Cannot setup test environment"\r
819 -       "$GIT_EXEC_PATH/git-init" "--template=$TEST_DIRECTORY/../templates/blt/" >&3 2>&4 ||\r
820 -       error "cannot run git init -- have you built things yet?"\r
821 -       mv .git/hooks .git/hooks-disabled\r
822 -       cd "$owd"\r
823 -}\r
824 -\r
825  test_done () {\r
826         GIT_EXIT_OK=t\r
827         test_results_dir="$TEST_DIRECTORY/test-results"\r
828 @@ -628,9 +719,27 @@ test_done () {\r
829         esac\r
830  }\r
831  \r
832 +find_notmuch_path ()\r
833 +{\r
834 +    dir="$1"\r
835 +\r
836 +    while [ -n "$dir" ]; do\r
837 +       bin="$dir/notmuch"\r
838 +       if [ -x "$bin" ]; then\r
839 +           echo "$dir"\r
840 +           return\r
841 +       fi\r
842 +       dir="$(dirname "$dir")"\r
843 +       if [ "$dir" = "/" ]; then\r
844 +           break\r
845 +       fi\r
846 +    done\r
847 +}\r
848 +\r
849  # Test the binaries we have just built.  The tests are kept in\r
850 -# t/ subdirectory and are run in 'trash directory' subdirectory.\r
851 +# test/ subdirectory and are run in 'trash directory' subdirectory.\r
852  TEST_DIRECTORY=$(pwd)\r
853 +# FIXME: Only the normal case bellow is updated to notmuch\r
854  if test -n "$valgrind"\r
855  then\r
856         make_symlink () {\r
857 @@ -699,48 +808,11 @@ elif test -n "$GIT_TEST_INSTALLED" ; then\r
858         error "Cannot run git from $GIT_TEST_INSTALLED."\r
859         PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH\r
860         GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}\r
861 -else # normal case, use ../bin-wrappers only unless $with_dashes:\r
862 -       git_bin_dir="$TEST_DIRECTORY/../bin-wrappers"\r
863 -       if ! test -x "$git_bin_dir/git" ; then\r
864 -               if test -z "$with_dashes" ; then\r
865 -                       say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"\r
866 -               fi\r
867 -               with_dashes=t\r
868 -       fi\r
869 -       PATH="$git_bin_dir:$PATH"\r
870 -       GIT_EXEC_PATH=$TEST_DIRECTORY/..\r
871 -       if test -n "$with_dashes" ; then\r
872 -               PATH="$TEST_DIRECTORY/..:$PATH"\r
873 -       fi\r
874 -fi\r
875 -GIT_TEMPLATE_DIR=$(pwd)/../templates/blt\r
876 -unset GIT_CONFIG\r
877 -GIT_CONFIG_NOSYSTEM=1\r
878 -GIT_CONFIG_NOGLOBAL=1\r
879 -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL\r
880 -\r
881 -. ../GIT-BUILD-OPTIONS\r
882 -\r
883 -GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git\r
884 -export GITPERLLIB\r
885 -test -d ../templates/blt || {\r
886 -       error "You haven't built things yet, have you?"\r
887 -}\r
888 -\r
889 -if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"\r
890 -then\r
891 -       GITPYTHONLIB="$(pwd)/../git_remote_helpers/build/lib"\r
892 -       export GITPYTHONLIB\r
893 -       test -d ../git_remote_helpers/build || {\r
894 -               error "You haven't built git_remote_helpers yet, have you?"\r
895 -       }\r
896 -fi\r
897 -\r
898 -if ! test -x ../test-chmtime; then\r
899 -       echo >&2 'You need to build test-chmtime:'\r
900 -       echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'\r
901 -       exit 1\r
902 +else # normal case\r
903 +       notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"`\r
904 +       test -n "$notmuch_path" && PATH="$notmuch_path:$PATH"\r
905  fi\r
906 +export PATH\r
907  \r
908  # Test repository\r
909  test="trash directory.$(basename "$0" .sh)"\r
910 @@ -756,10 +828,26 @@ rm -fr "$test" || {\r
911         exit 1\r
912  }\r
913  \r
914 -test_create_repo "$test"\r
915 +MAIL_DIR="${TRASH_DIRECTORY}/mail"\r
916 +export NOTMUCH_CONFIG="${TRASH_DIRECTORY}/notmuch-config"\r
917 +\r
918 +mkdir -p "${test}"\r
919 +mkdir "$MAIL_DIR"\r
920 +\r
921 +cat <<EOF >"${NOTMUCH_CONFIG}"\r
922 +[database]\r
923 +path=${MAIL_DIR}\r
924 +\r
925 +[user]\r
926 +name=Notmuch Test Suite\r
927 +primary_email=test_suite@notmuchmail.org\r
928 +other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org\r
929 +EOF\r
930 +\r
931 +\r
932  # Use -P to resolve symlinks in our working directory so that the cwd\r
933  # in subprocesses like git equals our $PWD (for pathname comparisons).\r
934 -cd -P "$test" || exit 1\r
935 +cd -P "$test" || error "Cannot setup test environment"\r
936  \r
937  this_test=${0##*/}\r
938  this_test=${this_test%%-*}\r
939 -- \r
940 1.7.1.3.g75e44\r
941 \r