unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v1 2/2] test: Add emacs attachment check tests.
Date: Thu,  6 Sep 2018 19:14:56 +0100	[thread overview]
Message-ID: <20180906181456.21719-3-dme@dme.org> (raw)
In-Reply-To: <20180906181456.21719-1-dme@dme.org>

---
 test/T720-emacs-attachment-warnings.sh | 36 ++++++++++++++++++++++++++++++++++
 test/emacs-attachment-test.el          | 25 +++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100755 test/T720-emacs-attachment-warnings.sh
 create mode 100644 test/emacs-attachment-test.el

diff --git a/test/T720-emacs-attachment-warnings.sh b/test/T720-emacs-attachment-warnings.sh
new file mode 100755
index 00000000..19bb2338
--- /dev/null
+++ b/test/T720-emacs-attachment-warnings.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+test_description="emacs attachment warnings"
+. $(dirname "$0")/test-lib.sh || exit 1
+
+declare -a okays=(
+    "nothing to see"
+    "attachment\n<#part filename=foo />"
+    "<#part filename=foo/>"
+)
+
+declare -a not_okays=(
+    "attachment"
+)
+
+echo "okay" > EXPECTED
+for okay in "${okays[@]}"; do
+    test_begin_subtest "Check okay"
+    test_emacs '
+(load-library "emacs-attachment-test.el")
+(single-test "'"$okay"'")
+(test-output)'
+    test_expect_equal_file EXPECTED OUTPUT
+done
+
+echo "not okay!" > EXPECTED
+for not_okay in "${not_okays[@]}"; do
+    test_begin_subtest "Check not_okay"
+    test_emacs '
+(load-library "emacs-attachment-test.el")
+(single-test "'"$not_okay"'")
+(test-output)'
+    test_expect_equal_file EXPECTED OUTPUT
+done
+
+test_done
diff --git a/test/emacs-attachment-test.el b/test/emacs-attachment-test.el
new file mode 100644
index 00000000..604a16e5
--- /dev/null
+++ b/test/emacs-attachment-test.el
@@ -0,0 +1,25 @@
+(defun single-test (bodytext)
+  (set-buffer (get-buffer-create "result"))
+  (delete-region (point-min) (point-max))
+  (insert (save-excursion
+	    (single-test1 bodytext))
+	  "\n"))
+
+(defun single-test1 (bodytext)
+  "Test `notmuch-mua-attachment-check' using a message consisting of BODYTEXT.
+
+Return 'okay' if the message would be sent, otherwise 'not
+okay!'"
+  (notmuch-mua-mail)
+  (message-goto-body)
+  (insert bodytext)
+  (prog1
+      (condition-case detail
+	  ;; Force `y-or-n-p' to always return `nil', as if the user
+	  ;; pressed "n".
+	  (letf (((symbol-function 'y-or-n-p) (lambda (&rest args) nil)))
+	    (notmuch-mua-attachment-check)
+	    "okay")
+	('error "not okay!"))
+    (set-buffer-modified-p nil)
+    (kill-buffer (current-buffer))))
-- 
2.11.0

      parent reply	other threads:[~2018-09-06 18:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-06 18:14 [PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing David Edmondson
2018-09-06 18:14 ` [PATCH v1 1/2] emacs: Optionally check for missing attachments in outgoing messages David Edmondson
2018-09-06 18:14 ` David Edmondson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180906181456.21719-3-dme@dme.org \
    --to=dme@dme.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).