3 (defun attachment-check-test (&optional fn)
4 "Test `notmuch-mua-attachment-check' using a message where optional FN is evaluated.
6 Return `t' if the message would be sent, otherwise `nil'"
13 ;; Force `y-or-n-p' to always return `nil', as if the user
15 (letf (((symbol-function 'y-or-n-p) (lambda (&rest args) nil)))
16 (notmuch-mua-attachment-check)
19 (set-buffer-modified-p nil)
20 (kill-buffer (current-buffer))))
22 (defvar attachment-check-tests
24 ;; These are all okay:
26 (t . (lambda () (insert "Nothing is a-tt-a-ch-ed!\n")))
28 (insert "Here is an attachment:\n")
29 (insert "<#part filename=\"foo\" />\n")))
30 (t . (lambda () (insert "<#part filename=\"foo\" />\n")))
32 ;; "attachment" is only mentioned in a quoted section.
33 (insert "> I sent you an attachment!\n")
34 ;; Code in `notmuch-mua-attachment-check' avoids matching on
35 ;; "attachment" in a quoted section of the message by looking at
36 ;; fontification properties. For fontification to happen we need to
37 ;; allow some time for redisplay.
40 ;; These should not be okay:
41 (nil . (lambda () (insert "Here is an attachment:\n")))
43 ;; "attachment" is mentioned in both a quoted section and
45 (insert "> I sent you an attachment!\n")
46 (insert "The attachment was missing!\n")
47 ;; Code in `notmuch-mua-attachment-check' avoids matching
48 ;; on "attachment" in a quoted section of the message by
49 ;; looking at fontification properties. For fontification
50 ;; to happen we need to allow some time for redisplay.
54 (defun notmuch-test-attachment-warning-1 ()
55 (let (output expected)
56 (mapcar (lambda (test)
57 (let* ((expect (car test))
59 (result (attachment-check-test body)))
60 (push expect expected)
61 (push (if (eq result expect)
63 ;; In the case of a failure, include the test
64 ;; details to make it simpler to debug.
65 (format "%S <-- %S" result body))
67 attachment-check-tests)
68 (notmuch-test-expect-equal output expected)))