(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)
;;; 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