[PATCH v2 5/5] test: Set all times to UTC

2010-05-10 Thread Michal Sojka
In order to have repeatable test suite, all times in messages are set
to UTC, which is the same time zone set in test-lib.sh.

Signed-off-by: Michal Sojka 
---
 test/t0004-thread-naming.sh|   32 ++--
 test/t0005-reply.sh|   24 ++--
 test/t0010-from-line-heuristics.sh |   40 ++--
 3 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/test/t0004-thread-naming.sh b/test/t0004-thread-naming.sh
index 88216f2..c77f726 100755
--- a/test/t0004-thread-naming.sh
+++ b/test/t0004-thread-naming.sh
@@ -3,17 +3,17 @@ test_description="naming of threads with changing subject"
 . ./test-lib.sh
 test_expect_success 'Generate some messages' '
 add_message "[subject]=\"thread-naming: Initial thread subject\"" \
-"[date]=\"Fri, 05 Jan 2001 15:43:56 -0800\"" &&
+"[date]=\"Fri, 05 Jan 2001 15:43:56 -\"" &&
 first=${gen_msg_cnt} &&
 parent=${gen_msg_id} &&
 add_message "[subject]=\"thread-naming: Older changed subject\"" \
-"[date]=\"Sat, 06 Jan 2001 15:43:56 -0800\"" \
+"[date]=\"Sat, 06 Jan 2001 15:43:56 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 add_message "[subject]=\"thread-naming: Newer changed subject\"" \
-"[date]=\"Sun, 07 Jan 2001 15:43:56 -0800\"" \
+"[date]=\"Sun, 07 Jan 2001 15:43:56 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 add_message "[subject]=\"thread-naming: Final thread subject\"" \
-"[date]=\"Mon, 08 Jan 2001 15:43:56 -0800\"" \
+"[date]=\"Mon, 08 Jan 2001 15:43:56 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 final=${gen_msg_id}

@@ -43,7 +43,7 @@ pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] 
Notmuch Test Suite; threa
 '
 test_expect_success "Ignore added reply prefix (Re:)" '
 add_message "[subject]=\"Re: thread-naming: Initial thread subject\"" \
-"[date]=\"Tue, 09 Jan 2001 15:43:45 -0800\"" \
+"[date]=\"Tue, 09 Jan 2001 15:43:45 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | 
notmuch_search_sanitize) &&
 pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; 
thread-naming: Initial thread subject (inbox unread)"
@@ -51,7 +51,7 @@ pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] 
Notmuch Test Suite; threa
 '
 test_expect_success "Ignore added reply prefix (Aw:)" '
 add_message "[subject]=\"Aw: thread-naming: Initial thread subject\"" \
-"[date]=\"Wed, 10 Jan 2001 15:43:45 -0800\"" \
+"[date]=\"Wed, 10 Jan 2001 15:43:45 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | 
notmuch_search_sanitize) &&
 pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] Notmuch Test Suite; 
thread-naming: Initial thread subject (inbox unread)"
@@ -59,7 +59,7 @@ pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] 
Notmuch Test Suite; threa
 '
 test_expect_success "Ignore added reply prefix (Vs:)" '
 add_message "[subject]=\"Vs: thread-naming: Initial thread subject\"" \
-"[date]=\"Thu, 11 Jan 2001 15:43:45 -0800\"" \
+"[date]=\"Thu, 11 Jan 2001 15:43:45 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | 
notmuch_search_sanitize) &&
 pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] Notmuch Test Suite; 
thread-naming: Initial thread subject (inbox unread)"
@@ -67,7 +67,7 @@ pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] 
Notmuch Test Suite; threa
 '
 test_expect_success "Ignore added reply prefix (Sv:)" '
 add_message "[subject]=\"Sv: thread-naming: Initial thread subject\"" \
-"[date]=\"Fri, 12 Jan 2001 15:43:45 -0800\"" \
+"[date]=\"Fri, 12 Jan 2001 15:43:45 -\"" \
 "[in-reply-to]=\<$parent\>" &&
 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | 
notmuch_search_sanitize) &&
 pass_if_equal "$output" "thread:XXX   2001-01-12 [6/8] Notmuch Test Suite; 
thread-naming: Initial thread subject (inbox unread)"
@@ -81,7 +81,7 @@ Notmuch Test Suite  
(2001-01-05) (unread)
 Subject: thread-naming: Initial thread subject
 From: Notmuch Test Suite 
 To: Notmuch Test Suite 
-Date: Fri, 05 Jan 2001 15:43:56 -0800
+Date: Fri, 05 Jan 2001 15:43:56 -
 header}
 body{
 part{ ID: 1, Content-type: text/plain
@@ -95,7 +95,7 @@ Notmuch Test Suite  
(2001-01-06) (inbox unread)
 Subject: thread-naming: Older changed subject
 From: Notmuch Test Suite 
 To: Notmuch Test Suite 
-Date: Sat, 06 Jan 2001 15:43:56 -0800
+Date: Sat, 06 Jan 2001 15:43:56 -
 header}
 body{
 part{ ID: 1, Content-type: text/plain
@@ -109,7 +109,7 @@ Notmuch Test Suite  
(2001-01-07) (inbox unread)
 Subject: thread-naming: Newer changed subject
 From: Notmuch Test Suite 
 To: Notmuch Test Suite 

[PATCH v2 4/5] Convert the actual tests to the new framework

2010-05-10 Thread Michal Sojka
The changes are:
- The notmuch-test was split into several files (t000?-*.sh).
- Removed helper functions which were moved to test-lib.sh
- Replaced every printf with test_expect_success.
- Test commands chained with && (test-lib.sh doesn't use "set -e" in
  order to complete the test suite even if something fails)
- Many variables such as ${MAIL_DIR} were properly quoted as they
  contain spaces.
- Changed quoting patterns in add_message and generate_message (single
  quotes are already used by the test framework).
- ${TEST_DIR} replaced by ${PWD}

QUICK HOWTO:

To run the whole test suite
make

To run only a single test
   ./t0001-new.sh

To stop on the first error
   ./t0001-new.sh -i
then mail store and database can be inspected in
"trash directory.t0001-new"

To see the output of tests
   ./t0001-new.sh -v

To not remove trash directory at the end:
   ./t0001-new.sh -d

To run all tests verbosely:
   make GIT_TEST_OPTS="-v"

Signed-off-by: Michal Sojka 
---
 test/notmuch-test| 1114 +-
 test/t-basic.sh  |2 +-
 test/t0001-new.sh|  164 +
 test/t0002-search.sh |  111 
 test/t0003-json.sh   |   46 ++
 test/t0004-thread-naming.sh  |  191 ++
 test/t0005-reply.sh  |  122 
 test/t0006-dump-restore.sh   |   30 +
 test/t0007-uuencode.sh   |   36 ++
 test/t0008-threading-out-of-order.sh |   31 +
 test/t0009-author-reordering.sh  |   35 ++
 test/t0010-from-line-heuristics.sh   |  214 +++
 12 files changed, 983 insertions(+), 1113 deletions(-)
 create mode 100755 test/t0001-new.sh
 create mode 100755 test/t0002-search.sh
 create mode 100755 test/t0003-json.sh
 create mode 100755 test/t0004-thread-naming.sh
 create mode 100755 test/t0005-reply.sh
 create mode 100755 test/t0006-dump-restore.sh
 create mode 100755 test/t0007-uuencode.sh
 create mode 100755 test/t0008-threading-out-of-order.sh
 create mode 100755 test/t0009-author-reordering.sh
 create mode 100755 test/t0010-from-line-heuristics.sh

diff --git a/test/notmuch-test b/test/notmuch-test
index a861df1..5c066ed 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -1,1114 +1,4 @@
 #!/bin/bash
-set -e

-# Messages contain time/date values with time zone and notmuch
-# displays them converted to the local time zone. We need to set fixed
-# timezone here so that the output of the tests is always the same
-# without regard to the time zone of where the test suite is run.
-export TZ=UTC+8
-
-find_notmuch_binary ()
-{
-dir=$1
-
-while [ -n "$dir" ]; do
-   bin=$dir/notmuch
-   if [ -x $bin ]; then
-   echo $bin
-   return
-   fi
-   dir=$(dirname $dir)
-   if [ "$dir" = "/" ]; then
-   break
-   fi
-done
-
-echo notmuch
-}
-
-increment_mtime_amount=0
-increment_mtime ()
-{
-dir=$1
-
-increment_mtime_amount=$((increment_mtime_amount + 1))
-touch -d "+${increment_mtime_amount} seconds" $dir
-}
-
-# Generate a new message in the mail directory, with a unique message
-# ID and subject. The message is not added to the index.
-#
-# After this function returns, the filename of the generated message
-# is available as $gen_msg_filename and the message ID is available as
-# $gen_msg_id .
-#
-# This function supports named parameters with the bash syntax for
-# assigning a value to an associative array ([name]=value). The
-# supported parameters are:
-#
-#  [dir]=directory/of/choice
-#
-#  Generate the message in directory 'directory/of/choice' within
-#  the mail store. The directory will be created if necessary.
-#
-#  [body]=text
-#
-#  Text to use as the body of the email message
-#
-#  '[from]="Some User "'
-#  '[to]="Some User "'
-#  '[subject]="Subject of email message"'
-#  '[date]="RFC 822 Date"'
-#
-#  Values for email headers. If not provided, default values will
-#  be generated instead.
-#
-#  '[cc]="Some User "'
-#  [reply-to]=some-address
-#  [in-reply-to]=
-#  '[header]=full header line, including keyword'
-#
-#  Additional values for email headers. If these are not provided
-#  then the relevant headers will simply not appear in the
-#  message.
-#
-#  '[id]='
-#
-#  Controls the message-id of the created message.
-gen_msg_cnt=0
-gen_msg_filename=""
-gen_msg_id=""
-generate_message ()
-{
-# This is our (bash-specific) magic for doing named parameters
-local -A template="($@)"
-local additional_headers
-
-if [ -z "${template[id]}" ]; then
-   gen_msg_cnt=$((gen_msg_cnt + 1))
-   gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
-   gen_msg_id="${gen_msg_name}@notmuch-test-suite"
-else
-   gen_msg_name="msg-${template[id]}"
-   gen_msg_id="${template[id]}"
-fi
-
-if [ -z "${template[dir]}" ]; then
-   gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
-else
-   

[PATCH v2 3/5] test: Update helper functions

2010-05-10 Thread Michal Sojka
Modify the helper functions to work with git-based test suite i.e.
1) Quote arguments where it is necessary.
2) Do not use $NOTMUCH. It doesn't exist and $PATH is set to the build
   tree
3) Modify pass_if_equal to fit into the git-based test suite.

Signed-off-by: Michal Sojka 
---
 test/test-lib.sh |   33 +
 1 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index e780dd3..06559cd 100755
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -221,10 +221,10 @@ remove_cr () {
 increment_mtime_amount=0
 increment_mtime ()
 {
-dir=$1
+dir="$1"

 increment_mtime_amount=$((increment_mtime_amount + 1))
-touch -d "+${increment_mtime_amount} seconds" $dir
+touch -d "+${increment_mtime_amount} seconds" "$dir"
 }

 # Generate a new message in the mail directory, with a unique message
@@ -289,7 +289,7 @@ generate_message ()
gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
 else
gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
-   mkdir -p $(dirname $gen_msg_filename)
+   mkdir -p "$(dirname "$gen_msg_filename")"
 fi

 if [ -z "${template[body]}" ]; then
@@ -334,7 +334,7 @@ ${additional_headers}"
 fi


-cat <$gen_msg_filename
+cat <"$gen_msg_filename"
 From: ${template[from]}
 To: ${template[to]}
 Message-Id: <${gen_msg_id}>
@@ -345,7 +345,7 @@ ${template[body]}
 EOF

 # Ensure that the mtime of the containing directory is updated
-increment_mtime $(dirname ${gen_msg_filename})
+increment_mtime "$(dirname "${gen_msg_filename}")"
 }

 # Generate a new message and add it to the index.
@@ -354,41 +354,34 @@ EOF
 # are also supported here, so see that function for details.
 add_message ()
 {
-generate_message "$@"
-
-$NOTMUCH new > /dev/null
+generate_message "$@" &&
+notmuch new > /dev/null
 }

-tests=0
-test_failures=0
-
 pass_if_equal ()
 {
 output=$1
 expected=$2

-tests=$((tests + 1))
-
 if [ "$output" = "$expected" ]; then
-   echo "  PASS"
+   true
 else
-   echo "  FAIL"
-   testname=test-$(printf "%03d" $tests)
+   testname=$this_test.$test_count
echo "$expected" > $testname.expected
echo "$output" > $testname.output
-   diff -u $testname.expected $testname.output || true
-   test_failures=$((test_failures + 1))
+   diff -u $testname.expected $testname.output
+   false
 fi
 }

 TEST_DIR=$(pwd)/test.$$
 MAIL_DIR=${TEST_DIR}/mail
 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
-NOTMUCH=$(find_notmuch_binary $(pwd))
+NOTMUCH=notmuch

 NOTMUCH_NEW ()
 {
-$NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* 
total file'
+notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* 
total file'
 }

 notmuch_search_sanitize ()
-- 
1.7.1



[PATCH v2 2/5] Update test framework for use with notmuch

2010-05-10 Thread Michal Sojka
This removes Git specific things from the test-lib.sh and adds helper
functions for notmuch taken from Carl's notmuch-test script. README is
also slightly modified to reflect the current state.

Signed-off-by: Michal Sojka 
---
 test/Makefile   |1 +
 test/README |   12 +-
 test/t-basic.sh |  335 +++
 test/test-lib.sh|  362 +++
 4 files changed, 244 insertions(+), 466 deletions(-)
 mode change 100644 => 100755 test/test-lib.sh

diff --git a/test/Makefile b/test/Makefile
index 25c559b..7a29eaa 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -6,6 +6,7 @@
 -include ../config.mak

 #GIT_TEST_OPTS=--verbose --debug
+SHELL=/bin/bash
 SHELL_PATH ?= $(SHELL)
 TAR ?= $(TAR)
 RM ?= rm -f
diff --git a/test/README b/test/README
index dcd3ebb..af27d60 100644
--- a/test/README
+++ b/test/README
@@ -165,10 +165,10 @@ Writing Tests
 -

 The test script is written as a shell script.  It should start
-with the standard "#!/bin/sh" with copyright notices, and an
+with the standard "#!/bin/bash" with copyright notices, and an
 assignment to variable 'test_description', like this:

-   #!/bin/sh
+   #!/bin/bash
#
# Copyright (c) 2005 Junio C Hamano
#
@@ -192,9 +192,11 @@ This test harness library does the following things:
  - If the script is invoked with command line argument --help
(or -h), it shows the test_description and exits.

- - Creates an empty test directory with an empty .git/objects
-   database and chdir(2) into it.  This directory is 't/trash directory'
-   if you must know, but I do not think you care.
+ - Creates a test directory with default notmuch-config and empty mail
+   store. This directory is 't/trash directory.' (note
+   the space) if you must know, but I do not think you care. The path
+   to notmuch-config is exported in NOTMUCH_CONFIG environment
+   variable and mail store path is stored in MAIL_DIR variable.

  - Defines standard test helper functions for your scripts to
use.  These functions are designed to make all scripts behave
diff --git a/test/t-basic.sh b/test/t-basic.sh
index 3ec9cbe..caade68 100755
--- a/test/t-basic.sh
+++ b/test/t-basic.sh
@@ -3,48 +3,39 @@
 # Copyright (c) 2005 Junio C Hamano
 #

-test_description='Test the very basics part #1.
-
-The rest of the test suite does not check the basic operation of git
-plumbing commands to work very carefully.  Their job is to concentrate
-on tricky features that caused bugs in the past to detect regression.
-
-This test runs very basic features, like registering things in cache,
-writing tree, etc.
-
-Note that this test *deliberately* hard-codes many expected object
-IDs.  When object ID computation changes, like in the previous case of
-swapping compression and hashing order, the person who is making the
-modification *should* take notice and update the test vectors here.
-'
+test_description='Tests the test framework itself.'

 
 # It appears that people try to run tests without building...

-../git >/dev/null
-if test $? != 1
+if ! test -x ../notmuch
 then
-   echo >&2 'You do not seem to have built git yet.'
+   echo >&2 'You do not seem to have built notmuch yet.'
exit 1
 fi

 . ./test-lib.sh

 
-# git init has been done in an empty repository.
-# make sure it is empty.
+# Test mail store prepared in test-lib.sh

-find .git/objects -type f -print >should-be-empty
 test_expect_success \
-'.git/objects should be empty after git init in an empty repo.' \
+'test that mail store was created' \
+'test -d "${MAIL_DIR}"'
+
+
+find "${MAIL_DIR}" -type f -print >should-be-empty
+test_expect_success \
+'mail store should be empty' \
 'cmp -s /dev/null should-be-empty'

-# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
-# 3 is counting "objects" itself
-find .git/objects -type d -print >full-of-directories
 test_expect_success \
-'.git/objects should have 3 subdirectories.' \
-'test $(wc -l < full-of-directories) = 3'
+'NOTMUCH_CONFIG is set and points to an existing file' \
+'test -f "${NOTMUCH_CONFIG}"'
+
+test_expect_success \
+'PATH is set to this repository' \
+'test "`echo $PATH|cut -f1 -d:`" = "`dirname ${TEST_DIRECTORY}`"'

 
 # Test harness
@@ -94,296 +85,4 @@ test_expect_code 2 'failure to clean up causes the test to 
fail' '
 test_when_finished "(exit 2)"
 '

-
-# Basics of the basics
-
-# updating a new file without --add should fail.
-test_expect_success 'git update-index without --add should fail adding.' '
-test_must_fail git update-index should-be-empty
-'
-
-# and with --add it should succeed, 

[PATCH v2 1/5] Copy test framework from Git

2010-05-10 Thread Michal Sojka
Git uses a simple and yet powerful test framework, written in shell.
The framework is easy to use for both users and developers so I think
it would help if it is used in notmuch as well.

This is a copy of Git's test framework from commit
b6b0afdc30e066788592ca07c9a6c6936c68cc11 in git repository.

Signed-off-by: Michal Sojka 
---
 test/Makefile |   48 +++
 test/README   |  297 
 test/aggregate-results.sh |   34 ++
 test/t-basic.sh   |  389 +
 test/test-lib.sh  |  832 +
 5 files changed, 1600 insertions(+), 0 deletions(-)
 create mode 100644 test/Makefile
 create mode 100644 test/README
 create mode 100755 test/aggregate-results.sh
 create mode 100755 test/t-basic.sh
 create mode 100644 test/test-lib.sh

diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 000..25c559b
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,48 @@
+# Run tests
+#
+# Copyright (c) 2005 Junio C Hamano
+#
+
+-include ../config.mak
+
+#GIT_TEST_OPTS=--verbose --debug
+SHELL_PATH ?= $(SHELL)
+TAR ?= $(TAR)
+RM ?= rm -f
+
+# Shell quote;
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+
+T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
+TSVN = $(wildcard t91[0-9][0-9]-*.sh)
+
+all: pre-clean
+   $(MAKE) aggregate-results-and-cleanup
+
+$(T):
+   @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ 
$(GIT_TEST_OPTS)
+
+pre-clean:
+   $(RM) -r test-results
+
+clean:
+   $(RM) -r 'trash directory'.* test-results
+   $(RM) t/cvsroot/CVSROOT/?*
+   $(RM) -r valgrind/bin
+
+aggregate-results-and-cleanup: $(T)
+   $(MAKE) aggregate-results
+   $(MAKE) clean
+
+aggregate-results:
+   '$(SHELL_PATH_SQ)' ./aggregate-results.sh test-results/t*-*
+
+# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
+full-svn-test:
+   $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C
+   $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8
+
+valgrind:
+   GIT_TEST_OPTS=--valgrind $(MAKE)
+
+.PHONY: pre-clean $(T) aggregate-results clean valgrind
diff --git a/test/README b/test/README
new file mode 100644
index 000..dcd3ebb
--- /dev/null
+++ b/test/README
@@ -0,0 +1,297 @@
+Core GIT Tests
+==
+
+This directory holds many test scripts for core GIT tools.  The
+first part of this short document describes how to run the tests
+and read their output.
+
+When fixing the tools or adding enhancements, you are strongly
+encouraged to add tests in this directory to cover what you are
+trying to fix or enhance.  The later part of this short document
+describes how your test scripts should be organized.
+
+
+Running Tests
+-
+
+The easiest way to run tests is to say "make".  This runs all
+the tests.
+
+*** t-basic.sh ***
+*   ok 1: .git/objects should be empty after git-init in an empty repo.
+*   ok 2: .git/objects should have 256 subdirectories.
+*   ok 3: git-update-index without --add should fail adding.
+...
+*   ok 23: no diff after checkout and git-update-index --refresh.
+* passed all 23 test(s)
+*** t0100-environment-names.sh ***
+*   ok 1: using old names should issue warnings.
+*   ok 2: using old names but having new names should not issue warnings.
+...
+
+Or you can run each test individually from command line, like
+this:
+
+$ sh ./t3001-ls-files-killed.sh
+*   ok 1: git-update-index --add to add various paths.
+*   ok 2: git-ls-files -k to show killed files.
+*   ok 3: validate git-ls-files -k output.
+* passed all 3 test(s)
+
+You can pass --verbose (or -v), --debug (or -d), and --immediate
+(or -i) command line argument to the test, or by setting GIT_TEST_OPTS
+appropriately before running "make".
+
+--verbose::
+   This makes the test more verbose.  Specifically, the
+   command being run and their output if any are also
+   output.
+
+--debug::
+   This may help the person who is developing a new test.
+   It causes the command defined with test_debug to run.
+
+--immediate::
+   This causes the test to immediately exit upon the first
+   failed test.
+
+--long-tests::
+   This causes additional long-running tests to be run (where
+   available), for more exhaustive testing.
+
+--valgrind::
+   Execute all Git binaries with valgrind and exit with status
+   126 on errors (just like regular tests, this will only stop
+   the test script when running under -i).  Valgrind errors
+   go to stderr, so you might want to pass the -v option, too.
+
+   Since it makes no sense to run the tests with --valgrind and
+   not see any output, this option implies --verbose.  For
+   convenience, it also implies --tee.
+
+--tee::
+   In addition to printing the test output to the terminal,
+   write it to files named 't/test-results/$TEST_NAME.out'.
+   As the names depend on the 

[PATCH v2 0/5] Git-based modularization of test suite

2010-05-10 Thread Michal Sojka
Hi,

Git's test suite was finally reslicensed and we can use it for
notmuch. Here is the converted and modularized version of notmuch-test
script which uses git's test-lib.sh.

The conversion was done semi-automatically, so I hope I didn't
introduce to much errors in the tests.

Michal Sojka (5):
  Copy test framework from Git
  Update test framework for use with notmuch
  test: Update helper functions
  Convert the actual tests to the new framework
  test: Set all times to UTC

 test/Makefile|   49 ++
 test/README  |  299 +
 test/aggregate-results.sh|   34 +
 test/notmuch-test| 1114 +-
 test/t-basic.sh  |   88 +++
 test/t0001-new.sh|  164 +
 test/t0002-search.sh |  111 
 test/t0003-json.sh   |   46 ++
 test/t0004-thread-naming.sh  |  191 ++
 test/t0005-reply.sh  |  122 
 test/t0006-dump-restore.sh   |   30 +
 test/t0007-uuencode.sh   |   36 ++
 test/t0008-threading-out-of-order.sh |   31 +
 test/t0009-author-reordering.sh  |   35 ++
 test/t0010-from-line-heuristics.sh   |  214 +++
 test/test-lib.sh |  901 +++
 16 files changed, 2353 insertions(+), 1112 deletions(-)
 create mode 100644 test/Makefile
 create mode 100644 test/README
 create mode 100755 test/aggregate-results.sh
 create mode 100755 test/t-basic.sh
 create mode 100755 test/t0001-new.sh
 create mode 100755 test/t0002-search.sh
 create mode 100755 test/t0003-json.sh
 create mode 100755 test/t0004-thread-naming.sh
 create mode 100755 test/t0005-reply.sh
 create mode 100755 test/t0006-dump-restore.sh
 create mode 100755 test/t0007-uuencode.sh
 create mode 100755 test/t0008-threading-out-of-order.sh
 create mode 100755 test/t0009-author-reordering.sh
 create mode 100755 test/t0010-from-line-heuristics.sh
 create mode 100755 test/test-lib.sh



rfc: improved MIME handling (multipart)

2010-05-10 Thread David Edmondson
A (third) attempt at improved MIME handling, specifically for multipart,
is at:
   http://github.com/dme/notmuch/tree/mp3
   git://github.com/dme/notmuch.git (branch 'mp3')

I wouldn't describe this as finished, but it's usable for my own
day-to-day work, so I'd like to see if some others could try it out and
provide feedback. Particularly interesting would be to know about
messages where it behaves badly.

The JSON format output from `notmuch show' is where most of the change
is apparent. The text output should be similar to before, with the only
change being to output a header{} block for in-lined message/rfc822
parts. This could be easily removed if it breaks something (the vim
plugin?).

This doesn't yet have the changes necessary to support multipart/related
text/html parts with associated graphics or useful multipart/signed
(there's no checking of signatures, etc.). Those should be `a simple
matter' of writing some more emacs lisp. If someone else wants to have a
go at that I'd be thrilled.

dme.
-- 
David Edmondson, http://dme.org
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100510/dc554e9f/attachment.pgp>


rfc: improved MIME handling (multipart)

2010-05-10 Thread David Edmondson
A (third) attempt at improved MIME handling, specifically for multipart,
is at:
   http://github.com/dme/notmuch/tree/mp3
   git://github.com/dme/notmuch.git (branch 'mp3')

I wouldn't describe this as finished, but it's usable for my own
day-to-day work, so I'd like to see if some others could try it out and
provide feedback. Particularly interesting would be to know about
messages where it behaves badly.

The JSON format output from `notmuch show' is where most of the change
is apparent. The text output should be similar to before, with the only
change being to output a header{} block for in-lined message/rfc822
parts. This could be easily removed if it breaks something (the vim
plugin?).

This doesn't yet have the changes necessary to support multipart/related
text/html parts with associated graphics or useful multipart/signed
(there's no checking of signatures, etc.). Those should be `a simple
matter' of writing some more emacs lisp. If someone else wants to have a
go at that I'd be thrilled.

dme.
-- 
David Edmondson, http://dme.org


pgp3ZcHaHyCPi.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 0/5] Git-based modularization of test suite

2010-05-10 Thread Michal Sojka
Hi,

Git's test suite was finally reslicensed and we can use it for
notmuch. Here is the converted and modularized version of notmuch-test
script which uses git's test-lib.sh.

The conversion was done semi-automatically, so I hope I didn't
introduce to much errors in the tests.

Michal Sojka (5):
  Copy test framework from Git
  Update test framework for use with notmuch
  test: Update helper functions
  Convert the actual tests to the new framework
  test: Set all times to UTC

 test/Makefile|   49 ++
 test/README  |  299 +
 test/aggregate-results.sh|   34 +
 test/notmuch-test| 1114 +-
 test/t-basic.sh  |   88 +++
 test/t0001-new.sh|  164 +
 test/t0002-search.sh |  111 
 test/t0003-json.sh   |   46 ++
 test/t0004-thread-naming.sh  |  191 ++
 test/t0005-reply.sh  |  122 
 test/t0006-dump-restore.sh   |   30 +
 test/t0007-uuencode.sh   |   36 ++
 test/t0008-threading-out-of-order.sh |   31 +
 test/t0009-author-reordering.sh  |   35 ++
 test/t0010-from-line-heuristics.sh   |  214 +++
 test/test-lib.sh |  901 +++
 16 files changed, 2353 insertions(+), 1112 deletions(-)
 create mode 100644 test/Makefile
 create mode 100644 test/README
 create mode 100755 test/aggregate-results.sh
 create mode 100755 test/t-basic.sh
 create mode 100755 test/t0001-new.sh
 create mode 100755 test/t0002-search.sh
 create mode 100755 test/t0003-json.sh
 create mode 100755 test/t0004-thread-naming.sh
 create mode 100755 test/t0005-reply.sh
 create mode 100755 test/t0006-dump-restore.sh
 create mode 100755 test/t0007-uuencode.sh
 create mode 100755 test/t0008-threading-out-of-order.sh
 create mode 100755 test/t0009-author-reordering.sh
 create mode 100755 test/t0010-from-line-heuristics.sh
 create mode 100755 test/test-lib.sh

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2 2/5] Update test framework for use with notmuch

2010-05-10 Thread Michal Sojka
This removes Git specific things from the test-lib.sh and adds helper
functions for notmuch taken from Carl's notmuch-test script. README is
also slightly modified to reflect the current state.

Signed-off-by: Michal Sojka sojk...@fel.cvut.cz
---
 test/Makefile   |1 +
 test/README |   12 +-
 test/t-basic.sh |  335 +++
 test/test-lib.sh|  362 +++
 4 files changed, 244 insertions(+), 466 deletions(-)
 mode change 100644 = 100755 test/test-lib.sh

diff --git a/test/Makefile b/test/Makefile
index 25c559b..7a29eaa 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -6,6 +6,7 @@
 -include ../config.mak
 
 #GIT_TEST_OPTS=--verbose --debug
+SHELL=/bin/bash
 SHELL_PATH ?= $(SHELL)
 TAR ?= $(TAR)
 RM ?= rm -f
diff --git a/test/README b/test/README
index dcd3ebb..af27d60 100644
--- a/test/README
+++ b/test/README
@@ -165,10 +165,10 @@ Writing Tests
 -
 
 The test script is written as a shell script.  It should start
-with the standard #!/bin/sh with copyright notices, and an
+with the standard #!/bin/bash with copyright notices, and an
 assignment to variable 'test_description', like this:
 
-   #!/bin/sh
+   #!/bin/bash
#
# Copyright (c) 2005 Junio C Hamano
#
@@ -192,9 +192,11 @@ This test harness library does the following things:
  - If the script is invoked with command line argument --help
(or -h), it shows the test_description and exits.
 
- - Creates an empty test directory with an empty .git/objects
-   database and chdir(2) into it.  This directory is 't/trash directory'
-   if you must know, but I do not think you care.
+ - Creates a test directory with default notmuch-config and empty mail
+   store. This directory is 't/trash directory.test-basename' (note
+   the space) if you must know, but I do not think you care. The path
+   to notmuch-config is exported in NOTMUCH_CONFIG environment
+   variable and mail store path is stored in MAIL_DIR variable.
 
  - Defines standard test helper functions for your scripts to
use.  These functions are designed to make all scripts behave
diff --git a/test/t-basic.sh b/test/t-basic.sh
index 3ec9cbe..caade68 100755
--- a/test/t-basic.sh
+++ b/test/t-basic.sh
@@ -3,48 +3,39 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-test_description='Test the very basics part #1.
-
-The rest of the test suite does not check the basic operation of git
-plumbing commands to work very carefully.  Their job is to concentrate
-on tricky features that caused bugs in the past to detect regression.
-
-This test runs very basic features, like registering things in cache,
-writing tree, etc.
-
-Note that this test *deliberately* hard-codes many expected object
-IDs.  When object ID computation changes, like in the previous case of
-swapping compression and hashing order, the person who is making the
-modification *should* take notice and update the test vectors here.
-'
+test_description='Tests the test framework itself.'
 
 
 # It appears that people try to run tests without building...
 
-../git /dev/null
-if test $? != 1
+if ! test -x ../notmuch
 then
-   echo 2 'You do not seem to have built git yet.'
+   echo 2 'You do not seem to have built notmuch yet.'
exit 1
 fi
 
 . ./test-lib.sh
 
 
-# git init has been done in an empty repository.
-# make sure it is empty.
+# Test mail store prepared in test-lib.sh
 
-find .git/objects -type f -print should-be-empty
 test_expect_success \
-'.git/objects should be empty after git init in an empty repo.' \
+'test that mail store was created' \
+'test -d ${MAIL_DIR}'
+
+
+find ${MAIL_DIR} -type f -print should-be-empty
+test_expect_success \
+'mail store should be empty' \
 'cmp -s /dev/null should-be-empty'
 
-# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
-# 3 is counting objects itself
-find .git/objects -type d -print full-of-directories
 test_expect_success \
-'.git/objects should have 3 subdirectories.' \
-'test $(wc -l  full-of-directories) = 3'
+'NOTMUCH_CONFIG is set and points to an existing file' \
+'test -f ${NOTMUCH_CONFIG}'
+
+test_expect_success \
+'PATH is set to this repository' \
+'test `echo $PATH|cut -f1 -d:` = `dirname ${TEST_DIRECTORY}`'
 
 
 # Test harness
@@ -94,296 +85,4 @@ test_expect_code 2 'failure to clean up causes the test to 
fail' '
 test_when_finished (exit 2)
 '
 
-
-# Basics of the basics
-
-# updating a new file without --add should fail.
-test_expect_success 'git update-index without --add should fail adding.' '
-test_must_fail git update-index should-be-empty
-'
-
-# and with --add it 

[PATCH v2 1/5] Copy test framework from Git

2010-05-10 Thread Michal Sojka
Git uses a simple and yet powerful test framework, written in shell.
The framework is easy to use for both users and developers so I think
it would help if it is used in notmuch as well.

This is a copy of Git's test framework from commit
b6b0afdc30e066788592ca07c9a6c6936c68cc11 in git repository.

Signed-off-by: Michal Sojka sojk...@fel.cvut.cz
---
 test/Makefile |   48 +++
 test/README   |  297 
 test/aggregate-results.sh |   34 ++
 test/t-basic.sh   |  389 +
 test/test-lib.sh  |  832 +
 5 files changed, 1600 insertions(+), 0 deletions(-)
 create mode 100644 test/Makefile
 create mode 100644 test/README
 create mode 100755 test/aggregate-results.sh
 create mode 100755 test/t-basic.sh
 create mode 100644 test/test-lib.sh

diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 000..25c559b
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,48 @@
+# Run tests
+#
+# Copyright (c) 2005 Junio C Hamano
+#
+
+-include ../config.mak
+
+#GIT_TEST_OPTS=--verbose --debug
+SHELL_PATH ?= $(SHELL)
+TAR ?= $(TAR)
+RM ?= rm -f
+
+# Shell quote;
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+
+T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
+TSVN = $(wildcard t91[0-9][0-9]-*.sh)
+
+all: pre-clean
+   $(MAKE) aggregate-results-and-cleanup
+
+$(T):
+   @echo *** $@ ***; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ 
$(GIT_TEST_OPTS)
+
+pre-clean:
+   $(RM) -r test-results
+
+clean:
+   $(RM) -r 'trash directory'.* test-results
+   $(RM) t/cvsroot/CVSROOT/?*
+   $(RM) -r valgrind/bin
+
+aggregate-results-and-cleanup: $(T)
+   $(MAKE) aggregate-results
+   $(MAKE) clean
+
+aggregate-results:
+   '$(SHELL_PATH_SQ)' ./aggregate-results.sh test-results/t*-*
+
+# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL
+full-svn-test:
+   $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C
+   $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8
+
+valgrind:
+   GIT_TEST_OPTS=--valgrind $(MAKE)
+
+.PHONY: pre-clean $(T) aggregate-results clean valgrind
diff --git a/test/README b/test/README
new file mode 100644
index 000..dcd3ebb
--- /dev/null
+++ b/test/README
@@ -0,0 +1,297 @@
+Core GIT Tests
+==
+
+This directory holds many test scripts for core GIT tools.  The
+first part of this short document describes how to run the tests
+and read their output.
+
+When fixing the tools or adding enhancements, you are strongly
+encouraged to add tests in this directory to cover what you are
+trying to fix or enhance.  The later part of this short document
+describes how your test scripts should be organized.
+
+
+Running Tests
+-
+
+The easiest way to run tests is to say make.  This runs all
+the tests.
+
+*** t-basic.sh ***
+*   ok 1: .git/objects should be empty after git-init in an empty repo.
+*   ok 2: .git/objects should have 256 subdirectories.
+*   ok 3: git-update-index without --add should fail adding.
+...
+*   ok 23: no diff after checkout and git-update-index --refresh.
+* passed all 23 test(s)
+*** t0100-environment-names.sh ***
+*   ok 1: using old names should issue warnings.
+*   ok 2: using old names but having new names should not issue warnings.
+...
+
+Or you can run each test individually from command line, like
+this:
+
+$ sh ./t3001-ls-files-killed.sh
+*   ok 1: git-update-index --add to add various paths.
+*   ok 2: git-ls-files -k to show killed files.
+*   ok 3: validate git-ls-files -k output.
+* passed all 3 test(s)
+
+You can pass --verbose (or -v), --debug (or -d), and --immediate
+(or -i) command line argument to the test, or by setting GIT_TEST_OPTS
+appropriately before running make.
+
+--verbose::
+   This makes the test more verbose.  Specifically, the
+   command being run and their output if any are also
+   output.
+
+--debug::
+   This may help the person who is developing a new test.
+   It causes the command defined with test_debug to run.
+
+--immediate::
+   This causes the test to immediately exit upon the first
+   failed test.
+
+--long-tests::
+   This causes additional long-running tests to be run (where
+   available), for more exhaustive testing.
+
+--valgrind::
+   Execute all Git binaries with valgrind and exit with status
+   126 on errors (just like regular tests, this will only stop
+   the test script when running under -i).  Valgrind errors
+   go to stderr, so you might want to pass the -v option, too.
+
+   Since it makes no sense to run the tests with --valgrind and
+   not see any output, this option implies --verbose.  For
+   convenience, it also implies --tee.
+
+--tee::
+   In addition to printing the test output to the terminal,
+   write it to files named 't/test-results/$TEST_NAME.out'.
+   As the names 

[PATCH v2 3/5] test: Update helper functions

2010-05-10 Thread Michal Sojka
Modify the helper functions to work with git-based test suite i.e.
1) Quote arguments where it is necessary.
2) Do not use $NOTMUCH. It doesn't exist and $PATH is set to the build
   tree
3) Modify pass_if_equal to fit into the git-based test suite.

Signed-off-by: Michal Sojka sojk...@fel.cvut.cz
---
 test/test-lib.sh |   33 +
 1 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index e780dd3..06559cd 100755
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -221,10 +221,10 @@ remove_cr () {
 increment_mtime_amount=0
 increment_mtime ()
 {
-dir=$1
+dir=$1
 
 increment_mtime_amount=$((increment_mtime_amount + 1))
-touch -d +${increment_mtime_amount} seconds $dir
+touch -d +${increment_mtime_amount} seconds $dir
 }
 
 # Generate a new message in the mail directory, with a unique message
@@ -289,7 +289,7 @@ generate_message ()
gen_msg_filename=${MAIL_DIR}/$gen_msg_name
 else
gen_msg_filename=${MAIL_DIR}/${template[dir]}/$gen_msg_name
-   mkdir -p $(dirname $gen_msg_filename)
+   mkdir -p $(dirname $gen_msg_filename)
 fi
 
 if [ -z ${template[body]} ]; then
@@ -334,7 +334,7 @@ ${additional_headers}
 fi
 
 
-cat EOF $gen_msg_filename
+cat EOF $gen_msg_filename
 From: ${template[from]}
 To: ${template[to]}
 Message-Id: ${gen_msg_id}
@@ -345,7 +345,7 @@ ${template[body]}
 EOF
 
 # Ensure that the mtime of the containing directory is updated
-increment_mtime $(dirname ${gen_msg_filename})
+increment_mtime $(dirname ${gen_msg_filename})
 }
 
 # Generate a new message and add it to the index.
@@ -354,41 +354,34 @@ EOF
 # are also supported here, so see that function for details.
 add_message ()
 {
-generate_message $@
-
-$NOTMUCH new  /dev/null
+generate_message $@ 
+notmuch new  /dev/null
 }
 
-tests=0
-test_failures=0
-
 pass_if_equal ()
 {
 output=$1
 expected=$2
 
-tests=$((tests + 1))
-
 if [ $output = $expected ]; then
-   echo   PASS
+   true
 else
-   echo   FAIL
-   testname=test-$(printf %03d $tests)
+   testname=$this_test.$test_count
echo $expected  $testname.expected
echo $output  $testname.output
-   diff -u $testname.expected $testname.output || true
-   test_failures=$((test_failures + 1))
+   diff -u $testname.expected $testname.output
+   false
 fi
 }
 
 TEST_DIR=$(pwd)/test.$$
 MAIL_DIR=${TEST_DIR}/mail
 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
-NOTMUCH=$(find_notmuch_binary $(pwd))
+NOTMUCH=notmuch
 
 NOTMUCH_NEW ()
 {
-$NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* 
total file'
+notmuch new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* 
total file'
 }
 
 notmuch_search_sanitize ()
-- 
1.7.1

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch