aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/eshell/esh-cmd.el8
-rw-r--r--test/lisp/eshell/eshell-tests.el47
2 files changed, 52 insertions, 3 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index f4ac384ccc5..706477a5f45 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1032,18 +1032,20 @@ produced by `eshell-parse-command'."
1032 (setq eshell-current-command command) 1032 (setq eshell-current-command command)
1033 (let* ((delim (catch 'eshell-incomplete 1033 (let* ((delim (catch 'eshell-incomplete
1034 (eshell-resume-eval))) 1034 (eshell-resume-eval)))
1035 (val (car-safe delim))) 1035 (val (car-safe delim))
1036 (val-is-process (or (eshell-processp val)
1037 (eshell-process-pair-p val))))
1036 ;; If the return value of `eshell-resume-eval' is wrapped in a 1038 ;; If the return value of `eshell-resume-eval' is wrapped in a
1037 ;; list, it indicates that the command was run asynchronously. 1039 ;; list, it indicates that the command was run asynchronously.
1038 ;; In that case, unwrap the value before checking the delimiter 1040 ;; In that case, unwrap the value before checking the delimiter
1039 ;; value. 1041 ;; value.
1040 (if (and val 1042 (if (and val
1041 (not (eshell-processp val)) 1043 (not val-is-process)
1042 (not (eq val t))) 1044 (not (eq val t)))
1043 (error "Unmatched delimiter: %S" val) 1045 (error "Unmatched delimiter: %S" val)
1044 ;; Eshell-command expect a list like (<process>) to know if the 1046 ;; Eshell-command expect a list like (<process>) to know if the
1045 ;; command should be async or not. 1047 ;; command should be async or not.
1046 (or (and (eshell-processp val) delim) val))))) 1048 (or (and val-is-process delim) val)))))
1047 1049
1048(defun eshell-resume-command (proc status) 1050(defun eshell-resume-command (proc status)
1049 "Resume the current command when a process ends." 1051 "Resume the current command when a process ends."
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index 3c4a8ec97ea..b57abe3226c 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -105,6 +105,53 @@
105 (format template "format \"%s\" eshell-in-pipeline-p") 105 (format template "format \"%s\" eshell-in-pipeline-p")
106 "nil"))) 106 "nil")))
107 107
108(ert-deftest eshell-test/eshell-command/simple ()
109 "Test that the `eshell-command' function writes to the current buffer."
110 (skip-unless (executable-find "echo"))
111 (ert-with-temp-directory eshell-directory-name
112 (let ((eshell-history-file-name nil))
113 (with-temp-buffer
114 (eshell-command "*echo hi" t)
115 (should (equal (buffer-string) "hi\n"))))))
116
117(ert-deftest eshell-test/eshell-command/pipeline ()
118 "Test that the `eshell-command' function writes to the current buffer.
119This test uses a pipeline for the command."
120 (skip-unless (and (executable-find "echo")
121 (executable-find "cat")))
122 (ert-with-temp-directory eshell-directory-name
123 (let ((eshell-history-file-name nil))
124 (with-temp-buffer
125 (eshell-command "*echo hi | *cat" t)
126 (should (equal (buffer-string) "hi\n"))))))
127
128(ert-deftest eshell-test/eshell-command/background ()
129 "Test that `eshell-command' works for background commands."
130 (skip-unless (executable-find "echo"))
131 (ert-with-temp-directory eshell-directory-name
132 (let ((eshell-history-file-name nil))
133 ;; XXX: We can't write to the current buffer here, since
134 ;; `eshell-command' will produce an invalid command in that
135 ;; case. Just make sure the command runs and produces an output
136 ;; buffer.
137 (eshell-command "*echo hi &")
138 (with-current-buffer "*Eshell Async Command Output*"
139 (goto-char (point-min))
140 (should (looking-at "\\[echo\\(<[0-9]+>\\)?\\]"))))))
141
142(ert-deftest eshell-test/eshell-command/background-pipeline ()
143 "Test that `eshell-command' works for background commands.
144This test uses a pipeline for the command."
145 (skip-unless (and (executable-find "echo")
146 (executable-find "cat")))
147 (ert-with-temp-directory eshell-directory-name
148 (let ((eshell-history-file-name nil))
149 ;; XXX: As above, we can't write to the current buffer here.
150 (eshell-command "*echo hi | *cat &")
151 (with-current-buffer "*Eshell Async Command Output*"
152 (goto-char (point-min))
153 (should (looking-at "\\[cat\\(<[0-9]+>\\)?\\]"))))))
154
108(ert-deftest eshell-test/command-running-p () 155(ert-deftest eshell-test/command-running-p ()
109 "Modeline should show no command running" 156 "Modeline should show no command running"
110 (with-temp-eshell 157 (with-temp-eshell