* 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)
(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))))
(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)))
(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))
(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 ()
(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
default-directory))))
(defvar eshell-test-value nil)
+(defvar eshell-command-output)
;;; Tests:
(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