[PATCH v3 2/5] Update test framework for use with notmuch
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 10 Jun 2010 06:48:01 +0000 (08:48 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:08 +0000 (09:37 -0800)
fb/2c16aa0e218483d66cf965a0e9b045631da2fc [new file with mode: 0644]

diff --git a/fb/2c16aa0e218483d66cf965a0e9b045631da2fc b/fb/2c16aa0e218483d66cf965a0e9b045631da2fc
new file mode 100644 (file)
index 0000000..ced4e59
--- /dev/null
@@ -0,0 +1,941 @@
+Return-Path: <sojkam1@fel.cvut.cz>\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 8261D431FC1\r
+       for <notmuch@notmuchmail.org>; Wed,  9 Jun 2010 23:49:12 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9] autolearn=ham\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 1ijT7qQYv8vC for <notmuch@notmuchmail.org>;\r
+       Wed,  9 Jun 2010 23:48:55 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 382BC4196F3\r
+       for <notmuch@notmuchmail.org>; Wed,  9 Jun 2010 23:48:36 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.4])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id 892B219F33ED;\r
+       Thu, 10 Jun 2010 08:48:35 +0200 (CEST)\r
+X-Virus-Scanned: IMAP AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+       by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
+       port 10044)\r
+       with ESMTP id FTA238JKBtlT; Thu, 10 Jun 2010 08:48:33 +0200 (CEST)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id 33AC419F35DE;\r
+       Thu, 10 Jun 2010 08:48:32 +0200 (CEST)\r
+Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])\r
+       (Authenticated sender: sojkam1)\r
+       by imap.feld.cvut.cz (Postfix) with ESMTPSA id 2B3FE15C062;\r
+       Thu, 10 Jun 2010 08:48:32 +0200 (CEST)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.72)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1OMbZ1-0000JX-Py; Thu, 10 Jun 2010 08:48:31 +0200\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/5] Update test framework for use with notmuch\r
+Date: Thu, 10 Jun 2010 08:48:01 +0200\r
+Message-Id: <1276152484-1164-3-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.1.3.g75e44\r
+In-Reply-To: <1276152484-1164-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1276152484-1164-1-git-send-email-sojkam1@fel.cvut.cz>\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: Thu, 10 Jun 2010 06:49:12 -0000\r
+\r
+This removes Git specific things from the test-lib.sh and adds helper\r
+functions for notmuch taken from Carl's notmuch-test script. README is\r
+also slightly modified to reflect the current state.\r
+\r
+Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
+---\r
+ test/Makefile       |    1 +\r
+ test/README         |   12 +-\r
+ test/t0000-basic.sh |  335 +++-------------------------------------------\r
+ test/test-lib.sh    |  374 +++++++++++++++++++++++++++++++--------------------\r
+ 4 files changed, 256 insertions(+), 466 deletions(-)\r
+\r
+diff --git a/test/Makefile b/test/Makefile\r
+index 25c559b..7a29eaa 100644\r
+--- a/test/Makefile\r
++++ b/test/Makefile\r
+@@ -6,6 +6,7 @@\r
+ -include ../config.mak\r
\r
+ #GIT_TEST_OPTS=--verbose --debug\r
++SHELL=/bin/bash\r
+ SHELL_PATH ?= $(SHELL)\r
+ TAR ?= $(TAR)\r
+ RM ?= rm -f\r
+diff --git a/test/README b/test/README\r
+index dcd3ebb..af27d60 100644\r
+--- a/test/README\r
++++ b/test/README\r
+@@ -165,10 +165,10 @@ Writing Tests\r
+ -------------\r
\r
+ The test script is written as a shell script.  It should start\r
+-with the standard "#!/bin/sh" with copyright notices, and an\r
++with the standard "#!/bin/bash" with copyright notices, and an\r
+ assignment to variable 'test_description', like this:\r
\r
+-      #!/bin/sh\r
++      #!/bin/bash\r
+       #\r
+       # Copyright (c) 2005 Junio C Hamano\r
+       #\r
+@@ -192,9 +192,11 @@ This test harness library does the following things:\r
+  - If the script is invoked with command line argument --help\r
+    (or -h), it shows the test_description and exits.\r
\r
+- - Creates an empty test directory with an empty .git/objects\r
+-   database and chdir(2) into it.  This directory is 't/trash directory'\r
+-   if you must know, but I do not think you care.\r
++ - Creates a test directory with default notmuch-config and empty mail\r
++   store. This directory is 't/trash directory.<test-basename>' (note\r
++   the space) if you must know, but I do not think you care. The path\r
++   to notmuch-config is exported in NOTMUCH_CONFIG environment\r
++   variable and mail store path is stored in MAIL_DIR variable.\r
\r
+  - Defines standard test helper functions for your scripts to\r
+    use.  These functions are designed to make all scripts behave\r
+diff --git a/test/t0000-basic.sh b/test/t0000-basic.sh\r
+index 3ec9cbe..caade68 100755\r
+--- a/test/t0000-basic.sh\r
++++ b/test/t0000-basic.sh\r
+@@ -3,48 +3,39 @@\r
+ # Copyright (c) 2005 Junio C Hamano\r
+ #\r
\r
+-test_description='Test the very basics part #1.\r
+-\r
+-The rest of the test suite does not check the basic operation of git\r
+-plumbing commands to work very carefully.  Their job is to concentrate\r
+-on tricky features that caused bugs in the past to detect regression.\r
+-\r
+-This test runs very basic features, like registering things in cache,\r
+-writing tree, etc.\r
+-\r
+-Note that this test *deliberately* hard-codes many expected object\r
+-IDs.  When object ID computation changes, like in the previous case of\r
+-swapping compression and hashing order, the person who is making the\r
+-modification *should* take notice and update the test vectors here.\r
+-'\r
++test_description='Tests the test framework itself.'\r
\r
+ ################################################################\r
+ # It appears that people try to run tests without building...\r
\r
+-../git >/dev/null\r
+-if test $? != 1\r
++if ! test -x ../notmuch\r
+ then\r
+-      echo >&2 'You do not seem to have built git yet.'\r
++      echo >&2 'You do not seem to have built notmuch yet.'\r
+       exit 1\r
+ fi\r
\r
+ . ./test-lib.sh\r
\r
+ ################################################################\r
+-# git init has been done in an empty repository.\r
+-# make sure it is empty.\r
++# Test mail store prepared in test-lib.sh\r
\r
+-find .git/objects -type f -print >should-be-empty\r
+ test_expect_success \\r
+-    '.git/objects should be empty after git init in an empty repo.' \\r
++    'test that mail store was created' \\r
++    'test -d "${MAIL_DIR}"'\r
++\r
++\r
++find "${MAIL_DIR}" -type f -print >should-be-empty\r
++test_expect_success \\r
++    'mail store should be empty' \\r
+     'cmp -s /dev/null should-be-empty'\r
\r
+-# also it should have 2 subdirectories; no fan-out anymore, pack, and info.\r
+-# 3 is counting "objects" itself\r
+-find .git/objects -type d -print >full-of-directories\r
+ test_expect_success \\r
+-    '.git/objects should have 3 subdirectories.' \\r
+-    'test $(wc -l < full-of-directories) = 3'\r
++    'NOTMUCH_CONFIG is set and points to an existing file' \\r
++    'test -f "${NOTMUCH_CONFIG}"'\r
++\r
++test_expect_success \\r
++    'PATH is set to this repository' \\r
++    'test "`echo $PATH|cut -f1 -d:`" = "`dirname ${TEST_DIRECTORY}`"'\r
\r
+ ################################################################\r
+ # Test harness\r
+@@ -94,296 +85,4 @@ test_expect_code 2 'failure to clean up causes the test to fail' '\r
+     test_when_finished "(exit 2)"\r
+ '\r
\r
+-################################################################\r
+-# Basics of the basics\r
+-\r
+-# updating a new file without --add should fail.\r
+-test_expect_success 'git update-index without --add should fail adding.' '\r
+-    test_must_fail git update-index should-be-empty\r
+-'\r
+-\r
+-# and with --add it should succeed, even if it is empty (it used to fail).\r
+-test_expect_success \\r
+-    'git update-index with --add should succeed.' \\r
+-    'git update-index --add should-be-empty'\r
+-\r
+-test_expect_success \\r
+-    'writing tree out with git write-tree' \\r
+-    'tree=$(git write-tree)'\r
+-\r
+-# we know the shape and contents of the tree and know the object ID for it.\r
+-test_expect_success \\r
+-    'validate object ID of a known tree.' \\r
+-    'test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a'\r
+-\r
+-# Removing paths.\r
+-rm -f should-be-empty full-of-directories\r
+-test_expect_success 'git update-index without --remove should fail removing.' '\r
+-    test_must_fail git update-index should-be-empty\r
+-'\r
+-\r
+-test_expect_success \\r
+-    'git update-index with --remove should be able to remove.' \\r
+-    'git update-index --remove should-be-empty'\r
+-\r
+-# Empty tree can be written with recent write-tree.\r
+-test_expect_success \\r
+-    'git write-tree should be able to write an empty tree.' \\r
+-    'tree=$(git write-tree)'\r
+-\r
+-test_expect_success \\r
+-    'validate object ID of a known tree.' \\r
+-    'test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904'\r
+-\r
+-# Various types of objects\r
+-# Some filesystems do not support symblic links; on such systems\r
+-# some expected values are different\r
+-mkdir path2 path3 path3/subp3\r
+-paths='path0 path2/file2 path3/file3 path3/subp3/file3'\r
+-for p in $paths\r
+-do\r
+-    echo "hello $p" >$p\r
+-done\r
+-if test_have_prereq SYMLINKS\r
+-then\r
+-      for p in $paths\r
+-      do\r
+-              ln -s "hello $p" ${p}sym\r
+-      done\r
+-      expectfilter=cat\r
+-      expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b\r
+-      expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3\r
+-      expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2\r
+-else\r
+-      expectfilter='grep -v sym'\r
+-      expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46\r
+-      expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325\r
+-      expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f\r
+-fi\r
+-\r
+-test_expect_success \\r
+-    'adding various types of objects with git update-index --add.' \\r
+-    'find path* ! -type d -print | xargs git update-index --add'\r
+-\r
+-# Show them and see that matches what we expect.\r
+-test_expect_success \\r
+-    'showing stage with git ls-files --stage' \\r
+-    'git ls-files --stage >current'\r
+-\r
+-$expectfilter >expected <<\EOF\r
+-100644 f87290f8eb2cbbea7857214459a0739927eab154 0     path0\r
+-120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0     path0sym\r
+-100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0     path2/file2\r
+-120000 d8ce161addc5173867a3c3c730924388daedbc38 0     path2/file2sym\r
+-100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0     path3/file3\r
+-120000 8599103969b43aff7e430efea79ca4636466794f 0     path3/file3sym\r
+-100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0     path3/subp3/file3\r
+-120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0     path3/subp3/file3sym\r
+-EOF\r
+-test_expect_success \\r
+-    'validate git ls-files output for a known tree.' \\r
+-    'test_cmp expected current'\r
+-\r
+-test_expect_success \\r
+-    'writing tree out with git write-tree.' \\r
+-    'tree=$(git write-tree)'\r
+-test_expect_success \\r
+-    'validate object ID for a known tree.' \\r
+-    'test "$tree" = "$expectedtree"'\r
+-\r
+-test_expect_success \\r
+-    'showing tree with git ls-tree' \\r
+-    'git ls-tree $tree >current'\r
+-cat >expected <<\EOF\r
+-100644 blob f87290f8eb2cbbea7857214459a0739927eab154  path0\r
+-120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01  path0sym\r
+-040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe  path2\r
+-040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3  path3\r
+-EOF\r
+-test_expect_success SYMLINKS \\r
+-    'git ls-tree output for a known tree.' \\r
+-    'test_cmp expected current'\r
+-\r
+-# This changed in ls-tree pathspec change -- recursive does\r
+-# not show tree nodes anymore.\r
+-test_expect_success \\r
+-    'showing tree with git ls-tree -r' \\r
+-    'git ls-tree -r $tree >current'\r
+-$expectfilter >expected <<\EOF\r
+-100644 blob f87290f8eb2cbbea7857214459a0739927eab154  path0\r
+-120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01  path0sym\r
+-100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7  path2/file2\r
+-120000 blob d8ce161addc5173867a3c3c730924388daedbc38  path2/file2sym\r
+-100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376  path3/file3\r
+-120000 blob 8599103969b43aff7e430efea79ca4636466794f  path3/file3sym\r
+-100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f  path3/subp3/file3\r
+-120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c  path3/subp3/file3sym\r
+-EOF\r
+-test_expect_success \\r
+-    'git ls-tree -r output for a known tree.' \\r
+-    'test_cmp expected current'\r
+-\r
+-# But with -r -t we can have both.\r
+-test_expect_success \\r
+-    'showing tree with git ls-tree -r -t' \\r
+-    'git ls-tree -r -t $tree >current'\r
+-cat >expected <<\EOF\r
+-100644 blob f87290f8eb2cbbea7857214459a0739927eab154  path0\r
+-120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01  path0sym\r
+-040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe  path2\r
+-100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7  path2/file2\r
+-120000 blob d8ce161addc5173867a3c3c730924388daedbc38  path2/file2sym\r
+-040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3  path3\r
+-100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376  path3/file3\r
+-120000 blob 8599103969b43aff7e430efea79ca4636466794f  path3/file3sym\r
+-040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2  path3/subp3\r
+-100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f  path3/subp3/file3\r
+-120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c  path3/subp3/file3sym\r
+-EOF\r
+-test_expect_success SYMLINKS \\r
+-    'git ls-tree -r output for a known tree.' \\r
+-    'test_cmp expected current'\r
+-\r
+-test_expect_success \\r
+-    'writing partial tree out with git write-tree --prefix.' \\r
+-    'ptree=$(git write-tree --prefix=path3)'\r
+-test_expect_success \\r
+-    'validate object ID for a known tree.' \\r
+-    'test "$ptree" = "$expectedptree1"'\r
+-\r
+-test_expect_success \\r
+-    'writing partial tree out with git write-tree --prefix.' \\r
+-    'ptree=$(git write-tree --prefix=path3/subp3)'\r
+-test_expect_success \\r
+-    'validate object ID for a known tree.' \\r
+-    'test "$ptree" = "$expectedptree2"'\r
+-\r
+-cat >badobjects <<EOF\r
+-100644 blob 1000000000000000000000000000000000000000  dir/file1\r
+-100644 blob 2000000000000000000000000000000000000000  dir/file2\r
+-100644 blob 3000000000000000000000000000000000000000  dir/file3\r
+-100644 blob 4000000000000000000000000000000000000000  dir/file4\r
+-100644 blob 5000000000000000000000000000000000000000  dir/file5\r
+-EOF\r
+-\r
+-rm .git/index\r
+-test_expect_success \\r
+-    'put invalid objects into the index.' \\r
+-    'git update-index --index-info < badobjects'\r
+-\r
+-test_expect_success 'writing this tree without --missing-ok.' '\r
+-    test_must_fail git write-tree\r
+-'\r
+-\r
+-test_expect_success \\r
+-    'writing this tree with --missing-ok.' \\r
+-    'git write-tree --missing-ok'\r
+-\r
+-\r
+-################################################################\r
+-rm .git/index\r
+-test_expect_success \\r
+-    'git read-tree followed by write-tree should be idempotent.' \\r
+-    'git read-tree $tree &&\r
+-     test -f .git/index &&\r
+-     newtree=$(git write-tree) &&\r
+-     test "$newtree" = "$tree"'\r
+-\r
+-$expectfilter >expected <<\EOF\r
+-:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M    path0\r
+-:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M    path0sym\r
+-:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M    path2/file2\r
+-:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M    path2/file2sym\r
+-:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M    path3/file3\r
+-:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M    path3/file3sym\r
+-:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M    path3/subp3/file3\r
+-:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M    path3/subp3/file3sym\r
+-EOF\r
+-test_expect_success \\r
+-    'validate git diff-files output for a know cache/work tree state.' \\r
+-    'git diff-files >current && diff >/dev/null -b current expected'\r
+-\r
+-test_expect_success \\r
+-    'git update-index --refresh should succeed.' \\r
+-    'git update-index --refresh'\r
+-\r
+-test_expect_success \\r
+-    'no diff after checkout and git update-index --refresh.' \\r
+-    'git diff-files >current && cmp -s current /dev/null'\r
+-\r
+-################################################################\r
+-P=$expectedtree\r
+-test_expect_success \\r
+-    'git commit-tree records the correct tree in a commit.' \\r
+-    'commit0=$(echo NO | git commit-tree $P) &&\r
+-     tree=$(git show --pretty=raw $commit0 |\r
+-       sed -n -e "s/^tree //p" -e "/^author /q") &&\r
+-     test "z$tree" = "z$P"'\r
+-\r
+-test_expect_success \\r
+-    'git commit-tree records the correct parent in a commit.' \\r
+-    'commit1=$(echo NO | git commit-tree $P -p $commit0) &&\r
+-     parent=$(git show --pretty=raw $commit1 |\r
+-       sed -n -e "s/^parent //p" -e "/^author /q") &&\r
+-     test "z$commit0" = "z$parent"'\r
+-\r
+-test_expect_success \\r
+-    'git commit-tree omits duplicated parent in a commit.' \\r
+-    'commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&\r
+-     parent=$(git show --pretty=raw $commit2 |\r
+-       sed -n -e "s/^parent //p" -e "/^author /q" |\r
+-       sort -u) &&\r
+-     test "z$commit0" = "z$parent" &&\r
+-     numparent=$(git show --pretty=raw $commit2 |\r
+-       sed -n -e "s/^parent //p" -e "/^author /q" |\r
+-       wc -l) &&\r
+-     test $numparent = 1'\r
+-\r
+-test_expect_success 'update-index D/F conflict' '\r
+-      mv path0 tmp &&\r
+-      mv path2 path0 &&\r
+-      mv tmp path2 &&\r
+-      git update-index --add --replace path2 path0/file2 &&\r
+-      numpath0=$(git ls-files path0 | wc -l) &&\r
+-      test $numpath0 = 1\r
+-'\r
+-\r
+-test_expect_success SYMLINKS 'absolute path works as expected' '\r
+-      mkdir first &&\r
+-      ln -s ../.git first/.git &&\r
+-      mkdir second &&\r
+-      ln -s ../first second/other &&\r
+-      mkdir third &&\r
+-      dir="$(cd .git; pwd -P)" &&\r
+-      dir2=third/../second/other/.git &&\r
+-      test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&\r
+-      file="$dir"/index &&\r
+-      test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&\r
+-      basename=blub &&\r
+-      test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&\r
+-      ln -s ../first/file .git/syml &&\r
+-      sym="$(cd first; pwd -P)"/file &&\r
+-      test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"\r
+-'\r
+-\r
+-test_expect_success 'very long name in the index handled sanely' '\r
+-\r
+-      a=a && # 1\r
+-      a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16\r
+-      a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256\r
+-      a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096\r
+-      a=${a}q &&\r
+-\r
+-      >path4 &&\r
+-      git update-index --add path4 &&\r
+-      (\r
+-              git ls-files -s path4 |\r
+-              sed -e "s/      .*/     /" |\r
+-              tr -d "\012"\r
+-              echo "$a"\r
+-      ) | git update-index --index-info &&\r
+-      len=$(git ls-files "a*" | wc -c) &&\r
+-      test $len = 4098\r
+-'\r
+-\r
+ test_done\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 7422bba..7684c2e 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -1,4 +1,4 @@\r
+-#!/bin/sh\r
++#!/bin/bash\r
+ #\r
+ # Copyright (c) 2005 Junio C Hamano\r
+ #\r
+@@ -41,40 +41,6 @@ PAGER=cat\r
+ TZ=UTC\r
+ TERM=dumb\r
+ export LANG LC_ALL PAGER TERM TZ\r
+-EDITOR=:\r
+-unset VISUAL\r
+-unset GIT_EDITOR\r
+-unset AUTHOR_DATE\r
+-unset AUTHOR_EMAIL\r
+-unset AUTHOR_NAME\r
+-unset COMMIT_AUTHOR_EMAIL\r
+-unset COMMIT_AUTHOR_NAME\r
+-unset EMAIL\r
+-unset GIT_ALTERNATE_OBJECT_DIRECTORIES\r
+-unset GIT_AUTHOR_DATE\r
+-GIT_AUTHOR_EMAIL=author@example.com\r
+-GIT_AUTHOR_NAME='A U Thor'\r
+-unset GIT_COMMITTER_DATE\r
+-GIT_COMMITTER_EMAIL=committer@example.com\r
+-GIT_COMMITTER_NAME='C O Mitter'\r
+-unset GIT_DIFF_OPTS\r
+-unset GIT_DIR\r
+-unset GIT_WORK_TREE\r
+-unset GIT_EXTERNAL_DIFF\r
+-unset GIT_INDEX_FILE\r
+-unset GIT_OBJECT_DIRECTORY\r
+-unset GIT_CEILING_DIRECTORIES\r
+-unset SHA1_FILE_DIRECTORIES\r
+-unset SHA1_FILE_DIRECTORY\r
+-unset GIT_NOTES_REF\r
+-unset GIT_NOTES_DISPLAY_REF\r
+-unset GIT_NOTES_REWRITE_REF\r
+-unset GIT_NOTES_REWRITE_MODE\r
+-GIT_MERGE_VERBOSITY=5\r
+-export GIT_MERGE_VERBOSITY\r
+-export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\r
+-export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\r
+-export EDITOR\r
+ GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\r
\r
+ # Protect ourselves from common misconfiguration to export\r
+@@ -98,6 +64,9 @@ esac\r
+ _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\r
+ _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"\r
\r
++_x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\r
++_x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"\r
++\r
+ # Each test should start with something like this, after copyright notices:\r
+ #\r
+ # test_description='Description of this test...\r
+@@ -221,22 +190,6 @@ die () {\r
+ GIT_EXIT_OK=\r
+ trap 'die' EXIT\r
\r
+-# The semantics of the editor variables are that of invoking\r
+-# sh -c "$EDITOR \"$@\"" files ...\r
+-#\r
+-# If our trash directory contains shell metacharacters, they will be\r
+-# interpreted if we just set $EDITOR directly, so do a little dance with\r
+-# environment variables to work around this.\r
+-#\r
+-# In particular, quoting isn't enough, as the path may contain the same quote\r
+-# that we're using.\r
+-test_set_editor () {\r
+-      FAKE_EDITOR="$1"\r
+-      export FAKE_EDITOR\r
+-      EDITOR='"$FAKE_EDITOR"'\r
+-      export EDITOR\r
+-}\r
+-\r
+ test_decode_color () {\r
+       sed     -e 's/.\[1m/<WHITE>/g' \\r
+               -e 's/.\[31m/<RED>/g' \\r
+@@ -264,52 +217,205 @@ remove_cr () {\r
+       tr '\015' Q | sed -e 's/Q$//'\r
+ }\r
\r
+-test_tick () {\r
+-      if test -z "${test_tick+set}"\r
+-      then\r
+-              test_tick=1112911993\r
+-      else\r
+-              test_tick=$(($test_tick + 60))\r
+-      fi\r
+-      GIT_COMMITTER_DATE="$test_tick -0700"\r
+-      GIT_AUTHOR_DATE="$test_tick -0700"\r
+-      export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\r
++# Notmuch helper functions\r
++increment_mtime_amount=0\r
++increment_mtime ()\r
++{\r
++    dir=$1\r
++\r
++    increment_mtime_amount=$((increment_mtime_amount + 1))\r
++    touch -d "+${increment_mtime_amount} seconds" $dir\r
+ }\r
\r
+-# Call test_commit with the arguments "<message> [<file> [<contents>]]"\r
++# Generate a new message in the mail directory, with a unique message\r
++# ID and subject. The message is not added to the index.\r
++#\r
++# After this function returns, the filename of the generated message\r
++# is available as $gen_msg_filename and the message ID is available as\r
++# $gen_msg_id .\r
++#\r
++# This function supports named parameters with the bash syntax for\r
++# assigning a value to an associative array ([name]=value). The\r
++# supported parameters are:\r
++#\r
++#  [dir]=directory/of/choice\r
++#\r
++#     Generate the message in directory 'directory/of/choice' within\r
++#     the mail store. The directory will be created if necessary.\r
+ #\r
+-# This will commit a file with the given contents and the given commit\r
+-# message.  It will also add a tag with <message> as name.\r
++#  [body]=text\r
+ #\r
+-# Both <file> and <contents> default to <message>.\r
++#     Text to use as the body of the email message\r
++#\r
++#  '[from]="Some User <user@example.com>"'\r
++#  '[to]="Some User <user@example.com>"'\r
++#  '[subject]="Subject of email message"'\r
++#  '[date]="RFC 822 Date"'\r
++#\r
++#     Values for email headers. If not provided, default values will\r
++#     be generated instead.\r
++#\r
++#  '[cc]="Some User <user@example.com>"'\r
++#  [reply-to]=some-address\r
++#  [in-reply-to]=<message-id>\r
++#  [references]=<message-id>\r
++#  [content-type]=content-type-specification\r
++#  '[header]=full header line, including keyword'\r
++#\r
++#     Additional values for email headers. If these are not provided\r
++#     then the relevant headers will simply not appear in the\r
++#     message.\r
++#\r
++#  '[id]=message-id'\r
++#\r
++#     Controls the message-id of the created message.\r
++gen_msg_cnt=0\r
++gen_msg_filename=""\r
++gen_msg_id=""\r
++generate_message ()\r
++{\r
++    # This is our (bash-specific) magic for doing named parameters\r
++    local -A template="($@)"\r
++    local additional_headers\r
++\r
++    gen_msg_cnt=$((gen_msg_cnt + 1))\r
++    gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)\r
++\r
++    if [ -z "${template[id]}" ]; then\r
++      gen_msg_id="${gen_msg_name}@notmuch-test-suite"\r
++    else\r
++      gen_msg_id="${template[id]}"\r
++    fi\r
++\r
++    if [ -z "${template[dir]}" ]; then\r
++      gen_msg_filename="${MAIL_DIR}/$gen_msg_name"\r
++    else\r
++      gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"\r
++      mkdir -p $(dirname $gen_msg_filename)\r
++    fi\r
++\r
++    if [ -z "${template[body]}" ]; then\r
++      template[body]="This is just a test message (#${gen_msg_cnt})"\r
++    fi\r
++\r
++    if [ -z "${template[from]}" ]; then\r
++      template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"\r
++    fi\r
++\r
++    if [ -z "${template[to]}" ]; then\r
++      template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"\r
++    fi\r
++\r
++    if [ -z "${template[subject]}" ]; then\r
++      template[subject]="Test message #${gen_msg_cnt}"\r
++    fi\r
++\r
++    if [ -z "${template[date]}" ]; then\r
++      template[date]="Tue, 05 Jan 2001 15:43:57 -0800"\r
++    fi\r
++\r
++    additional_headers=""\r
++    if [ ! -z "${template[header]}" ]; then\r
++      additional_headers="${template[header]}\r
++${additional_headers}"\r
++    fi\r
++\r
++    if [ ! -z "${template[reply-to]}" ]; then\r
++      additional_headers="Reply-To: ${template[reply-to]}\r
++${additional_headers}"\r
++    fi\r
++\r
++    if [ ! -z "${template[in-reply-to]}" ]; then\r
++      additional_headers="In-Reply-To: ${template[in-reply-to]}\r
++${additional_headers}"\r
++    fi\r
++\r
++    if [ ! -z "${template[cc]}" ]; then\r
++      additional_headers="Cc: ${template[cc]}\r
++${additional_headers}"\r
++    fi\r
++\r
++    if [ ! -z "${template[references]}" ]; then\r
++      additional_headers="References: ${template[references]}\r
++${additional_headers}"\r
++    fi\r
++\r
++    if [ ! -z "${template[content-type]}" ]; then\r
++      additional_headers="Content-Type: ${template[content-type]}\r
++${additional_headers}"\r
++    fi\r
++\r
++\r
++cat <<EOF >$gen_msg_filename\r
++From: ${template[from]}\r
++To: ${template[to]}\r
++Message-Id: <${gen_msg_id}>\r
++Subject: ${template[subject]}\r
++Date: ${template[date]}\r
++${additional_headers}\r
++${template[body]}\r
++EOF\r
++\r
++    # Ensure that the mtime of the containing directory is updated\r
++    increment_mtime $(dirname ${gen_msg_filename})\r
++}\r
++\r
++# Generate a new message and add it to the index.\r
++#\r
++# All of the arguments and return values supported by generate_message\r
++# are also supported here, so see that function for details.\r
++add_message ()\r
++{\r
++    generate_message "$@"\r
\r
+-test_commit () {\r
+-      file=${2:-"$1.t"}\r
+-      echo "${3-$1}" > "$file" &&\r
+-      git add "$file" &&\r
+-      test_tick &&\r
+-      git commit -m "$1" &&\r
+-      git tag "$1"\r
++    $NOTMUCH new > /dev/null\r
+ }\r
\r
+-# Call test_merge with the arguments "<message> <commit>", where <commit>\r
+-# can be a tag pointing to the commit-to-merge.\r
++tests=0\r
++test_failures=0\r
\r
+-test_merge () {\r
+-      test_tick &&\r
+-      git merge -m "$1" "$2" &&\r
+-      git tag "$1"\r
++pass_if_equal ()\r
++{\r
++    output=$1\r
++    expected=$2\r
++\r
++    tests=$((tests + 1))\r
++\r
++    if [ "$output" = "$expected" ]; then\r
++      echo "  PASS"\r
++    else\r
++      echo "  FAIL"\r
++      testname=test-$(printf "%03d" $tests)\r
++      echo "$expected" > $testname.expected\r
++      echo "$output" > $testname.output\r
++      diff -u $testname.expected $testname.output || true\r
++      test_failures=$((test_failures + 1))\r
++    fi\r
++}\r
++\r
++TEST_DIR=$(pwd)/test.$$\r
++MAIL_DIR=${TEST_DIR}/mail\r
++export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config\r
++NOTMUCH=$(find_notmuch_binary $(pwd))\r
++\r
++NOTMUCH_NEW ()\r
++{\r
++    $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'\r
+ }\r
\r
+-# This function helps systems where core.filemode=false is set.\r
+-# Use it instead of plain 'chmod +x' to set or unset the executable bit\r
+-# of a file in the working directory and add it to the index.\r
++notmuch_search_sanitize ()\r
++{\r
++    sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'\r
++}\r
\r
+-test_chmod () {\r
+-      chmod "$@" &&\r
+-      git update-index --add "--chmod=$@"\r
++NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'\r
++notmuch_show_sanitize ()\r
++{\r
++    sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"\r
+ }\r
\r
++# End of notmuch helper functions\r
++\r
+ # Use test_set_prereq to tell that a particular prerequisite is available.\r
+ # The prerequisite can later be checked for in two ways:\r
+ #\r
+@@ -572,21 +678,6 @@ test_when_finished () {\r
+               } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"\r
+ }\r
\r
+-# Most tests can use the created repository, but some may need to create more.\r
+-# Usage: test_create_repo <directory>\r
+-test_create_repo () {\r
+-      test "$#" = 1 ||\r
+-      error "bug in the test script: not 1 parameter to test-create-repo"\r
+-      owd=`pwd`\r
+-      repo="$1"\r
+-      mkdir -p "$repo"\r
+-      cd "$repo" || error "Cannot setup test environment"\r
+-      "$GIT_EXEC_PATH/git-init" "--template=$TEST_DIRECTORY/../templates/blt/" >&3 2>&4 ||\r
+-      error "cannot run git init -- have you built things yet?"\r
+-      mv .git/hooks .git/hooks-disabled\r
+-      cd "$owd"\r
+-}\r
+-\r
+ test_done () {\r
+       GIT_EXIT_OK=t\r
+       test_results_dir="$TEST_DIRECTORY/test-results"\r
+@@ -628,9 +719,27 @@ test_done () {\r
+       esac\r
+ }\r
\r
++find_notmuch_path ()\r
++{\r
++    dir="$1"\r
++\r
++    while [ -n "$dir" ]; do\r
++      bin="$dir/notmuch"\r
++      if [ -x "$bin" ]; then\r
++          echo "$dir"\r
++          return\r
++      fi\r
++      dir="$(dirname "$dir")"\r
++      if [ "$dir" = "/" ]; then\r
++          break\r
++      fi\r
++    done\r
++}\r
++\r
+ # Test the binaries we have just built.  The tests are kept in\r
+-# t/ subdirectory and are run in 'trash directory' subdirectory.\r
++# test/ subdirectory and are run in 'trash directory' subdirectory.\r
+ TEST_DIRECTORY=$(pwd)\r
++# FIXME: Only the normal case bellow is updated to notmuch\r
+ if test -n "$valgrind"\r
+ then\r
+       make_symlink () {\r
+@@ -699,48 +808,11 @@ elif test -n "$GIT_TEST_INSTALLED" ; then\r
+       error "Cannot run git from $GIT_TEST_INSTALLED."\r
+       PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH\r
+       GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}\r
+-else # normal case, use ../bin-wrappers only unless $with_dashes:\r
+-      git_bin_dir="$TEST_DIRECTORY/../bin-wrappers"\r
+-      if ! test -x "$git_bin_dir/git" ; then\r
+-              if test -z "$with_dashes" ; then\r
+-                      say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"\r
+-              fi\r
+-              with_dashes=t\r
+-      fi\r
+-      PATH="$git_bin_dir:$PATH"\r
+-      GIT_EXEC_PATH=$TEST_DIRECTORY/..\r
+-      if test -n "$with_dashes" ; then\r
+-              PATH="$TEST_DIRECTORY/..:$PATH"\r
+-      fi\r
+-fi\r
+-GIT_TEMPLATE_DIR=$(pwd)/../templates/blt\r
+-unset GIT_CONFIG\r
+-GIT_CONFIG_NOSYSTEM=1\r
+-GIT_CONFIG_NOGLOBAL=1\r
+-export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL\r
+-\r
+-. ../GIT-BUILD-OPTIONS\r
+-\r
+-GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git\r
+-export GITPERLLIB\r
+-test -d ../templates/blt || {\r
+-      error "You haven't built things yet, have you?"\r
+-}\r
+-\r
+-if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"\r
+-then\r
+-      GITPYTHONLIB="$(pwd)/../git_remote_helpers/build/lib"\r
+-      export GITPYTHONLIB\r
+-      test -d ../git_remote_helpers/build || {\r
+-              error "You haven't built git_remote_helpers yet, have you?"\r
+-      }\r
+-fi\r
+-\r
+-if ! test -x ../test-chmtime; then\r
+-      echo >&2 'You need to build test-chmtime:'\r
+-      echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'\r
+-      exit 1\r
++else # normal case\r
++      notmuch_path=`find_notmuch_path "$TEST_DIRECTORY"`\r
++      test -n "$notmuch_path" && PATH="$notmuch_path:$PATH"\r
+ fi\r
++export PATH\r
\r
+ # Test repository\r
+ test="trash directory.$(basename "$0" .sh)"\r
+@@ -756,10 +828,26 @@ rm -fr "$test" || {\r
+       exit 1\r
+ }\r
\r
+-test_create_repo "$test"\r
++MAIL_DIR="${TRASH_DIRECTORY}/mail"\r
++export NOTMUCH_CONFIG="${TRASH_DIRECTORY}/notmuch-config"\r
++\r
++mkdir -p "${test}"\r
++mkdir "$MAIL_DIR"\r
++\r
++cat <<EOF >"${NOTMUCH_CONFIG}"\r
++[database]\r
++path=${MAIL_DIR}\r
++\r
++[user]\r
++name=Notmuch Test Suite\r
++primary_email=test_suite@notmuchmail.org\r
++other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org\r
++EOF\r
++\r
++\r
+ # Use -P to resolve symlinks in our working directory so that the cwd\r
+ # in subprocesses like git equals our $PWD (for pathname comparisons).\r
+-cd -P "$test" || exit 1\r
++cd -P "$test" || error "Cannot setup test environment"\r
\r
+ this_test=${0##*/}\r
+ this_test=${this_test%%-*}\r
+-- \r
+1.7.1.3.g75e44\r
+\r