Fix redirecting Eshell output to symbols in some places

* lisp/eshell/esh-io.el (eshell-output-object-to-target): Don't require
TARGET to be bound.

* lisp/eshell/em-script.el (eshell-execute-file):
* lisp/eshell/eshell.el (eshell-command): Quote the output/error
targets.

* test/lisp/eshell/em-script-tests.el (eshell-execute-file-output): New
variable.
(em-script-test/execute-file/output-symbol): New test.

* test/lisp/eshell/eshell-tests.el (eshell-command-output): New
variable.
(eshell-test/eshell-command/output-symbol): New test (bug#72857).
This commit is contained in:
Jim Porter 2024-08-28 18:53:03 -07:00
parent 5c68545a93
commit e269cf63a6
5 changed files with 19 additions and 3 deletions

View file

@ -128,7 +128,7 @@ Comments begin with `#'."
(with-temp-buffer
(eshell-mode)
(eshell-do-eval
`(eshell-with-handles (,stdout 'insert ,stderr 'insert)
`(eshell-with-handles (',stdout 'insert ',stderr 'insert)
(let ((eshell-current-subjob-p))
,(eshell--source-file file args)))
t))))

View file

@ -711,7 +711,7 @@ Returns what was actually sent, or nil if nothing was sent.")
(cl-defmethod eshell-output-object-to-target (object (target symbol))
"Output OBJECT to the value of the symbol TARGET."
(if (not (symbol-value target))
(if (not (and (boundp target) (symbol-value target)))
(set target object)
(setq object (eshell-stringify object))
(if (not (stringp (symbol-value target)))

View file

@ -354,7 +354,7 @@ buffer is already taken by another running shell command."
(eshell-non-interactive-p t))
(eshell-mode)
(let* ((proc (eshell-eval-command
`(eshell-with-handles (,stdout 'insert ,stderr 'insert)
`(eshell-with-handles (',stdout 'insert ',stderr 'insert)
(let ((eshell-current-subjob-p))
,(eshell-parse-command command)))
command))

View file

@ -33,6 +33,9 @@
(expand-file-name "eshell-tests-helpers"
(file-name-directory (or load-file-name
default-directory))))
(defvar eshell-execute-file-output)
;;; Tests:
(ert-deftest em-script-test/source-script ()
@ -121,6 +124,13 @@
(eshell-execute-file temp-file nil output-file))
(should (equal (eshell-test-file-string output-file) "moreinitial")))))
(ert-deftest em-script-test/execute-file/output-symbol ()
"Test `eshell-execute-file' redirecting to a symbol."
(ert-with-temp-file temp-file :text "echo hi\necho bye"
(with-temp-eshell-settings
(eshell-execute-file temp-file nil 'eshell-execute-file-output))
(should (equal eshell-execute-file-output "hibye"))))
(ert-deftest em-script-test/batch-file ()
"Test running an Eshell script file as a batch script."
(ert-with-temp-file temp-file

View file

@ -35,6 +35,7 @@
default-directory))))
(defvar eshell-test-value nil)
(defvar eshell-command-output)
;;; Tests:
@ -144,6 +145,11 @@ This test uses a pipeline for the command."
(eshell-command "echo more" temp-file)
(should (equal (eshell-test-file-string temp-file) "moreinitial"))))
(ert-deftest eshell-test/eshell-command/output-symbol ()
"Test that `eshell-command' can write to a symbol."
(eshell-command "echo hi" 'eshell-command-output)
(should (equal eshell-command-output "hi")))
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
(with-temp-eshell