From 7d2870dc856790de343a876611837b38ad6adcff Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 17 Sep 2023 15:42:22 -0700 Subject: [PATCH] Fix running background commands via 'eshell-command' This regressed (I believe) due to 2ec41c174f9. * lisp/eshell/esh-cmd.el (eshell-resume-eval): Check for non-nil 'retval' instead of for a process list (nil is also a technically a process list!). * test/lisp/eshell/eshell-tests.el (eshell-test/eshell-command/background-pipeline): Remove unnecessary 'copy-tree'. (eshell-test/eshell-command/output-buffer/sync) (eshell-test/eshell-command/output-buffer/async): New tests. --- lisp/eshell/esh-cmd.el | 29 ++++++++++++++--------------- test/lisp/eshell/eshell-tests.el | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 23b83521f68..a4542dd917d 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -1009,21 +1009,20 @@ process(es) in a cons cell like: (defun eshell-resume-eval () "Destructively evaluate a form which may need to be deferred." - (eshell-condition-case err - (progn - (setq eshell-last-async-procs nil) - (when eshell-current-command - (let* (retval - (procs (catch 'eshell-defer - (ignore - (setq retval - (eshell-do-eval - eshell-current-command)))))) - (if (eshell-process-list-p procs) - (ignore (setq eshell-last-async-procs procs)) - (cadr retval))))) - (error - (error (error-message-string err))))) + (setq eshell-last-async-procs nil) + (when eshell-current-command + (eshell-condition-case err + (let* (retval + (procs (catch 'eshell-defer + (ignore + (setq retval + (eshell-do-eval + eshell-current-command)))))) + (if retval + (cadr retval) + (ignore (setq eshell-last-async-procs procs)))) + (error + (error (error-message-string err)))))) (defmacro eshell-manipulate (form tag &rest body) "Manipulate a command FORM with BODY, using TAG as a debug identifier." diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index 777c927c78e..37117e865d3 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -75,13 +75,37 @@ 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 ((orig-processes (copy-tree (process-list))) + (let ((orig-processes (process-list)) (eshell-history-file-name nil)) (with-temp-buffer (eshell-command "*echo hi | *cat &" t) (eshell-wait-for (lambda () (equal (process-list) orig-processes))) (should (equal (buffer-string) "hi\n")))))) +(ert-deftest eshell-test/eshell-command/output-buffer/sync () + "Test that the `eshell-command' function writes to its output buffer." + (skip-unless (executable-find "echo")) + (ert-with-temp-directory eshell-directory-name + (let ((orig-processes (process-list)) + (eshell-history-file-name nil)) + (eshell-command "*echo 'hi\nbye'") + (with-current-buffer "*Eshell Command Output*" + (should (equal (buffer-string) "hi\nbye"))) + (kill-buffer "*Eshell Command Output*")))) + +(ert-deftest eshell-test/eshell-command/output-buffer/async () + "Test that the `eshell-command' function writes to its async output buffer." + (skip-unless (executable-find "echo")) + (ert-with-temp-directory eshell-directory-name + (let ((orig-processes (process-list)) + (eshell-history-file-name nil)) + (eshell-command "*echo hi &") + (eshell-wait-for (lambda () (equal (process-list) orig-processes))) + (with-current-buffer "*Eshell Async Command Output*" + (goto-char (point-min)) + (forward-line) + (should (looking-at "hi\n")))))) + (ert-deftest eshell-test/command-running-p () "Modeline should show no command running" (with-temp-eshell -- 2.39.5