From b0283696aad40cc00d2516748c368da75f5dd6dd Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Wed, 28 Aug 2024 18:53:03 -0700 Subject: [PATCH] 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). (cherry picked from commit e269cf63a67d529740d0ec2382ae7c3a982cd064) --- lisp/eshell/em-script.el | 2 +- lisp/eshell/esh-io.el | 2 +- lisp/eshell/eshell.el | 2 +- test/lisp/eshell/em-script-tests.el | 10 ++++++++++ test/lisp/eshell/eshell-tests.el | 6 ++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lisp/eshell/em-script.el b/lisp/eshell/em-script.el index 8cdaa994cc5..03d9a88e32e 100644 --- a/lisp/eshell/em-script.el +++ b/lisp/eshell/em-script.el @@ -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)))) diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index a6df75e86e9..0fcba9b1474 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el @@ -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))) diff --git a/lisp/eshell/eshell.el b/lisp/eshell/eshell.el index 41e0348f3cd..fc08734d5f3 100644 --- a/lisp/eshell/eshell.el +++ b/lisp/eshell/eshell.el @@ -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)) diff --git a/test/lisp/eshell/em-script-tests.el b/test/lisp/eshell/em-script-tests.el index b9f96fa86db..5e5eb80f215 100644 --- a/test/lisp/eshell/em-script-tests.el +++ b/test/lisp/eshell/em-script-tests.el @@ -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 diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index c84af62fdbd..e5aeee5123e 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -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 -- 2.39.5