From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.devel Subject: Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Date: Mon, 26 Mar 2018 08:57:18 +0200 Message-ID: <878taf1fzl.fsf@mbork.pl> References: <834lo8fqyi.fsf@gnu.org> <20171230103432.GB10623@ACM> <20171230120136.GD10623@ACM> <83shbse5rs.fsf@gnu.org> <20171230130529.GE10623@ACM> <87incjh7ef.fsf@mbork.pl> <20180103162403.GB5435@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1522047380 29129 195.159.176.226 (26 Mar 2018 06:56:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 26 Mar 2018 06:56:20 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: Eli Zaretskii , ccsmile2008@outlook.com, npostavs@gmail.com, emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 26 08:56:16 2018 Return-path: Envelope-to: ged-emacs-devel@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 1f0M3A-0007Mg-Oz for ged-emacs-devel@m.gmane.org; Mon, 26 Mar 2018 08:56:13 +0200 Original-Received: from localhost ([::1]:54916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0M5C-0001Ce-G3 for ged-emacs-devel@m.gmane.org; Mon, 26 Mar 2018 02:58:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0M53-0001CS-MS for emacs-devel@gnu.org; Mon, 26 Mar 2018 02:58:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0M52-0008Jw-Gb for emacs-devel@gnu.org; Mon, 26 Mar 2018 02:58:09 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:34642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0M4y-0008If-J2; Mon, 26 Mar 2018 02:58:04 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 4D70CE6C01; Mon, 26 Mar 2018 08:58:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gNmh1WOiJK0A; Mon, 26 Mar 2018 08:57:55 +0200 (CEST) Original-Received: from localhost (apn-31-2-91-24.dynamic.gprs.plus.pl [31.2.91.24]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 769BDE6B93; Mon, 26 Mar 2018 08:57:55 +0200 (CEST) In-reply-to: <20180103162403.GB5435@ACM> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.110.48.8 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224027 Archived-At: --=-=-= Content-Type: text/plain On 2018-01-03, at 17:24, Alan Mackenzie wrote: > These things are tricky to test properly. ;-) Fair enough. But we should at least try to prepare a regression test when a bug pops its head. ;-) I attach a set of two patches wit such a test. WDYT? Best, -- Marcin Borkowski http://mbork.pl --=-=-= Content-Type: text/x-patch; size=2.61KiB Content-Disposition: attachment; filename=0001-Add-a-more-general-tests-with-temp-buffer-macro.patch >From fb6fa889ec026f2b5d265a043ae5c7e0813aa7c5 Mon Sep 17 00:00:00 2001 From: Marcin Borkowski Date: Tue, 6 Mar 2018 06:46:10 +0100 Subject: [PATCH 1/2] Add a more general "tests-with-temp-buffer" macro --- test/lisp/emacs-lisp/lisp-tests.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index 07eddb74d5..ec197602b6 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -307,12 +307,12 @@ backward-up-list-basic ;;; Helpers (eval-and-compile - (defvar elisp-test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)=" + (defvar test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)=" "A regexp matching placeholders for point position for `elisp-tests-with-temp-buffer'.")) ;; Copied and heavily modified from `python-tests-with-temp-buffer' -(defmacro elisp-tests-with-temp-buffer (contents &rest body) +(defmacro tests-with-temp-buffer (mode contents &rest body) "Create an `emacs-lisp-mode' enabled temp buffer with CONTENTS. BODY is the code to be executed within the temp buffer. Point is always located at the beginning of buffer. CONTENTS is an @@ -320,12 +320,12 @@ elisp-tests-with-temp-buffer of the form =!NAME= in CONTENTS are removed, and a for each one a variable called NAME is bound to the position of the word's start." - (declare (indent 1) (debug (def-form body))) + (declare (indent 2) (debug (def-form body))) (let* ((var-pos nil) (text (with-temp-buffer (insert (eval contents)) (goto-char (point-min)) - (while (re-search-forward elisp-test-point-position-regex nil t) + (while (re-search-forward test-point-position-regex nil t) (push (list (intern (match-string-no-properties 1)) (match-beginning 0)) var-pos) @@ -333,7 +333,7 @@ elisp-tests-with-temp-buffer (match-end 0))) (buffer-string)))) `(with-temp-buffer - (emacs-lisp-mode) + (,mode) (insert ,text) (goto-char (point-min)) (let ,var-pos @@ -341,6 +341,11 @@ elisp-tests-with-temp-buffer ,@(mapcar (lambda (v-p) `(ignore ,(car v-p))) var-pos) ,@body)))) +(defmacro elisp-tests-with-temp-buffer (contents &rest body) + "Use TESTS-WITH-TEMP-BUFFER with Emacs Lisp mode." + (declare (indent 1) (debug (def-form body))) + `(tests-with-temp-buffer emacs-lisp-mode ,contents ,@body)) + ;;; mark-defun (eval-and-compile -- 2.16.2 --=-=-= Content-Type: text/x-patch; size=1.09KiB Content-Disposition: attachment; filename=0002-Add-a-regression-test-for-beginning-of-defun-comment.patch >From 098f49607e19a3246b087afbebb624a3736ef300 Mon Sep 17 00:00:00 2001 From: Marcin Borkowski Date: Mon, 19 Mar 2018 06:17:31 +0100 Subject: [PATCH 2/2] Add a regression test for `beginning-of-defun-comments` --- test/lisp/emacs-lisp/lisp-tests.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index ec197602b6..b456a65737 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -372,6 +372,26 @@ elisp-tests-with-temp-buffer " "Test buffer for `mark-defun'.")) +(ert-deftest mark-defun-c-mode () + "Test `mark-defun` in C mode." + (setq last-command nil) + (tests-with-temp-buffer c-mode + "int test_func1(int a) +{ + int i; + + return 0; +} +=!beg-of-defun=int test_func2(int a) +{ + int i=!inside-2=; + + return 0; +}" + (goto-char inside-2) + (mark-defun) + (should (= (point) beg-of-defun)))) + (ert-deftest mark-defun-no-arg-region-inactive () "Test `mark-defun' with no prefix argument and inactive region." -- 2.16.2 --=-=-=--