aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJim Porter2023-09-23 11:36:11 -0700
committerJim Porter2023-10-02 20:49:41 -0700
commit498d31e9f0549189f4e9b140549419dd4e462575 (patch)
treee66ae54cfe9f53d7481df35850a066042e0b6e1d /test
parent8f2cfe15a72a0c440909faa50a9c436931dcf85e (diff)
downloademacs-498d31e9f0549189f4e9b140549419dd4e462575.tar.gz
emacs-498d31e9f0549189f4e9b140549419dd4e462575.zip
Support Eshell iterative evaluation in the background
This really just generalizes Eshell's previous support for iterative evaluation of a single current command to a list of multiple commands, of which at most one can be in the foreground (bug#66066). * lisp/eshell/esh-cmd.el (eshell-last-async-procs) (eshell-current-command): Make obsolete in favor of... (eshell-foreground-command): ... this (eshell-background-commands): New variable. (eshell-interactive-process-p): Make obsolete. (eshell-head-process, eshell-tail-process): Use 'eshell-foreground-command'. (eshell-cmd-initialize): Initialize new variables. (eshell-add-command, eshell-remove-command) (eshell-commands-for-process): New functions. (eshell-parse-command): Make 'eshell-do-subjob' the outermost call. (eshell-do-subjob): Call 'eshell-resume-eval' to split this command off from its parent forms. (eshell-eval-command): Use 'eshell-add-command'. (eshell-resume-command): Use 'eshell-commands-for-process'. (eshell-resume-eval): Take a COMMAND argument. Return ':eshell-background' form for deferred background commands. (eshell-do-eval): Remove check for 'eshell-current-subjob-p'. This is handled differently now. * lisp/eshell/eshell.el (eshell-command): Wait for all processes to exit when running synchronously. * lisp/eshell/esh-mode.el (eshell-intercept-commands) (eshell-watch-for-password-prompt): * lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): * lisp/eshell/em-smart.el (eshell-smart-display-move): Use 'eshell-foreground-command'. * test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/background/simple-command) (esh-cmd-test/background/subcommand): New tests. (esh-cmd-test/throw): Use 'eshell-foreground-command'. * test/lisp/eshell/eshell-tests.el (eshell-test/queue-input): Use 'eshell-foreground-command'. * test/lisp/eshell/em-script-tests.el (em-script-test/source-script/background): Make the test script more complex. * test/lisp/eshell/eshell-tests.el (eshell-test/eshell-command/pipeline-wait): New test. * doc/misc/eshell.texi (Bugs and ideas): Remove implemented feature.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/eshell/em-script-tests.el4
-rw-r--r--test/lisp/eshell/esh-cmd-tests.el29
-rw-r--r--test/lisp/eshell/eshell-tests.el14
3 files changed, 42 insertions, 5 deletions
diff --git a/test/lisp/eshell/em-script-tests.el b/test/lisp/eshell/em-script-tests.el
index 191755dcc3e..02e4125d827 100644
--- a/test/lisp/eshell/em-script-tests.el
+++ b/test/lisp/eshell/em-script-tests.el
@@ -67,14 +67,14 @@
67 "Test sourcing a script in the background." 67 "Test sourcing a script in the background."
68 (skip-unless (executable-find "echo")) 68 (skip-unless (executable-find "echo"))
69 (ert-with-temp-file temp-file 69 (ert-with-temp-file temp-file
70 :text "*echo hi" 70 :text "*echo hi\nif {[ foo = foo ]} {*echo bye}"
71 (eshell-with-temp-buffer bufname "old" 71 (eshell-with-temp-buffer bufname "old"
72 (with-temp-eshell 72 (with-temp-eshell
73 (eshell-match-command-output 73 (eshell-match-command-output
74 (format "source %s > #<%s> &" temp-file bufname) 74 (format "source %s > #<%s> &" temp-file bufname)
75 "\\`\\'") 75 "\\`\\'")
76 (eshell-wait-for-subprocess t)) 76 (eshell-wait-for-subprocess t))
77 (should (equal (buffer-string) "hi\n"))))) 77 (should (equal (buffer-string) "hi\nbye\n")))))
78 78
79(ert-deftest em-script-test/source-script/arg-vars () 79(ert-deftest em-script-test/source-script/arg-vars ()
80 "Test sourcing script with $0, $1, ... variables." 80 "Test sourcing script with $0, $1, ... variables."
diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el
index 643038f89ff..e0783b26ad6 100644
--- a/test/lisp/eshell/esh-cmd-tests.el
+++ b/test/lisp/eshell/esh-cmd-tests.el
@@ -104,6 +104,32 @@ bug#59469."
104 "value\nexternal\nvalue\n"))) 104 "value\nexternal\nvalue\n")))
105 105
106 106
107;; Background command invocation
108
109(ert-deftest esh-cmd-test/background/simple-command ()
110 "Test invocation with a simple background command."
111 (skip-unless (executable-find "echo"))
112 (eshell-with-temp-buffer bufname ""
113 (with-temp-eshell
114 (eshell-match-command-output
115 (format "*echo hi > #<%s> &" bufname)
116 (rx "[echo" (? ".exe") "] " (+ digit) "\n"))
117 (eshell-wait-for-subprocess t))
118 (should (equal (buffer-string) "hi\n"))))
119
120(ert-deftest esh-cmd-test/background/subcommand ()
121 "Test invocation with a background command containing subcommands."
122 (skip-unless (and (executable-find "echo")
123 (executable-find "rev")))
124 (eshell-with-temp-buffer bufname ""
125 (with-temp-eshell
126 (eshell-match-command-output
127 (format "*echo ${*echo hello | rev} > #<%s> &" bufname)
128 (rx "[echo" (? ".exe") "] " (+ digit) "\n"))
129 (eshell-wait-for-subprocess t))
130 (should (equal (buffer-string) "olleh\n"))))
131
132
107;; Lisp forms 133;; Lisp forms
108 134
109(ert-deftest esh-cmd-test/quoted-lisp-form () 135(ert-deftest esh-cmd-test/quoted-lisp-form ()
@@ -453,8 +479,7 @@ This tests when `eshell-lisp-form-nil-is-failure' is nil."
453 "echo hi; (throw 'tag 42); echo bye")) 479 "echo hi; (throw 'tag 42); echo bye"))
454 42)) 480 42))
455 (should (eshell-match-output "\\`hi\n\\'")) 481 (should (eshell-match-output "\\`hi\n\\'"))
456 (should-not eshell-current-command) 482 (should-not eshell-foreground-command)
457 (should-not eshell-last-async-procs)
458 ;; Make sure we can call another command after throwing. 483 ;; Make sure we can call another command after throwing.
459 (eshell-match-command-output "echo again" "\\`again\n"))) 484 (eshell-match-command-output "echo again" "\\`again\n")))
460 485
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index 25c8cfd389c..b02e5fca592 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -58,6 +58,18 @@ This test uses a pipeline for the command."
58 (eshell-command "*echo hi | *cat" t) 58 (eshell-command "*echo hi | *cat" t)
59 (should (equal (buffer-string) "hi\n")))))) 59 (should (equal (buffer-string) "hi\n"))))))
60 60
61(ert-deftest eshell-test/eshell-command/pipeline-wait ()
62 "Check that `eshell-command' waits for all its processes before returning."
63 (skip-unless (and (executable-find "echo")
64 (executable-find "sh")
65 (executable-find "rev")))
66 (ert-with-temp-directory eshell-directory-name
67 (let ((eshell-history-file-name nil))
68 (with-temp-buffer
69 (eshell-command
70 "*echo hello | sh -c 'sleep 1; rev' 1>&2 | *echo goodbye" t)
71 (should (equal (buffer-string) "goodbye\nolleh\n"))))))
72
61(ert-deftest eshell-test/eshell-command/background () 73(ert-deftest eshell-test/eshell-command/background ()
62 "Test that `eshell-command' works for background commands." 74 "Test that `eshell-command' works for background commands."
63 (skip-unless (executable-find "echo")) 75 (skip-unless (executable-find "echo"))
@@ -132,7 +144,7 @@ insert the queued one at the next prompt, and finally run it."
132 (eshell-insert-command "sleep 1; echo slept") 144 (eshell-insert-command "sleep 1; echo slept")
133 (eshell-insert-command "echo alpha" #'eshell-queue-input) 145 (eshell-insert-command "echo alpha" #'eshell-queue-input)
134 (let ((start (marker-position (eshell-beginning-of-output)))) 146 (let ((start (marker-position (eshell-beginning-of-output))))
135 (eshell-wait-for (lambda () (not eshell-current-command))) 147 (eshell-wait-for (lambda () (not eshell-foreground-command)))
136 (should (string-match "^slept\n.*echo alpha\nalpha\n$" 148 (should (string-match "^slept\n.*echo alpha\nalpha\n$"
137 (buffer-substring-no-properties 149 (buffer-substring-no-properties
138 start (eshell-end-of-output))))))) 150 start (eshell-end-of-output)))))))