(setq eshell-current-command command)
(let* ((delim (catch 'eshell-incomplete
(eshell-resume-eval)))
- (val (car-safe delim)))
+ (val (car-safe delim))
+ (val-is-process (or (eshell-processp val)
+ (eshell-process-pair-p val))))
;; If the return value of `eshell-resume-eval' is wrapped in a
;; list, it indicates that the command was run asynchronously.
;; In that case, unwrap the value before checking the delimiter
;; value.
(if (and val
- (not (eshell-processp val))
+ (not val-is-process)
(not (eq val t)))
(error "Unmatched delimiter: %S" val)
;; Eshell-command expect a list like (<process>) to know if the
;; command should be async or not.
- (or (and (eshell-processp val) delim) val)))))
+ (or (and val-is-process delim) val)))))
(defun eshell-resume-command (proc status)
"Resume the current command when a process ends."
(format template "format \"%s\" eshell-in-pipeline-p")
"nil")))
+(ert-deftest eshell-test/eshell-command/simple ()
+ "Test that the `eshell-command' function writes to the current buffer."
+ (skip-unless (executable-find "echo"))
+ (ert-with-temp-directory eshell-directory-name
+ (let ((eshell-history-file-name nil))
+ (with-temp-buffer
+ (eshell-command "*echo hi" t)
+ (should (equal (buffer-string) "hi\n"))))))
+
+(ert-deftest eshell-test/eshell-command/pipeline ()
+ "Test that the `eshell-command' function writes to the current buffer.
+This test uses a pipeline for the command."
+ (skip-unless (and (executable-find "echo")
+ (executable-find "cat")))
+ (ert-with-temp-directory eshell-directory-name
+ (let ((eshell-history-file-name nil))
+ (with-temp-buffer
+ (eshell-command "*echo hi | *cat" t)
+ (should (equal (buffer-string) "hi\n"))))))
+
+(ert-deftest eshell-test/eshell-command/background ()
+ "Test that `eshell-command' works for background commands."
+ (skip-unless (executable-find "echo"))
+ (ert-with-temp-directory eshell-directory-name
+ (let ((eshell-history-file-name nil))
+ ;; XXX: We can't write to the current buffer here, since
+ ;; `eshell-command' will produce an invalid command in that
+ ;; case. Just make sure the command runs and produces an output
+ ;; buffer.
+ (eshell-command "*echo hi &")
+ (with-current-buffer "*Eshell Async Command Output*"
+ (goto-char (point-min))
+ (should (looking-at "\\[echo\\(<[0-9]+>\\)?\\]"))))))
+
+(ert-deftest eshell-test/eshell-command/background-pipeline ()
+ "Test that `eshell-command' works for background commands.
+This test uses a pipeline for the command."
+ (skip-unless (and (executable-find "echo")
+ (executable-find "cat")))
+ (ert-with-temp-directory eshell-directory-name
+ (let ((eshell-history-file-name nil))
+ ;; XXX: As above, we can't write to the current buffer here.
+ (eshell-command "*echo hi | *cat &")
+ (with-current-buffer "*Eshell Async Command Output*"
+ (goto-char (point-min))
+ (should (looking-at "\\[cat\\(<[0-9]+>\\)?\\]"))))))
+
(ert-deftest eshell-test/command-running-p ()
"Modeline should show no command running"
(with-temp-eshell