From: Jim Porter Date: Mon, 21 Jul 2025 04:17:05 +0000 (-0700) Subject: Fix Eshell call to 'string-suffix-p' when checking for trailing newline X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d5b2fb78f346708d5b80d1db6561fd3d72682f98;p=emacs.git Fix Eshell call to 'string-suffix-p' when checking for trailing newline * 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) --- diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index 965b78f4bbc..0aec5cae7e2 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el @@ -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) diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el index d95b52297c7..87fc32390d2 100644 --- a/test/lisp/eshell/esh-io-tests.el +++ b/test/lisp/eshell/esh-io-tests.el @@ -40,6 +40,28 @@ ;;; Tests: + +;; 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\\'"))) + ;; Basic redirection