diff options
Diffstat (limited to 'test/lisp/eshell/esh-proc-tests.el')
-rw-r--r-- | test/lisp/eshell/esh-proc-tests.el | 111 |
1 files changed, 84 insertions, 27 deletions
diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el index 7d0432dbe68..9118bcd1c61 100644 --- a/test/lisp/eshell/esh-proc-tests.el +++ b/test/lisp/eshell/esh-proc-tests.el @@ -86,7 +86,7 @@ "\\`\\'")) (should (equal (buffer-string) "stdout\nstderr\n")))) -(ert-deftest esh-var-test/output/remote-redirect () +(ert-deftest esh-proc-test/output/remote-redirect () "Check that redirecting stdout for a remote process works." (skip-unless (and (eshell-tests-remote-accessible-p) (executable-find "echo"))) @@ -137,18 +137,19 @@ (skip-unless (and (executable-find "sh") (executable-find "echo") (executable-find "sleep"))) - (with-temp-eshell - (eshell-match-command-output - ;; The first command is like `yes' but slower. This is to prevent - ;; it from taxing Emacs's process filter too much and causing a - ;; hang. Note that we use "|&" to connect the processes so that - ;; Emacs doesn't create an extra pipe process for the first "sh" - ;; invocation. - (concat "sh -c 'while true; do echo y; sleep 1; done' |& " - "sh -c 'read NAME; echo ${NAME}'") - "y\n") - (eshell-wait-for-subprocess t) - (should (eq (process-list) nil)))) + (let ((starting-process-list (process-list))) + (with-temp-eshell + (eshell-match-command-output + ;; The first command is like `yes' but slower. This is to prevent + ;; it from taxing Emacs's process filter too much and causing a + ;; hang. Note that we use "|&" to connect the processes so that + ;; Emacs doesn't create an extra pipe process for the first "sh" + ;; invocation. + (concat "sh -c 'while true; do echo y; sleep 1; done' |& " + "sh -c 'read NAME; echo ${NAME}'") + "y\n") + (eshell-wait-for-subprocess t) + (should (equal (process-list) starting-process-list))))) (ert-deftest esh-proc-test/pipeline-connection-type/no-pipeline () "Test that all streams are PTYs when a command is not in a pipeline." @@ -173,23 +174,70 @@ pipeline." (skip-unless (and (executable-find "sh") (executable-find "cat"))) - ;; An `eshell-pipe-broken' signal might occur internally; let Eshell - ;; handle it! - (let ((debug-on-error nil)) - (eshell-command-result-equal - (concat "echo hi | " esh-proc-test--detect-pty-cmd " | cat") - nil))) + (eshell-command-result-equal + (concat "(ignore) | " esh-proc-test--detect-pty-cmd " | cat") + nil)) (ert-deftest esh-proc-test/pipeline-connection-type/last () "Test that only output streams are PTYs when a command ends a pipeline." (skip-unless (executable-find "sh")) - ;; An `eshell-pipe-broken' signal might occur internally; let Eshell - ;; handle it! - (let ((debug-on-error nil)) - (eshell-command-result-equal - (concat "echo hi | " esh-proc-test--detect-pty-cmd) - (unless (eq system-type 'windows-nt) - "stdout\nstderr\n")))) + (eshell-command-result-equal + (concat "(ignore) | " esh-proc-test--detect-pty-cmd) + (unless (eq system-type 'windows-nt) + "stdout\nstderr\n"))) + + +;; Synchronous processes + +;; These tests check that synchronous subprocesses (only used on +;; MS-DOS by default) work correctly. To help them run on MS-DOS as +;; well, we use the Emacs executable as our subprocess to test +;; against; that way, users don't need to have GNU coreutils (or +;; similar) installed. + +(defsubst esh-proc-test/emacs-command (command) + "Evaluate COMMAND in a new Emacs batch instance." + (mapconcat #'shell-quote-argument + `(,(expand-file-name invocation-name invocation-directory) + "-Q" "--batch" "--eval" ,(prin1-to-string command)) + " ")) + +(defvar esh-proc-test/emacs-echo + (esh-proc-test/emacs-command '(princ "hello\n")) + "A command that prints \"hello\" to stdout using Emacs.") + +(defvar esh-proc-test/emacs-upcase + (esh-proc-test/emacs-command + '(princ (upcase (concat (read-string "") "\n")))) + "A command that upcases the text from stdin using Emacs.") + +(ert-deftest esh-proc-test/synchronous-proc/simple/interactive () + "Test that synchronous processes work in an interactive shell." + (let ((eshell-supports-asynchronous-processes nil)) + (with-temp-eshell + (eshell-match-command-output esh-proc-test/emacs-echo + "\\`hello\n")))) + +(ert-deftest esh-proc-test/synchronous-proc/simple/command-result () + "Test that synchronous processes work via `eshell-command-result'." + (let ((eshell-supports-asynchronous-processes nil)) + (eshell-command-result-equal esh-proc-test/emacs-echo + "hello\n"))) + +(ert-deftest esh-proc-test/synchronous-proc/pipeline/interactive () + "Test that synchronous pipelines work in an interactive shell." + (let ((eshell-supports-asynchronous-processes nil)) + (with-temp-eshell + (eshell-match-command-output (concat esh-proc-test/emacs-echo " | " + esh-proc-test/emacs-upcase) + "\\`HELLO\n")))) + +(ert-deftest esh-proc-test/synchronous-proc/pipeline/command-result () + "Test that synchronous pipelines work via `eshell-command-result'." + (let ((eshell-supports-asynchronous-processes nil)) + (eshell-command-result-equal (concat esh-proc-test/emacs-echo " | " + esh-proc-test/emacs-upcase) + "HELLO\n"))) ;; Killing processes @@ -228,7 +276,7 @@ prompt. See bug#54136." (executable-find "sleep"))) ;; This test doesn't work on EMBA with AOT nativecomp, but works ;; fine elsewhere. - (skip-unless (not (getenv "EMACS_EMBA_CI"))) + (skip-when (getenv "EMACS_EMBA_CI")) (with-temp-eshell (eshell-insert-command (concat "sh -c 'while true; do echo y; sleep 1; done' | " @@ -259,6 +307,15 @@ write the exit status to the pipe. See bug#54136." output-start (eshell-end-of-output)) ""))))) +(ert-deftest esh-proc-test/kill-process/redirect-message () + "Test that killing a process with a redirected stderr omits the exit status." + (skip-unless (executable-find "sleep")) + (eshell-with-temp-buffer bufname "" + (with-temp-eshell + (eshell-insert-command (format "sleep 100 2> #<buffer %s>" bufname)) + (kill-process (eshell-head-process))) + (should (equal (buffer-string) "")))) + ;; Remote processes |