aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Zorman <soliditsallgood@mailbox.org>2023-10-29 08:25:21 +0100
committerDavid Bremner <david@tethera.net>2024-07-25 19:44:49 +0900
commit199e2de224440833d07665e4cf779a88f3d52863 (patch)
tree94167a4a8af2243c5e94753304f6ab8a0afcc3a7
parentfefc7a94740946e9d13a2d25c6170b55c9e075e4 (diff)
test/emacs: test notmuch-mua-subject-check
Amended by db: rename test file to avoid collision.
-rwxr-xr-xtest/T770-emacs-subject-warnings.sh12
-rw-r--r--test/emacs-subject-warnings.el48
2 files changed, 60 insertions, 0 deletions
diff --git a/test/T770-emacs-subject-warnings.sh b/test/T770-emacs-subject-warnings.sh
new file mode 100755
index 00000000..f9d27140
--- /dev/null
+++ b/test/T770-emacs-subject-warnings.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+test_description="emacs subject warnings"
+. $(dirname "$0")/test-lib.sh || exit 1
+. $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
+
+test_require_emacs
+
+test_begin_subtest "notmuch-test-subject-warning part 1"
+test_emacs_expect_t '(notmuch-test-subject-warning-1)'
+
+test_done
diff --git a/test/emacs-subject-warnings.el b/test/emacs-subject-warnings.el
new file mode 100644
index 00000000..1e547429
--- /dev/null
+++ b/test/emacs-subject-warnings.el
@@ -0,0 +1,48 @@
+(require 'cl-lib)
+(require 'notmuch-mua)
+
+(defun subject-check-test (&optional fn)
+ "Test `notmuch-mua-subject-check'.
+Optionally, evaluate FN before doing the test.
+
+Return t if the message would be sent, and nil otherwise."
+ (notmuch-mua-mail)
+ (message-goto-subject)
+ (when fn
+ (funcall fn))
+ (prog1
+ (condition-case nil
+ ;; Force `y-or-n-p' to always return `nil', as if the user
+ ;; pressed "n".
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (&rest args) nil)))
+ (notmuch-mua-subject-check)
+ t)
+ ('error nil))
+ (set-buffer-modified-p nil)
+ (kill-buffer (current-buffer))))
+
+(defvar subject-check-tests
+ '(;; These are okay.
+ (t . (lambda () (insert "something")))
+ ;; These should not be okay.
+ (nil)
+ (nil . (lambda () (insert " ")))
+ (nil . (lambda () (insert " ")))
+ (nil . (lambda () (insert " "))) ; NON-BREAKING SPACE
+ ))
+
+(defun notmuch-test-subject-warning-1 ()
+ (let (output expected)
+ (dolist (test subject-check-tests)
+ (let* ((expect (car test))
+ (body (cdr test))
+ (result (subject-check-test body)))
+ (push expect expected)
+ (push (if (eq result expect)
+ result
+ ;; In the case of a failure, include the test
+ ;; details to make it simpler to debug.
+ (format "%S <-- %S" result body))
+ output)))
+ (notmuch-test-expect-equal output expected)))