]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Eshell call to 'string-suffix-p' when checking for trailing newline
authorJim Porter <jporterbugs@gmail.com>
Mon, 21 Jul 2025 04:17:05 +0000 (21:17 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Jul 2025 13:40:01 +0000 (15:40 +0200)
* lisp/eshell/esh-io.el (eshell--output-maybe-n): Fix call.

* test/lisp/eshell/esh-io-tests.el
(esh-io-test/output-newline/add-newline)
(esh-io-test/output-newline/no-newline)
(esh-io-test/output-newline/no-extra-newline): New tests (bug#79063).

(cherry picked from commit dd29b0ab66d63b3b8e890c8de8f8e5c3fb44217a)

lisp/eshell/esh-io.el
test/lisp/eshell/esh-io-tests.el

index 965b78f4bbc5d5dc68f1875d455fbc7f50889de2..0aec5cae7e2e86e6c452c62999d4c5b686ff812c 100644 (file)
@@ -568,7 +568,7 @@ ends in a newline."
   (eshell-output-object object handle)
   (when (and eshell-ensure-newline-p
              (not (and (stringp object)
-                       (string-suffix-p object "\n"))))
+                       (string-suffix-p "\n" object))))
     (eshell-maybe-output-newline handle)))
 
 (defsubst eshell-print-maybe-n (object)
index d95b52297c738a2c375845a1f580c3856f0568d6..87fc32390d29edc7fb51556f444687173f7cee0f 100644 (file)
 
 ;;; Tests:
 
+\f
+;; Newlines
+
+(ert-deftest esh-io-test/output-newline/add-newline ()
+  "Ensure we add a newline when writing a string to stdout."
+  (with-temp-eshell
+    (eshell-match-command-output "(concat \"hello\")" "\\`hello\n\\'")))
+
+(ert-deftest esh-io-test/output-newline/no-newline ()
+  "Ensure we don't add a newline when writing a string to a buffer."
+  (eshell-with-temp-buffer bufname ""
+    (with-temp-eshell
+      (eshell-match-command-output
+       (format "(concat \"hello\") > #<%s>" bufname)
+       "\\`\\'"))
+    (should (equal (buffer-string) "hello"))))
+
+(ert-deftest esh-io-test/output-newline/no-extra-newline ()
+  "Ensure we don't add an extra newline when writing to stdout."
+  (with-temp-eshell
+    (eshell-match-command-output "(concat \"hello\n\")" "\\`hello\n\\'")))
+
 \f
 ;; Basic redirection