From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Gemini Lasswell Newsgroups: gmane.emacs.bugs Subject: bug#24939: [PATCH] Add tests for lisp/kmacro.el Date: Tue, 29 Nov 2016 12:56:36 -0800 Message-ID: References: <834m3ahxic.fsf@gnu.org> <83vavphpac.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1480453035 6318 195.159.176.226 (29 Nov 2016 20:57:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 29 Nov 2016 20:57:15 +0000 (UTC) Cc: 24939@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 29 21:57:11 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cBpSe-0000Mr-BZ for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Nov 2016 21:57:08 +0100 Original-Received: from localhost ([::1]:39253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cBpSi-0007Ie-6A for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Nov 2016 15:57:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cBpSb-0007IX-PQ for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2016 15:57:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cBpSY-0001mN-Kw for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2016 15:57:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59334) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cBpSY-0001mI-IP for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2016 15:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cBpSY-00081I-Am for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2016 15:57:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Gemini Lasswell Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Nov 2016 20:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24939 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 24939-submit@debbugs.gnu.org id=B24939.148045300430802 (code B ref 24939); Tue, 29 Nov 2016 20:57:02 +0000 Original-Received: (at 24939) by debbugs.gnu.org; 29 Nov 2016 20:56:44 +0000 Original-Received: from localhost ([127.0.0.1]:46500 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cBpSG-00080i-45 for submit@debbugs.gnu.org; Tue, 29 Nov 2016 15:56:44 -0500 Original-Received: from aibo.runbox.com ([91.220.196.211]:40910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cBpSE-00080a-K8 for 24939@debbugs.gnu.org; Tue, 29 Nov 2016 15:56:43 -0500 Original-Received: from [10.9.9.210] (helo=mailfront10.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1cBpSC-0003v2-DK; Tue, 29 Nov 2016 21:56:40 +0100 Original-Received: from c-24-22-244-161.hsd1.wa.comcast.net ([24.22.244.161] helo=rainbow.local) by mailfront10.runbox.com with esmtpsa (uid:179284 ) (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) id 1cBpSB-0001ut-0Y; Tue, 29 Nov 2016 21:56:39 +0100 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:126263 Archived-At: Eli Zaretskii writes: >> >> +(defmacro kmacro-tests-should-match-message (value &rest body) >> > >> > I don't like this implementation. >> >> This strategy is used in autorevert-tests.el and filenotify-tests.el, >> which is where I copied it from. So those should be changed too. > > Most probably. But let's first see what better implementation we > could come up with. > Here is an implementation of message capturing using advice: (defmacro ert-with-message-capture (var &rest body) "Execute BODY while collecting messages in VAR. Capture all messages produced by `message' when it is called from Lisp, and concatenate them separated by newlines into one string." (declare (debug (symbolp body)) (indent 1)) (let ((g-advice (cl-gensym))) `(let* ((,var "") (,g-advice (lambda (func &rest args) (if (or (null args) (equal (car args) "")) (apply func args) (let ((msg (apply #'format-message args))) (setq ,var (concat ,var msg "\n")) (funcall func "%s" msg)))))) (advice-add 'message :around ,g-advice) (unwind-protect (progn ,@body) (advice-remove 'message ,g-advice))))) The reason I have set it up to bind a variable during the code body execution is to make it usable by autorevert-tests.el and filenotify-tests.el. For example, here's an excerpt from filenotify-tests.el: (with-current-buffer (get-buffer-create "*Messages*") (narrow-to-region (point-max) (point-max))) (sleep-for 1) (write-region "another text" nil file-notify--test-tmpfile nil 'no-message) ;; Check, that the buffer has been reverted. (with-current-buffer (get-buffer-create "*Messages*") (file-notify--wait-for-events timeout (string-match (format-message "Reverting buffer `%s'." (buffer-name buf)) (buffer-string)))) file-notify--wait-for-events polls read-event in a loop with a fractional timeout until the form that is its second argument becomes non-nil, or the larger timeout expires. With the macro above, this excerpt becomes: (ert-with-message-capture captured-messages (sleep-for 1) (write-region "another text" nil file-notify--test-tmpfile nil 'no-message) ;; Check, that the buffer has been reverted. (file-notify--wait-for-events timeout (string-match (format-message "Reverting buffer `%s'." (buffer-name buf)) captured-messages))) Let me know what you think.