test: set variables using let' instead of setq' in Emacs tests

Using `setq' for setting variables in Emacs tests affect other
tests that may run in the same Emacs environment.  Currently it
works because each test is run in a separate Emacs instance.  But
in the future multiple tests will run in a single Emacs instance.
The patch changes all variables to use `let', so the scope of the
change is limited to a single test.
This commit is contained in:
Dmitry Kurochkin 2011-06-28 08:45:09 +04:00 committed by Carl Worth
parent 0417c1fad6
commit 0cc5483a9c
2 changed files with 52 additions and 45 deletions

View file

@ -1,4 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Note: do not use `setq' for setting variables in Emacs tests because
# it affects other tests that may run in the same Emacs instance. Use
# `let' instead so the scope of the changed variables is limited to a
# single test.
test_description="emacs interface" test_description="emacs interface"
. test-lib.sh . test-lib.sh
@ -12,20 +18,20 @@ test_emacs '(notmuch-hello)
test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello
test_begin_subtest "Saved search with 0 results" test_begin_subtest "Saved search with 0 results"
test_emacs '(setq notmuch-show-empty-saved-searches t) test_emacs '(let ((notmuch-show-empty-saved-searches t)
(setq notmuch-saved-searches (notmuch-saved-searches
'\''(("inbox" . "tag:inbox") '\''(("inbox" . "tag:inbox")
("unread" . "tag:unread") ("unread" . "tag:unread")
("empty" . "tag:doesnotexist"))) ("empty" . "tag:doesnotexist"))))
(notmuch-hello) (notmuch-hello)
(test-output)' (test-output))'
test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty
test_begin_subtest "No saved searches displayed (all with 0 results)" test_begin_subtest "No saved searches displayed (all with 0 results)"
test_emacs '(setq notmuch-saved-searches test_emacs '(let ((notmuch-saved-searches
'\''(("empty" . "tag:doesnotexist"))) '\''(("empty" . "tag:doesnotexist"))))
(notmuch-hello) (notmuch-hello)
(test-output)' (test-output))'
test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches
test_begin_subtest "Basic notmuch-search view in emacs" test_begin_subtest "Basic notmuch-search view in emacs"
@ -147,9 +153,9 @@ output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_sear
test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)" test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)"
test_begin_subtest "notmuch-fcc-dirs set to nil" test_begin_subtest "notmuch-fcc-dirs set to nil"
test_emacs "(setq notmuch-fcc-dirs nil) test_emacs "(let ((notmuch-fcc-dirs nil))
(notmuch-mua-mail) (notmuch-mua-mail)
(test-output)" (test-output))"
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org> From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: To:
@ -164,9 +170,9 @@ mkdir -p mail/sent-string/new
mkdir -p mail/sent-string/tmp mkdir -p mail/sent-string/tmp
test_begin_subtest "notmuch-fcc-dirs set to a string" test_begin_subtest "notmuch-fcc-dirs set to a string"
test_emacs "(setq notmuch-fcc-dirs \"sent-string\") test_emacs "(let ((notmuch-fcc-dirs \"sent-string\"))
(notmuch-mua-mail) (notmuch-mua-mail)
(test-output)" (test-output))"
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org> From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: To:
@ -185,11 +191,11 @@ mkdir -p mail/failure/new
mkdir -p mail/failure/tmp mkdir -p mail/failure/tmp
test_begin_subtest "notmuch-fcc-dirs set to a list (with match)" test_begin_subtest "notmuch-fcc-dirs set to a list (with match)"
test_emacs "(setq notmuch-fcc-dirs test_emacs "(let ((notmuch-fcc-dirs
'((\"notmuchmail.org\" . \"sent-list-match\") '((\"notmuchmail.org\" . \"sent-list-match\")
(\".*\" . \"failure\"))) (\".*\" . \"failure\"))))
(notmuch-mua-mail) (notmuch-mua-mail)
(test-output)" (test-output))"
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org> From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: To:
@ -205,11 +211,11 @@ mkdir -p mail/sent-list-catch-all/new
mkdir -p mail/sent-list-catch-all/tmp mkdir -p mail/sent-list-catch-all/tmp
test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)" test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
test_emacs "(setq notmuch-fcc-dirs test_emacs "(let ((notmuch-fcc-dirs
'((\"example.com\" . \"failure\") '((\"example.com\" . \"failure\")
(\".*\" . \"sent-list-catch-all\"))) (\".*\" . \"sent-list-catch-all\"))))
(notmuch-mua-mail) (notmuch-mua-mail)
(test-output)" (test-output))"
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org> From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: To:
@ -220,11 +226,11 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "notmuch-fcc-dirs set to a list (no match)" test_begin_subtest "notmuch-fcc-dirs set to a list (no match)"
test_emacs "(setq notmuch-fcc-dirs test_emacs "(let ((notmuch-fcc-dirs
'((\"example.com\" . \"failure\") '((\"example.com\" . \"failure\")
(\"nomatchhere.net\" . \"failure\"))) (\"nomatchhere.net\" . \"failure\"))))
(notmuch-mua-mail) (notmuch-mua-mail)
(test-output)" (test-output))"
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
From: Notmuch Test Suite <test_suite@notmuchmail.org> From: Notmuch Test Suite <test_suite@notmuchmail.org>
To: To:

View file

@ -394,19 +394,20 @@ emacs_deliver_message ()
mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp} mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
../smtp-dummy sent_message & ../smtp-dummy sent_message &
smtp_dummy_pid=$! smtp_dummy_pid=$!
test_emacs "(setq message-send-mail-function 'message-smtpmail-send-it) test_emacs \
(setq smtpmail-smtp-server \"localhost\") "(let ((message-send-mail-function 'message-smtpmail-send-it)
(setq smtpmail-smtp-service \"25025\") (smtpmail-smtp-server \"localhost\")
(notmuch-hello) (smtpmail-smtp-service \"25025\"))
(notmuch-mua-mail) (notmuch-hello)
(message-goto-to) (notmuch-mua-mail)
(insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\") (message-goto-to)
(message-goto-subject) (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
(insert \"${subject}\") (message-goto-subject)
(message-goto-body) (insert \"${subject}\")
(insert \"${body}\") (message-goto-body)
$@ (insert \"${body}\")
(message-send-and-exit)" >/dev/null 2>&1 $@
(message-send-and-exit))" >/dev/null 2>&1
wait ${smtp_dummy_pid} wait ${smtp_dummy_pid}
notmuch new >/dev/null notmuch new >/dev/null
} }