From 1dec6548b824c7d4d90ad614040fa6119ebf984a Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 13 May 2022 22:53:16 +0200 Subject: [PATCH] Use ert-with-temp-file in undigest-tests.el * test/lisp/mail/undigest-tests.el (ert-x): Require. (rmail-undigest-test-rfc934-digest) (rmail-undigest-test-rfc1153-digest-strict) (rmail-undigest-test-rfc1153-less-strict-digest) (rmail-undigest-test-rfc1153-sloppy-digest) (rmail-undigest-test-rfc1521-mime-digest) (rmail-undigest-test-multipart-mixed-digest): Use ert-with-temp-file. --- test/lisp/mail/undigest-tests.el | 121 +++++++++++++------------------ 1 file changed, 49 insertions(+), 72 deletions(-) diff --git a/test/lisp/mail/undigest-tests.el b/test/lisp/mail/undigest-tests.el index b88868be7fb..1c473c4996f 100644 --- a/test/lisp/mail/undigest-tests.el +++ b/test/lisp/mail/undigest-tests.el @@ -20,6 +20,7 @@ ;;; Code: (require 'ert) +(require 'ert-x) (require 'rmail) (require 'undigest) @@ -270,66 +271,50 @@ The footer. ;;; Tests: (ert-deftest rmail-undigest-test-rfc934-digest () "Test that we can undigest a RFC 934 digest." - (let ((file (make-temp-file "undigest-test-"))) - (unwind-protect - (with-temp-buffer - (insert rmail-rfc934-digest) - (write-region nil nil file) - (rmail file) - (undigestify-rmail-message) - (should (= rmail-total-messages 4)) - (should (string= (rmail-message-content 2) "Testing the undigester.\n\n")) - (should (string= (rmail-message-content 3) "This is message one.\n\n")) - (should (string= (rmail-message-content 4) "This is message two.\n"))) - (delete-file file)))) + (ert-with-temp-file file + :text rmail-rfc934-digest + (rmail file) + (undigestify-rmail-message) + (should (= rmail-total-messages 4)) + (should (string= (rmail-message-content 2) "Testing the undigester.\n\n")) + (should (string= (rmail-message-content 3) "This is message one.\n\n")) + (should (string= (rmail-message-content 4) "This is message two.\n")))) (ert-deftest rmail-undigest-test-rfc1153-digest-strict () "Test that we can undigest a strict RFC 1153 digest." :expected-result :failed - (let ((file (make-temp-file "undigest-test-"))) - (unwind-protect - (with-temp-buffer - (insert rmail-rfc1153-digest-strict) - (write-region nil nil file) - (rmail file) - (should - (ignore-errors - ;; This throws an error, because the Trailer is not recognized - ;; as a valid RFC 822 (or later) message. - (undigestify-rmail-message) - (should (string= (rmail-message-content 2) "Testing the undigester.\n\n")) - (should (string= (rmail-message-content 3) "This is message one.\n\n")) - (should (string= (rmail-message-content 4) "This is message two.\n")) - t))) - (delete-file file)))) + (ert-with-temp-file file + :text rmail-rfc1153-digest-strict + (rmail file) + (should + (ignore-errors + ;; This throws an error, because the Trailer is not recognized + ;; as a valid RFC 822 (or later) message. + (undigestify-rmail-message) + (should (string= (rmail-message-content 2) "Testing the undigester.\n\n")) + (should (string= (rmail-message-content 3) "This is message one.\n\n")) + (should (string= (rmail-message-content 4) "This is message two.\n")) + t)))) (ert-deftest rmail-undigest-test-rfc1153-less-strict-digest () "Test that we can undigest a RFC 1153 with a Subject header in its footer." - (let ((file (make-temp-file "undigest-test-"))) - (unwind-protect - (with-temp-buffer - (insert rmail-rfc1153-digest-less-strict) - (write-region nil nil file) - (rmail file) - (undigestify-rmail-message) - (should (= rmail-total-messages 5)) - (should (string= (rmail-message-content 3) "This is message one.\n\n")) - (should (string= (rmail-message-content 4) "This is message two.\n\n"))) - (delete-file file)))) + (ert-with-temp-file file + :text rmail-rfc1153-digest-less-strict + (rmail file) + (undigestify-rmail-message) + (should (= rmail-total-messages 5)) + (should (string= (rmail-message-content 3) "This is message one.\n\n")) + (should (string= (rmail-message-content 4) "This is message two.\n\n")))) (ert-deftest rmail-undigest-test-rfc1153-sloppy-digest () "Test that we can undigest a sloppy RFC 1153 digest." - (let ((file (make-temp-file "undigest-test-"))) - (unwind-protect - (with-temp-buffer - (insert rmail-rfc1153-digest-sloppy) - (write-region nil nil file) - (rmail file) - (undigestify-rmail-message) - (should (= rmail-total-messages 5)) - (should (string= (rmail-message-content 3) "This is message one.\n\n")) - (should (string= (rmail-message-content 4) "This is message two.\n\n"))) - (delete-file file)))) + (ert-with-temp-file file + :text rmail-rfc1153-digest-sloppy + (rmail file) + (undigestify-rmail-message) + (should (= rmail-total-messages 5)) + (should (string= (rmail-message-content 3) "This is message one.\n\n")) + (should (string= (rmail-message-content 4) "This is message two.\n\n")))) ;; This fails because `rmail-digest-parse-mime' combines the preamble with the ;; first message of the digest. And then, it doesn't get rid of the last @@ -337,28 +322,20 @@ The footer. (ert-deftest rmail-undigest-test-rfc1521-mime-digest () "Test that we can undigest a RFC 1521 MIME digest." :expected-result :failed - (let ((file (make-temp-file "undigest-test-"))) - (unwind-protect - (with-temp-buffer - (insert rmail-rfc1521-mime-digest) - (write-region nil nil file) - (rmail file) - (undigestify-rmail-message) - (should (= rmail-total-messages 3)) - (should (string= (rmail-message-content 2) "Message one.\n\n")) - (should (string= (rmail-message-content 3) "Message two.\n\n"))) - (delete-file file)))) + (ert-with-temp-file file + :text rmail-rfc1521-mime-digest + (rmail file) + (undigestify-rmail-message) + (should (= rmail-total-messages 3)) + (should (string= (rmail-message-content 2) "Message one.\n\n")) + (should (string= (rmail-message-content 3) "Message two.\n\n")))) (ert-deftest rmail-undigest-test-multipart-mixed-digest () "Test that we can undigest a digest inside a multipart/mixed digest." - (let ((file (make-temp-file "undigest-test-"))) - (unwind-protect - (with-temp-buffer - (insert rmail-multipart-mixed-digest) - (write-region nil nil file) - (rmail file) - (undigestify-rmail-message) - (should (= rmail-total-messages 4)) - (should (string= (rmail-message-content 2) "Message one.\n\n")) - (should (string= (rmail-message-content 3) "Message two.\n\n"))) - (delete-file file)))) + (ert-with-temp-file file + :text rmail-multipart-mixed-digest + (rmail file) + (undigestify-rmail-message) + (should (= rmail-total-messages 4)) + (should (string= (rmail-message-content 2) "Message one.\n\n")) + (should (string= (rmail-message-content 3) "Message two.\n\n")))) -- 2.39.2