emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master a9c962be961 5/6: pp-fill: Fix tests breakage


From: Stefan Monnier
Subject: master a9c962be961 5/6: pp-fill: Fix tests breakage
Date: Sat, 17 Jun 2023 18:06:23 -0400 (EDT)

branch: master
commit a9c962be961ae121c4202943879dcf28f3a8364a
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    pp-fill: Fix tests breakage
    
    * lisp/emacs-lisp/pp.el (pp-to-string, pp-buffer, pp): Preserve old
    behavior of (almost always) returning a trailing newline.
    
    * test/lisp/emacs-lisp/pp-tests.el (pp-print-quote): Adjust tests, now
    that `pp-to-string` always returns a trailing newline, rather than only
    most of the time.
    
    * test/lisp/emacs-lisp/backtrace-tests.el
    (backtrace-tests--single-and-multi-line): Make the test less sensitive
    to the choice of what is "pretty".
---
 lisp/emacs-lisp/pp.el                   | 13 +++++++++++--
 test/lisp/emacs-lisp/backtrace-tests.el |  6 +++++-
 test/lisp/emacs-lisp/pp-tests.el        |  4 ++--
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index 88ce5cb3ee8..625fc5f252d 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -142,6 +142,8 @@ Optional argument PP-FUNCTION overrides 
`pp-default-function'."
     (lisp-mode-variables nil)
     (set-syntax-table emacs-lisp-mode-syntax-table)
     (funcall (or pp-function pp-default-function) object)
+    ;; Preserve old behavior of (usually) finishing with a newline.
+    (unless (bolp) (insert "\n"))
     (buffer-string)))
 
 (defun pp--within-fill-column-p ()
@@ -236,7 +238,12 @@ it inserts and pretty-prints that arg at point."
 (defun pp-buffer ()
   "Prettify the current buffer with printed representation of a Lisp object."
   (interactive)
-  (funcall pp-default-function (point-min) (point-max)))
+  (funcall pp-default-function (point-min) (point-max))
+  ;; Preserve old behavior of (usually) finishing with a newline and
+  ;; with point at BOB.
+  (goto-char (point-max))
+  (unless (bolp) (insert "\n"))
+  (goto-char (point-min)))
 
 (defun pp-28 (beg &optional end)        ;FIXME: Better name?
   "Prettify the current region with printed representation of a Lisp object.
@@ -283,7 +290,9 @@ Output stream is STREAM, or value of `standard-output' 
(which see)."
          (eq (syntax-table) emacs-lisp-mode-syntax-table)
          (eq indent-line-function #'lisp-indent-line))
     ;; Skip the buffer->string->buffer middle man.
-    (funcall pp-default-function object))
+    (funcall pp-default-function object)
+    ;; Preserve old behavior of (usually) finishing with a newline.
+    (unless (bolp) (insert "\n")))
    (t
     (princ (pp-to-string object) (or stream standard-output)))))
 
diff --git a/test/lisp/emacs-lisp/backtrace-tests.el 
b/test/lisp/emacs-lisp/backtrace-tests.el
index 794488edae8..e5899446ee4 100644
--- a/test/lisp/emacs-lisp/backtrace-tests.el
+++ b/test/lisp/emacs-lisp/backtrace-tests.el
@@ -226,6 +226,9 @@
   "Forms in backtrace frames can be on a single line or on multiple lines."
   (ert-with-test-buffer (:name "single-multi-line")
     (let* ((arg '(lambda (x)  ; Quote this so it isn't made into a closure.
+                   ;; Make the form long enough so `number' should not
+                   ;; appear on the first line once pretty-printed.
+                   (interactive (region-beginning))
                    (let ((number (1+ x)))
                      (+ x number))))
            (header-string "Test header: ")
@@ -280,7 +283,8 @@ line contains the strings \"lambda\" and \"number\"."
   ;; Verify that the form is now back on one line,
   ;; and that point is at the same place.
   (should (string= (backtrace-tests--get-substring
-                    (- (point) 6) (point)) "number"))
+                    (- (point) 6) (point))
+                   "number"))
   (should-not (= (point) (pos-bol)))
   (should (string= (backtrace-tests--get-substring
                     (pos-bol) (1+ (pos-eol)))
diff --git a/test/lisp/emacs-lisp/pp-tests.el b/test/lisp/emacs-lisp/pp-tests.el
index 72c7cb880d2..1b248e19a31 100644
--- a/test/lisp/emacs-lisp/pp-tests.el
+++ b/test/lisp/emacs-lisp/pp-tests.el
@@ -23,8 +23,8 @@
 (require 'ert-x)
 
 (ert-deftest pp-print-quote ()
-  (should (string= (pp-to-string 'quote) "quote"))
-  (should (string= (pp-to-string ''quote) "'quote"))
+  (should (string= (pp-to-string 'quote) "quote\n"))
+  (should (string= (pp-to-string ''quote) "'quote\n"))
   (should (string= (pp-to-string '('a 'b)) "('a 'b)\n"))
   (should (string= (pp-to-string '(''quote 'quote)) "(''quote 'quote)\n"))
   (should (string= (pp-to-string '(quote)) "(quote)\n"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]