From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Newsgroups: gmane.emacs.bugs Subject: bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime' Date: Sat, 06 May 2017 19:27:48 +0000 Message-ID: References: <83fugvpw24.fsf@gnu.org> <20170429122027.39318-1-phst@google.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1143d6b8eadd1d054ee000eb X-Trace: blaine.gmane.org 1494098970 3685 195.159.176.226 (6 May 2017 19:29:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 May 2017 19:29:30 +0000 (UTC) Cc: Philipp Stephani To: npostavs@users.sourceforge.net, emacs-devel@gnu.org, eliz@gnu.org, 25951-done@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 06 21:29:13 2017 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 1d75OC-0000gb-FF for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 May 2017 21:29:12 +0200 Original-Received: from localhost ([::1]:52468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d75OI-0001dI-1J for geb-bug-gnu-emacs@m.gmane.org; Sat, 06 May 2017 15:29:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d75O6-0001bz-Dw for bug-gnu-emacs@gnu.org; Sat, 06 May 2017 15:29:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d75O3-0002Fz-5c for bug-gnu-emacs@gnu.org; Sat, 06 May 2017 15:29:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60375) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d75O3-0002Ft-1j for bug-gnu-emacs@gnu.org; Sat, 06 May 2017 15:29:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d75O2-0008Nb-QA for bug-gnu-emacs@gnu.org; Sat, 06 May 2017 15:29:02 -0400 Resent-From: Philipp Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 May 2017 19:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 25951 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 25951@debbugs.gnu.org, p.stephani2@gmail.com, p.stephani2@gmail.com Original-Received: via spool by 25951-done@debbugs.gnu.org id=D25951.149409888732142 (code D ref 25951); Sat, 06 May 2017 19:29:02 +0000 Original-Received: (at 25951-done) by debbugs.gnu.org; 6 May 2017 19:28:07 +0000 Original-Received: from localhost ([127.0.0.1]:58570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d75N9-0008MM-5C for submit@debbugs.gnu.org; Sat, 06 May 2017 15:28:07 -0400 Original-Received: from mail-wm0-f52.google.com ([74.125.82.52]:33027) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d75N6-0008Lq-Hx for 25951-done@debbugs.gnu.org; Sat, 06 May 2017 15:28:05 -0400 Original-Received: by mail-wm0-f52.google.com with SMTP id n198so8333133wmg.0 for <25951-done@debbugs.gnu.org>; Sat, 06 May 2017 12:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m/ID9ew0bl8ZM95kXYiBD5f7FNknOssITUqWjGDbQq4=; b=AHyhid+WiGvzfjngTz4fXWqEgBOYYHXlTKd6hOgnyxq5LPzJbaTTQD+DBQ16gvnr5T uw6iPwb/ShOmRYjPPmLUHf8B2ALELZV+FavkVf+JbV94T72ilDQ1yA7osqONeK6kD3iT qwviej+gif7S9uqSPFVMhBY+Ih7WELx4ZDa5WancCp+EItnEe/Jn2C7JXl6kguIdEugI JpOrDtCCPdzBvr4w58aXzyE6dLbA3eUdoay0kPXdOMFSJN27sWfBjbyQt/rQXpu1sPCg WNYg31ErNC6aGP0OV3FCgEHG4qc2+azN9cx1nvhmuYk/yVDOQCLkiZWor8ezQTTYjZ54 BvIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m/ID9ew0bl8ZM95kXYiBD5f7FNknOssITUqWjGDbQq4=; b=LGe+nljuTUB2rMRjyfNZmWkNhOrX5egUDGBkwRthhIThDpBsA5M0s2df7/LtFssGIV NMLrEtSc2JDolb9MVl43cSJbEt8TO/HZoZ7apkSSCg2ZWWa8LZwR0VqkPDabo0VMHecl wiIp0SpCQaEvyk8xNbtMlI2/GTBmxyob/W3/GG2U0iPND0kevzq8hQ9dS939Dn/K/HAm 6OAGpssFXrkLdeeOguHPTUAsudQZpSgaYonFNesZCah7nJokhIL+PzNhb3vOHR2a5TTT VRHjcDv5G0IC9Fk8V5xzy6gpBN6yhcNMWP300T1LPxc11bApAPjY/kb2sCnKRw77yLO1 GPJA== X-Gm-Message-State: AN3rC/5vYNo+ZJ6aCVFn/HTaX3EcPlBnAB7dHuKUV0Pk5p/sZaEpV778 K+HnX4rfSk6la14IfbwVk5Dl3uhjwg== X-Received: by 10.28.55.9 with SMTP id e9mr8355056wma.44.1494098878583; Sat, 06 May 2017 12:27:58 -0700 (PDT) In-Reply-To: <20170429122027.39318-1-phst@google.com> 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:132317 Archived-At: --001a1143d6b8eadd1d054ee000eb Content-Type: text/plain; charset=UTF-8 Philipp Stephani schrieb am Sa., 29. Apr. 2017 um 14:20 Uhr: > Fixes Bug#25951. > > * lisp/files.el (file-name-non-special): Set the file name for the > correct buffer. > > * test/lisp/files-tests.el (files-tests--file-name-non-special--buffers): > Add unit test. > (files-tests--with-advice, files-tests--with-temp-file): New helper > macros. > --- > lisp/files.el | 9 ++++++- > test/lisp/files-tests.el | 64 > +++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 71 insertions(+), 2 deletions(-) > > diff --git a/lisp/files.el b/lisp/files.el > index 6848818cad..2e9ab1aad1 100644 > --- a/lisp/files.el > +++ b/lisp/files.el > @@ -28,6 +28,8 @@ > > ;;; Code: > > +(eval-when-compile (require 'cl-lib)) > + > (defvar font-lock-keywords) > > (defgroup backup nil > @@ -6987,7 +6989,12 @@ file-name-non-special > (when (and visit buffer-file-name) > (setq buffer-file-name (concat "/:" buffer-file-name)))))) > (`unquote-then-quote > - (let ((buffer-file-name (substring buffer-file-name 2))) > + (cl-letf* ((buffer (or (car arguments) (current-buffer))) > + ((buffer-local-value 'buffer-file-name buffer) > + (substring (buffer-file-name buffer) 2))) > + ;; `unquote-then-quote' is only used for the > + ;; `verify-visited-file-modtime' action, which takes a buffer > + ;; as only optional argument. > (apply operation arguments))) > (_ > (apply operation arguments))))) > diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el > index 80bbeb1bc5..4583b1af3c 100644 > --- a/test/lisp/files-tests.el > +++ b/test/lisp/files-tests.el > @@ -1,4 +1,4 @@ > -;;; files-tests.el --- tests for files.el. > +;;; files-tests.el --- tests for files.el. -*- lexical-binding: t; -*- > > ;; Copyright (C) 2012-2017 Free Software Foundation, Inc. > > @@ -20,6 +20,7 @@ > ;;; Code: > > (require 'ert) > +(require 'nadvice) > > ;; Set to t if the local variable was set, `query' if the query was > ;; triggered. > @@ -251,5 +252,66 @@ files-test-bug-18141-file > (start-file-process "foo" nil "true")))) > (should (eq (let ((default-directory "/:/")) (shell-command "true")) > 0))) > > +(defmacro files-tests--with-advice (symbol where function &rest body) > + (declare (indent 3)) > + (cl-check-type symbol symbol) > + (cl-check-type where keyword) > + (cl-check-type function function) > + (macroexp-let2 nil function function > + `(progn > + (advice-add #',symbol ,where ,function) > + (unwind-protect > + (progn ,@body) > + (advice-remove #',symbol ,function))))) > + > +(defmacro files-tests--with-temp-file (name &rest body) > + (declare (indent 1)) > + (cl-check-type name symbol) > + `(let ((,name (make-temp-file "emacs"))) > + (unwind-protect > + (progn ,@body) > + (delete-file ,name)))) > + > +(ert-deftest files-tests--file-name-non-special--buffers () > + "Check that Bug#25951 is fixed. > +We call `verify-visited-file-modtime' on a buffer visiting a file > +with a quoted name. We use two different variants: first with > +the buffer current and a nil argument, second passing the buffer > +object explicitly. In both cases no error should be raised and > +the `file-name-non-special' handler for quoted file names should > +be invoked with the right arguments." > + (files-tests--with-temp-file temp-file-name > + (with-temp-buffer > + (let* ((buffer-visiting-file (current-buffer)) > + (actual-args ()) > + (log (lambda (&rest args) (push args actual-args)))) > + (insert-file-contents (concat "/:" temp-file-name) :visit) > + (should (stringp buffer-file-name)) > + (should (string-prefix-p "/:" buffer-file-name)) > + (should (consp (visited-file-modtime))) > + (should (equal (find-file-name-handler buffer-file-name > + > #'verify-visited-file-modtime) > + #'file-name-non-special)) > + (files-tests--with-advice file-name-non-special :before log > + ;; This should call the file name handler with the right > + ;; buffer and not signal an error. The file hasn't been > + ;; modified, so `verify-visited-file-modtime' should return > + ;; t. > + (should (equal (verify-visited-file-modtime) t)) > + (with-temp-buffer > + (should (stringp (buffer-file-name buffer-visiting-file))) > + ;; This should call the file name handler with the right > + ;; buffer and not signal an error. The file hasn't been > + ;; modified, so `verify-visited-file-modtime' should return > + ;; t. > + (should (equal (verify-visited-file-modtime > buffer-visiting-file) > + t)))) > + ;; Verify that the handler was actually called. We called > + ;; `verify-visited-file-modtime' twice, so both calls should be > + ;; recorded in reverse order. > + (should (equal actual-args > + `((verify-visited-file-modtime > ,buffer-visiting-file) > + (verify-visited-file-modtime nil)))))))) > + > (provide 'files-tests) > ;;; files-tests.el ends here > -- > 2.12.2 > > No further comments, so I've pushed this as 5e47c2e52b. --001a1143d6b8eadd1d054ee000eb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


Philip= p Stephani <p.stephani2@gmail.c= om> schrieb am Sa., 29. Apr. 2017 um 14:20=C2=A0Uhr:
Fixes Bug#25951.

* lisp/files.el (file-name-non-special): Set the file name for the
correct buffer.

* test/lisp/files-tests.el (files-tests--file-name-non-special--buffers): Add unit test.
(files-tests--with-advice, files-tests--with-temp-file): New helper
macros.
---
=C2=A0lisp/files.el=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 ++++= ++-
=C2=A0test/lisp/files-tests.el | 64 +++++++++++++++++++++++++++++++++++++++= ++++++++-
=C2=A02 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 6848818cad..2e9ab1aad1 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -28,6 +28,8 @@

=C2=A0;;; Code:

+(eval-when-compile (require 'cl-lib))
+
=C2=A0(defvar font-lock-keywords)

=C2=A0(defgroup backup nil
@@ -6987,7 +6989,12 @@ file-name-non-special
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (and visit buffer-file-name= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq buffer-file-name (co= ncat "/:" buffer-file-name))))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(`unquote-then-quote
-=C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((buffer-file-name (substring buffer-file-= name 2)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-letf* ((buffer (or (car arguments) (current= -buffer)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((buffer-lo= cal-value 'buffer-file-name buffer)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(subs= tring (buffer-file-name buffer) 2)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; `unquote-then-quote' is only used= for the
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; `verify-visited-file-modtime' act= ion, which takes a buffer
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; as only optional argument.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (apply operation arguments)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(_
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (apply operation arguments)))))
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 80bbeb1bc5..4583b1af3c 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1,4 +1,4 @@
-;;; files-tests.el --- tests for files.el.
+;;; files-tests.el --- tests for files.el.=C2=A0 -*- lexical-binding: t; -= *-

=C2=A0;; Copyright (C) 2012-2017 Free Software Foundation, Inc.

@@ -20,6 +20,7 @@
=C2=A0;;; Code:

=C2=A0(require 'ert)
+(require 'nadvice)

=C2=A0;; Set to t if the local variable was set, `query' if the query w= as
=C2=A0;; triggered.
@@ -251,5 +252,66 @@ files-test-bug-18141-file
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(start-file-process "foo" nil "true"))))
=C2=A0 =C2=A0(should (eq (let ((default-directory "/:/")) (shell-= command "true")) 0)))

+(defmacro files-tests--with-advice (symbol where function &rest body)<= br> +=C2=A0 (declare (indent 3))
+=C2=A0 (cl-check-type symbol symbol)
+=C2=A0 (cl-check-type where keyword)
+=C2=A0 (cl-check-type function function)
+=C2=A0 (macroexp-let2 nil function function
+=C2=A0 =C2=A0 `(progn
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(advice-add #',symbol ,where ,function)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(unwind-protect
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn ,@body)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(advice-remove #',symbol ,function))= )))
+
+(defmacro files-tests--with-temp-file (name &rest body)
+=C2=A0 (declare (indent 1))
+=C2=A0 (cl-check-type name symbol)
+=C2=A0 `(let ((,name (make-temp-file "emacs")))
+=C2=A0 =C2=A0 =C2=A0(unwind-protect
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn ,@body)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-file ,name))))
+
+(ert-deftest files-tests--file-name-non-special--buffers ()
+=C2=A0 "Check that Bug#25951 is fixed.
+We call `verify-visited-file-modtime' on a buffer visiting a file
+with a quoted name.=C2=A0 We use two different variants: first with
+the buffer current and a nil argument, second passing the buffer
+object explicitly.=C2=A0 In both cases no error should be raised and
+the `file-name-non-special' handler for quoted file names should
+be invoked with the right arguments."
+=C2=A0 (files-tests--with-temp-file temp-file-name
+=C2=A0 =C2=A0 (with-temp-buffer
+=C2=A0 =C2=A0 =C2=A0(let* ((buffer-visiting-file (current-buffer))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (actual-args ())
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (log (lambda (&rest args) (p= ush args actual-args))))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(insert-file-contents (concat "/:" te= mp-file-name) :visit)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(should (stringp buffer-file-name))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(should (string-prefix-p "/:" buffer-= file-name))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(should (consp (visited-file-modtime)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(should (equal (find-file-name-handler buffer-f= ile-name
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 #'verify-visited-file-modtime)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 #'file-name-non-special))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(files-tests--with-advice file-name-non-special= :before log
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; This should call the file name handle= r with the right
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; buffer and not signal an error.=C2=A0= The file hasn't been
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; modified, so `verify-visited-file-mod= time' should return
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; t.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(should (equal (verify-visited-file-modt= ime) t))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(with-temp-buffer
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(should (stringp (buffer-file-nam= e buffer-visiting-file)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; This should call the file name= handler with the right
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; buffer and not signal an error= .=C2=A0 The file hasn't been
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; modified, so `verify-visited-f= ile-modtime' should return
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; t.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(should (equal (verify-visited-fi= le-modtime buffer-visiting-file)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 t))))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0;; Verify that the handler was actually called.= =C2=A0 We called
+=C2=A0 =C2=A0 =C2=A0 =C2=A0;; `verify-visited-file-modtime' twice, so = both calls should be
+=C2=A0 =C2=A0 =C2=A0 =C2=A0;; recorded in reverse order.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(should (equal actual-args
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 `((verify-visited-file-modtime ,buffer-visiting-file)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (verify-visited-file-modtime nil))))))))
+
=C2=A0(provide 'files-tests)
=C2=A0;;; files-tests.el ends here
--
2.12.2


No further comments, so I've pushe= d this as 5e47c2e52b.=C2=A0
--001a1143d6b8eadd1d054ee000eb--