summaryrefslogtreecommitdiff
path: root/test/lisp
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2022-01-20 14:37:54 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-01-20 14:37:54 +0100
commit4450c8bdd93d1b2e7f276e26be2cc37372034c22 (patch)
treee45604026d24ea26a1bb7ec342cc6d72edbce505 /test/lisp
parent55c1670bc52c924d80c72e55bf3864023749be29 (diff)
downloademacs-4450c8bdd93d1b2e7f276e26be2cc37372034c22.tar.gz
emacs-4450c8bdd93d1b2e7f276e26be2cc37372034c22.tar.bz2
emacs-4450c8bdd93d1b2e7f276e26be2cc37372034c22.zip
Consider subcommands when deciding to invoke Eshell command directly
When an Eshell command contains an asynchronous subcommand (such as calling an external process), it must be evaluated iteratively. See bug#30725. * lisp/eshell/esh-cmd.el (eshell-invoke-command): Move most of the logic from here... (eshell--invoke-command-directly): ... to here. Also add checks for subcommands. * test/lisp/eshell/eshell-tests.el (eshell-test--max-subprocess-time): New variable. (eshell-wait-for-subprocess): New function. (eshell-command-result-p): Use 'eshell-wait-for-subprocess'. (eshell-test/interp-cmd-external): New test (bug#30725).
Diffstat (limited to 'test/lisp')
-rw-r--r--test/lisp/eshell/eshell-tests.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index aef14479078..c4cb9bf4850 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -30,6 +30,10 @@
(require 'esh-mode)
(require 'eshell)
+(defvar eshell-test--max-subprocess-time 5
+ "The maximum amount of time to wait for a subprocess to finish, in seconds.
+See `eshell-wait-for-subprocess'.")
+
(defmacro with-temp-eshell (&rest body)
"Evaluate BODY in a temporary Eshell buffer."
`(ert-with-temp-directory eshell-directory-name
@@ -44,6 +48,17 @@
(let (kill-buffer-query-functions)
(kill-buffer eshell-buffer))))))
+(defun eshell-wait-for-subprocess ()
+ "Wait until there is no interactive subprocess running in Eshell.
+If this takes longer than `eshell-test--max-subprocess-time',
+raise an error."
+ (let ((start (current-time)))
+ (while (eshell-interactive-process)
+ (when (> (float-time (time-since start))
+ eshell-test--max-subprocess-time)
+ (error "timed out waiting for subprocess"))
+ (sit-for 0.1))))
+
(defun eshell-insert-command (text &optional func)
"Insert a command at the end of the buffer."
(goto-char eshell-last-output-end)
@@ -59,6 +74,7 @@
(defun eshell-command-result-p (text regexp &optional func)
"Insert a command at the end of the buffer."
(eshell-insert-command text func)
+ (eshell-wait-for-subprocess)
(eshell-match-result regexp))
(defvar eshell-history-file-name)
@@ -144,6 +160,13 @@ e.g. \"{(+ 1 2)} 3\" => 3"
"Interpolate and concat two Lisp forms"
(should (equal (eshell-test-command-result "+ $(+ 1 2)$(+ 1 2) 3") 36)))
+(ert-deftest eshell-test/interp-cmd-external ()
+ "Interpolate command result from external command"
+ (skip-unless (executable-find "echo"))
+ (with-temp-eshell
+ (eshell-command-result-p "echo ${*echo hi}"
+ "hi\n")))
+
(ert-deftest eshell-test/window-height ()
"$LINES should equal (window-height)"
(should (eshell-test-command-result "= $LINES (window-height)")))