Simple version of the `notmuch-hello' test, some tests of the matrix reflection code and the 're:' stripping code. --- emacs/notmuch-test.el | 62 +++++++++++++++++++++++++++++++-- test/emacs-ert | 3 ++ test/emacs.expected-output/emacs-ert | 20 ++++++---- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/emacs/notmuch-test.el b/emacs/notmuch-test.el index ac6e5a7..7d76537 100644 --- a/emacs/notmuch-test.el +++ b/emacs/notmuch-test.el @@ -23,6 +23,23 @@ ;; +(defun notmuch-test-file-as-string (filename) + (with-temp-buffer + (insert-file-contents filename) + (buffer-string))) + +;; This tends not to work well except in batch mode. +(defun notmuch-test-expected-result (name) + "Get the expected result of a test as a string." + (notmuch-test-file-as-string + (concat (getenv "EXPECTED") "/" name))) + +(defun notmuch-test-buffer-result (fn) + (funcall fn) + (buffer-substring-no-properties (point-min) (point-max))) + +;; + (require 'notmuch-maildir-fcc) (ert-deftest notmuch-fcc-trivial () @@ -85,12 +102,49 @@ ;; -(defun notmuch-test () - "Run the notmuch ERT tests." - (interactive) +(require 'notmuch-hello) + +(ert-deftest notmuch-hello () + "Check that `notmuch-hello' outputs correct data. + +Presumes that the email corpus is already present." + + (should (string= (notmuch-test-buffer-result 'notmuch-hello) + (notmuch-test-expected-result "notmuch-hello")))) + +(ert-deftest notmuch-hello-reflect () + (should (equal '(1 4 7 10 2 5 8 11 3 6 9 12) + (notmuch-hello-reflect '(1 2 3 4 5 6 7 8 9 10 11 12) 4))) + + (should (equal '(1 4 7 10 2 5 8 nil 3 6 9 nil) + (notmuch-hello-reflect '(1 2 3 4 5 6 7 8 9 10) 4)))) + +;; + +(require 'notmuch-show) + +(ert-deftest notmuch-show-strip-re () + (mapc '(lambda (test) + (should (string= "fish" + (notmuch-show-strip-re test)))) + '("fish" "re: fish" "Re: fish" "RE: fish")) - (ert t)) + (mapc '(lambda (test) + (should (string= "some fish" + (notmuch-show-strip-re test)))) + '("some fish" "re: some fish" "some re: fish")) + + (mapc '(lambda (test) + (should-not (string= "some fish" + (notmuch-show-strip-re test)))) + '(" some fish" "re: some fish " "somere: fish" "some fish re:"))) + +;; (defun notmuch-test-batch () "Run the notmuch ERT tests in batch mode." + + ;; Avoid the 10 column default of `emacs --batch'. + (set-frame-width (window-frame (get-buffer-window)) 80) + (ert-run-tests-batch-and-exit)) diff --git a/test/emacs-ert b/test/emacs-ert index 4a45a66..60da9b6 100755 --- a/test/emacs-ert +++ b/test/emacs-ert @@ -3,6 +3,9 @@ test_description="emacs interface (ert)" . test-lib.sh EXPECTED=../emacs.expected-output +export EXPECTED + +add_email_corpus test_begin_subtest "Emacs tests using ert" output=$(emacs \ diff --git a/test/emacs.expected-output/emacs-ert b/test/emacs.expected-output/emacs-ert index 50f592b..3cdf524 100644 --- a/test/emacs.expected-output/emacs-ert +++ b/test/emacs.expected-output/emacs-ert @@ -1,9 +1,13 @@ -Running 6 tests (today) - passed 1/6 notmuch-fcc-multiple - passed 2/6 notmuch-fcc-none - passed 3/6 notmuch-fcc-oldstyle - passed 4/6 notmuch-fcc-regexp - passed 5/6 notmuch-fcc-simple - passed 6/6 notmuch-fcc-trivial +Source file `/one/home/dme/s/notmuch/emacs/notmuch-show.el' newer than byte-compiled file +Running 9 tests (today) + passed 1/9 notmuch-fcc-multiple + passed 2/9 notmuch-fcc-none + passed 3/9 notmuch-fcc-oldstyle + passed 4/9 notmuch-fcc-regexp + passed 5/9 notmuch-fcc-simple + passed 6/9 notmuch-fcc-trivial + passed 7/9 notmuch-hello + passed 8/9 notmuch-hello-reflect + passed 9/9 notmuch-show-strip-re -Ran 6 tests, 6 results as expected (today) +Ran 9 tests, 9 results as expected (today) -- 1.7.2.3