Use 'eshell-with-handles' in a few more places
* 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.
This commit is contained in:
parent
9cd88bd62a
commit
5c68545a93
8 changed files with 32 additions and 25 deletions
|
@ -208,11 +208,9 @@ This is useful after manually editing the contents of the file."
|
|||
"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."
|
||||
|
|
|
@ -175,11 +175,9 @@ top in order to make it into an executable script:
|
|||
(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)
|
||||
|
|
|
@ -901,11 +901,10 @@ This avoids the need to use `let*'."
|
|||
(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
|
||||
;;
|
||||
|
|
|
@ -354,11 +354,9 @@ buffer is already taken by another running shell command."
|
|||
(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
|
||||
|
|
|
@ -113,6 +113,14 @@
|
|||
(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
|
||||
|
|
|
@ -34,12 +34,6 @@
|
|||
(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")
|
||||
|
|
|
@ -139,6 +139,12 @@ After inserting, call FUNC. If FUNC is nil, instead call
|
|||
(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)))
|
||||
|
|
|
@ -138,6 +138,12 @@ This test uses a pipeline for the command."
|
|||
(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
|
||||
|
|
Loading…
Add table
Reference in a new issue