#!/usr/bin/env bash
test_description="emacs tree view interface"
-. ./test-lib.sh || exit 1
+. $(dirname "$0")/test-lib.sh || exit 1
+. $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
-EXPECTED=$TEST_DIRECTORY/tree.expected-output
+EXPECTED=$NOTMUCH_SRCDIR/test/emacs-tree.expected-output
+test_require_emacs
add_email_corpus
test_begin_subtest "Basic notmuch-tree view in emacs"
(notmuch-test-wait)
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox OUTPUT
test_begin_subtest "Refreshed notmuch-tree view in emacs"
test_emacs '(notmuch-tree "tag:inbox")
(notmuch-test-wait)
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox OUTPUT
# In the following tag tests we make sure the display is updated
# correctly and, in a separate test, that the database is updated
(notmuch-tree-tag (list "+test_tag"))
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox-tagged
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox-tagged OUTPUT
test_begin_subtest "Tag message in notmuch tree view (database)"
output=$(notmuch search --output=messages 'tag:test_tag')
(notmuch-tree-tag (list "-test_tag"))
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox OUTPUT
test_begin_subtest "Untag message in notmuch tree view (database)"
output=$(notmuch search --output=messages 'tag:test_tag')
(notmuch-tree-tag-thread (list "+test_thread_tag"))
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox-thread-tagged
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox-thread-tagged OUTPUT
test_begin_subtest "Tag message in notmuch tree view (database)"
output=$(notmuch search --output=messages 'tag:test_thread_tag')
(notmuch-tree-tag-thread (list "-test_thread_tag"))
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox OUTPUT
test_begin_subtest "Untag message in notmuch tree view (database)"
output=$(notmuch search --output=messages 'tag:test_thread_tag')
(notmuch-test-wait)
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-tag-inbox
+test_expect_equal_file $EXPECTED/notmuch-tree-tag-inbox OUTPUT
test_begin_subtest "Tree view of a single thread (from search)"
test_emacs '(notmuch-hello)
(notmuch-test-wait)
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-single-thread
+test_expect_equal_file $EXPECTED/notmuch-tree-single-thread OUTPUT
test_begin_subtest "Tree view of a single thread (from show)"
test_emacs '(notmuch-hello)
(notmuch-test-wait)
(test-output)
(delete-other-windows)'
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-single-thread
+test_expect_equal_file $EXPECTED/notmuch-tree-single-thread OUTPUT
test_begin_subtest "Message window of tree view"
test_emacs '(notmuch-hello)
(select-window notmuch-tree-message-window)
(test-output)
(delete-other-windows)'
-cp OUTPUT /tmp/mjwout
-test_expect_equal_file OUTPUT $EXPECTED/notmuch-tree-show-window
+test_expect_equal_file $EXPECTED/notmuch-tree-show-window OUTPUT
test_begin_subtest "Stash id"
output=$(test_emacs '(notmuch-tree "id:1258498485-sup-142@elly")
(notmuch-show-stash-message-id)')
test_expect_equal "$output" "\"Stashed: id:1258493565-13508-1-git-send-email-keithp@keithp.com\""
+test_begin_subtest "Functions in tree-result-format"
+test_emacs '
+(let
+ ((notmuch-tree-result-format
+ (quote (("date" . "%12s ")
+ ("authors" . "%-20s")
+ ((("tree" . "%s")
+ ("subject" . "%s")) . " %-54s ")
+ (notmuch-test-result-flags . "(%s)")))))
+ (notmuch-tree "tag:inbox")
+ (notmuch-test-wait)
+ (test-output))
+'
+test_expect_equal_file $EXPECTED/result-format-function OUTPUT
+
+test_begin_subtest "notmuch-tree with nonexistent CWD"
+test_emacs '(test-log-error
+ (let ((default-directory "/nonexistent"))
+ (notmuch-tree "*")))'
+test_expect_equal "$(cat MESSAGES)" "COMPLETE"
+
+add_email_corpus duplicate
+
+ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
+test_begin_subtest "duplicate=3, subject"
+test_emacs "(notmuch-tree \"id:${ID3}\")
+ (notmuch-test-wait)
+ (notmuch-tree-show-message t)
+ (notmuch-show-choose-duplicate 3)
+ (test-visible-output \"OUTPUT\")"
+output=$(grep "Subject:" OUTPUT)
+file=$(notmuch search --output=files id:${ID3} | head -n 3 | tail -n 1)
+subject=$(grep '^Subject:' $file)
+test_expect_equal "$output" "$subject"
+
+test_begin_subtest "duplicate=4"
+test_emacs "(notmuch-show \"id:${ID3}\")
+ (notmuch-test-wait)
+ (notmuch-tree-show-message t)
+ (notmuch-show-choose-duplicate 4)
+ (test-visible-output \"OUTPUT\")"
+test_expect_equal_file_nonempty $NOTMUCH_SRCDIR/test/emacs-show.expected-output/notmuch-show-duplicate-4 OUTPUT
+
test_done