* lisp/eshell/em-alias.el (eshell-write-aliases-list):
* lisp/eshell/em-script.el (eshell-batch-file):
* lisp/eshell/esh-cmd.el (eshell-command-to-value):
* lisp/eshell/eshell.el (eshell-command): Use 'eshell-with-handles'.
* test/lisp/eshell/esh-io-tests.el (eshell-test-file-string): Move to...
* test/lisp/eshell/eshell-tests-helpers.el (eshell-test-file-string):
... here.
* test/lisp/eshell/eshell-tests.el
(eshell-test/eshell-command/output-file):
* test/lisp/eshell/em-script-tests.el
(em-script-test/execute-file/output-file): New tests.
(cherry picked from commit
5c68545a936ab42df90c8498ca77207a5e6aff1f)
"Write out the current aliases into `eshell-aliases-file'."
(when (and eshell-aliases-file
(file-writable-p (file-name-directory eshell-aliases-file)))
- (let ((eshell-current-handles
- (eshell-create-handles eshell-aliases-file 'overwrite)))
+ (eshell-with-handles (eshell-aliases-file 'overwrite)
(eshell/alias)
- (eshell-set-exit-info 0 nil)
- (eshell-close-handles))))
+ (eshell-set-exit-info 0 nil))))
(defsubst eshell-lookup-alias (name)
"Check whether NAME is aliased. Return the alias if there is one."
(with-temp-buffer
(eshell-mode)
(eshell-do-eval
- `(let ((eshell-current-handles
- (eshell-create-handles "/dev/stdout" 'append
- "/dev/stderr" 'append))
- (eshell-current-subjob-p))
- ,(eshell--source-file file args))
+ `(eshell-with-handles ("/dev/stdout" 'append "/dev/stderr" 'append)
+ (let ((eshell-current-subjob-p))
+ ,(eshell--source-file file args)))
t))))
(defun eshell/source (file &rest args)
(defmacro eshell-command-to-value (command)
"Run an Eshell COMMAND synchronously, returning its output."
(let ((value (make-symbol "eshell-temp")))
- `(let ((eshell-in-pipeline-p nil)
- (eshell-current-handles
- (eshell-create-handles ',value 'overwrite)))
- ,command
- ,value)))
+ `(eshell-with-handles (',value 'overwrite)
+ (let ((eshell-in-pipeline-p nil))
+ ,command
+ ,value))))
;;;_* Iterative evaluation
;;
(eshell-non-interactive-p t))
(eshell-mode)
(let* ((proc (eshell-eval-command
- `(let ((eshell-current-handles
- (eshell-create-handles ,stdout 'insert
- ,stderr 'insert))
- (eshell-current-subjob-p))
- ,(eshell-parse-command command))
+ `(eshell-with-handles (,stdout 'insert ,stderr 'insert)
+ (let ((eshell-current-subjob-p))
+ ,(eshell-parse-command command)))
command))
(async (eq (car-safe proc) :eshell-background))
(bufname (cond
(eshell-execute-file temp-file '(1 2 3) t))
(should (equal (buffer-string) "6")))))
+(ert-deftest em-script-test/execute-file/output-file ()
+ "Test `eshell-execute-file' redirecting to a file."
+ (ert-with-temp-file temp-file :text "echo more"
+ (ert-with-temp-file output-file :text "initial"
+ (with-temp-eshell-settings
+ (eshell-execute-file temp-file nil output-file))
+ (should (equal (eshell-test-file-string output-file) "moreinitial")))))
+
(ert-deftest em-script-test/batch-file ()
"Test running an Eshell script file as a batch script."
(ert-with-temp-file temp-file
(defvar eshell-test-value-with-fun nil)
(defun eshell-test-value-with-fun ())
-(defun eshell-test-file-string (file)
- "Return the contents of FILE as a string."
- (with-temp-buffer
- (insert-file-contents file)
- (buffer-string)))
-
(defun eshell/test-output ()
"Write some test output separately to stdout and stderr."
(eshell-printn "stdout")
(buffer-substring-no-properties
(eshell-beginning-of-output) (eshell-end-of-output)))
+(defun eshell-test-file-string (file)
+ "Return the contents of FILE as a string."
+ (with-temp-buffer
+ (insert-file-contents file)
+ (buffer-string)))
+
(defun eshell-match-output (regexp)
"Test whether the output of the last command matches REGEXP."
(string-match-p regexp (eshell-last-output)))
(forward-line)
(should (looking-at "bye\n"))))))
+(ert-deftest eshell-test/eshell-command/output-file ()
+ "Test that `eshell-command' can write to a file."
+ (ert-with-temp-file temp-file :text "initial"
+ (eshell-command "echo more" temp-file)
+ (should (equal (eshell-test-file-string temp-file) "moreinitial"))))
+
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
(with-temp-eshell