summaryrefslogtreecommitdiff
path: root/test/src/process-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/process-tests.el')
-rw-r--r--test/src/process-tests.el112
1 files changed, 112 insertions, 0 deletions
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 7a6762a9226..7745fccaf9d 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -210,5 +210,117 @@
(should-not (process-query-on-exit-flag process))))
(kill-process process)))))
+;; Return t if OUTPUT could have been generated by merging the INPUTS somehow.
+(defun process-tests--mixable (output &rest inputs)
+ (while (and output (let ((ins inputs))
+ (while (and ins (not (eq (car (car ins)) (car output))))
+ (setq ins (cdr ins)))
+ (if ins
+ (setcar ins (cdr (car ins))))
+ ins))
+ (setq output (cdr output)))
+ (not (apply #'append output inputs)))
+
+(ert-deftest make-process/mix-stderr ()
+ "Check that `make-process' mixes the output streams if STDERR is nil."
+ (skip-unless (executable-find "bash"))
+ ;; Frequent random (?) failures on hydra.nixos.org, with no process output.
+ ;; Maybe this test should be tagged unstable? See bug#31214.
+ (skip-unless (not (getenv "EMACS_HYDRA_CI")))
+ (with-temp-buffer
+ (let ((process (make-process
+ :name "mix-stderr"
+ :command (list "bash" "-c"
+ "echo stdout && echo stderr >&2")
+ :buffer (current-buffer)
+ :sentinel #'ignore
+ :noquery t
+ :connection-type 'pipe)))
+ (while (or (accept-process-output process)
+ (process-live-p process)))
+ (should (eq (process-status process) 'exit))
+ (should (eq (process-exit-status process) 0))
+ (should (process-tests--mixable (string-to-list (buffer-string))
+ (string-to-list "stdout\n")
+ (string-to-list "stderr\n"))))))
+
+(ert-deftest make-process-w32-debug-spawn-error ()
+ "Check that debugger runs on `make-process' failure (Bug#33016)."
+ (skip-unless (eq system-type 'windows-nt))
+ (let* ((debug-on-error t)
+ (have-called-debugger nil)
+ (debugger (lambda (&rest _)
+ (setq have-called-debugger t)
+ ;; Allow entering the debugger later in the same
+ ;; test run, before going back to the command
+ ;; loop.
+ (setq internal-when-entered-debugger -1))))
+ (should (eq :got-error ;; NOTE: `should-error' would inhibit debugger.
+ (condition-case-unless-debug ()
+ ;; Emacs doesn't search for absolute filenames, so
+ ;; the error will be hit in the w32 process spawn
+ ;; code.
+ (make-process :name "test" :command '("c:/No-Such-Command"))
+ (error :got-error))))
+ (should have-called-debugger)))
+
+(ert-deftest make-process/file-handler/found ()
+ "Check that the ‘:file-handler’ argument of ‘make-process’
+works as expected if a file name handler is found."
+ (let ((file-handler-calls 0))
+ (cl-flet ((file-handler
+ (&rest args)
+ (should (equal default-directory "test-handler:/dir/"))
+ (should (equal args '(make-process :name "name"
+ :command ("/some/binary")
+ :file-handler t)))
+ (cl-incf file-handler-calls)
+ 'fake-process))
+ (let ((file-name-handler-alist (list (cons (rx bos "test-handler:")
+ #'file-handler)))
+ (default-directory "test-handler:/dir/"))
+ (should (eq (make-process :name "name"
+ :command '("/some/binary")
+ :file-handler t)
+ 'fake-process))
+ (should (= file-handler-calls 1))))))
+
+(ert-deftest make-process/file-handler/not-found ()
+ "Check that the ‘:file-handler’ argument of ‘make-process’
+works as expected if no file name handler is found."
+ (let ((file-name-handler-alist ())
+ (default-directory invocation-directory)
+ (program (expand-file-name invocation-name invocation-directory)))
+ (should (processp (make-process :name "name"
+ :command (list program "--version")
+ :file-handler t)))))
+
+(ert-deftest make-process/file-handler/disable ()
+ "Check ‘make-process’ works as expected if it shouldn’t use the
+file name handler."
+ (let ((file-name-handler-alist (list (cons (rx bos "test-handler:")
+ #'process-tests--file-handler)))
+ (default-directory "test-handler:/dir/")
+ (program (expand-file-name invocation-name invocation-directory)))
+ (should (processp (make-process :name "name"
+ :command (list program "--version"))))))
+
+(defun process-tests--file-handler (operation &rest _args)
+ (cl-ecase operation
+ (unhandled-file-name-directory "/")
+ (make-process (ert-fail "file name handler called unexpectedly"))))
+
+(put #'process-tests--file-handler 'operations
+ '(unhandled-file-name-directory make-process))
+
+(ert-deftest make-process/stop ()
+ "Check that `make-process' doesn't accept a `:stop' key.
+See Bug#30460."
+ (should-error
+ (make-process :name "test"
+ :command (list (expand-file-name invocation-name
+ invocation-directory))
+ :stop t)))
+
(provide 'process-tests)
;; process-tests.el ends here.