aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp
diff options
context:
space:
mode:
authorMichael Albinus2020-01-14 11:46:42 +0100
committerMichael Albinus2020-01-14 11:46:42 +0100
commit06caa3b7e5e9fe91b6918f8567adbd5501d6dbdd (patch)
tree8dd6754d32ae7a56e87abd1967252a387071c231 /test/lisp
parent88efc736f562656efab778d35c32d549ef6270d7 (diff)
downloademacs-06caa3b7e5e9fe91b6918f8567adbd5501d6dbdd.tar.gz
emacs-06caa3b7e5e9fe91b6918f8567adbd5501d6dbdd.zip
Refactor Tramp async process code
* lisp/net/tramp-adb.el (tramp-adb-handle-make-process): * lisp/net/tramp-sh.el (tramp-sh-handle-make-process): Update stderr buffer when process has finished. Do not call `auto-revert'. * test/lisp/net/tramp-tests.el (tramp-test31-interrupt-process): Tag it :unstable. Change `accept-process-output' arguments. (tramp--test-async-shell-command): New defun. (tramp--test-shell-command-to-string-asynchronously): Use it. (tramp-test32-shell-command): Refactor code.
Diffstat (limited to 'test/lisp')
-rw-r--r--test/lisp/net/tramp-tests.el146
1 files changed, 58 insertions, 88 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index e2d7e35b52f..549fb70aa92 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4403,7 +4403,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4403 4403
4404(ert-deftest tramp-test31-interrupt-process () 4404(ert-deftest tramp-test31-interrupt-process ()
4405 "Check `interrupt-process'." 4405 "Check `interrupt-process'."
4406 :tags '(:expensive-test) 4406 ;; The test fails from time to time, w/o a reproducible pattern. So
4407 ;; we mark it as unstable.
4408 :tags '(:expensive-test :unstable)
4407 (skip-unless (tramp--test-enabled)) 4409 (skip-unless (tramp--test-enabled))
4408 (skip-unless (tramp--test-sh-p)) 4410 (skip-unless (tramp--test-sh-p))
4409 ;; Since Emacs 26.1. 4411 ;; Since Emacs 26.1.
@@ -4424,7 +4426,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4424 (should (interrupt-process proc)) 4426 (should (interrupt-process proc))
4425 ;; Let the process accept the interrupt. 4427 ;; Let the process accept the interrupt.
4426 (with-timeout (10 (tramp--test-timeout-handler)) 4428 (with-timeout (10 (tramp--test-timeout-handler))
4427 (while (accept-process-output proc nil nil 0))) 4429 (while (process-live-p proc)
4430 (while (accept-process-output proc 0 nil t))))
4428 (should-not (process-live-p proc)) 4431 (should-not (process-live-p proc))
4429 ;; An interrupted process cannot be interrupted, again. 4432 ;; An interrupted process cannot be interrupted, again.
4430 (should-error 4433 (should-error
@@ -4434,14 +4437,27 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4434 ;; Cleanup. 4437 ;; Cleanup.
4435 (ignore-errors (delete-process proc))))) 4438 (ignore-errors (delete-process proc)))))
4436 4439
4440(defun tramp--test-async-shell-command
4441 (command output-buffer &optional error-buffer input)
4442 "Like `async-shell-command', reading the output.
4443INPUT, if non-nil, is a string sent to the process."
4444 (let ((proc (async-shell-command command output-buffer error-buffer)))
4445 (when (stringp input)
4446 (process-send-string proc input))
4447 (with-timeout
4448 ((if (getenv "EMACS_EMBA_CI") 30 10) (tramp--test-timeout-handler))
4449 (while (accept-process-output proc nil nil t))
4450 (should-not (process-live-p proc)))
4451 ;; `ls' could produce colorized output.
4452 (with-current-buffer output-buffer
4453 (goto-char (point-min))
4454 (while (re-search-forward tramp-display-escape-sequence-regexp nil t)
4455 (replace-match "" nil nil)))))
4456
4437(defun tramp--test-shell-command-to-string-asynchronously (command) 4457(defun tramp--test-shell-command-to-string-asynchronously (command)
4438 "Like `shell-command-to-string', but for asynchronous processes." 4458 "Like `shell-command-to-string', but for asynchronous processes."
4439 (with-temp-buffer 4459 (with-temp-buffer
4440 (async-shell-command command (current-buffer)) 4460 (tramp--test-async-shell-command command (current-buffer))
4441 (with-timeout
4442 ((if (getenv "EMACS_EMBA_CI") 30 10) (tramp--test-timeout-handler))
4443 (while (accept-process-output
4444 (get-buffer-process (current-buffer)) nil nil t)))
4445 (buffer-substring-no-properties (point-min) (point-max)))) 4461 (buffer-substring-no-properties (point-min) (point-max))))
4446 4462
4447(ert-deftest tramp-test32-shell-command () 4463(ert-deftest tramp-test32-shell-command ()
@@ -4460,101 +4476,55 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4460 (inhibit-message t) 4476 (inhibit-message t)
4461 kill-buffer-query-functions) 4477 kill-buffer-query-functions)
4462 4478
4463 ;; Test ordinary `shell-command'. 4479 (dolist (this-shell-command
4464 (unwind-protect 4480 '(;; Synchronously.
4465 (with-temp-buffer 4481 shell-command
4466 (write-region "foo" nil tmp-name) 4482 ;; Asynchronously.
4467 (should (file-exists-p tmp-name)) 4483 tramp--test-async-shell-command))
4468 (shell-command
4469 (format "ls %s" (file-name-nondirectory tmp-name))
4470 (current-buffer))
4471 ;; `ls' could produce colorized output.
4472 (goto-char (point-min))
4473 (while
4474 (re-search-forward tramp-display-escape-sequence-regexp nil t)
4475 (replace-match "" nil nil))
4476 (should
4477 (string-equal
4478 (format "%s\n" (file-name-nondirectory tmp-name))
4479 (buffer-string))))
4480
4481 ;; Cleanup.
4482 (ignore-errors (delete-file tmp-name)))
4483 4484
4484 ;; Test `shell-command' with error buffer. 4485 ;; Test ordinary `{async-}shell-command'.
4485 (let ((stderr (generate-new-buffer "*stderr*")))
4486 (unwind-protect 4486 (unwind-protect
4487 (with-temp-buffer 4487 (with-temp-buffer
4488 (shell-command "cat /" (current-buffer) stderr) 4488 (write-region "foo" nil tmp-name)
4489 (should (= (point-min) (point-max))) 4489 (should (file-exists-p tmp-name))
4490 (with-current-buffer stderr 4490 (funcall
4491 (should 4491 this-shell-command
4492 (string-match "cat:.* Is a directory" (buffer-string))))) 4492 (format "ls %s" (file-name-nondirectory tmp-name))
4493 (current-buffer))
4494 (should
4495 (string-equal
4496 (format "%s\n" (file-name-nondirectory tmp-name))
4497 (buffer-string))))
4493 4498
4494 ;; Cleanup. 4499 ;; Cleanup.
4495 (ignore-errors (kill-buffer stderr)))) 4500 (ignore-errors (delete-file tmp-name)))
4496
4497 ;; Test ordinary `async-shell-command'.
4498 (unwind-protect
4499 (with-temp-buffer
4500 (write-region "foo" nil tmp-name)
4501 (should (file-exists-p tmp-name))
4502 (async-shell-command
4503 (format "ls %s" (file-name-nondirectory tmp-name))
4504 (current-buffer))
4505 ;; Read output.
4506 (with-timeout (10 (tramp--test-timeout-handler))
4507 (while (accept-process-output
4508 (get-buffer-process (current-buffer)) nil nil t)))
4509 ;; `ls' could produce colorized output.
4510 (goto-char (point-min))
4511 (while
4512 (re-search-forward tramp-display-escape-sequence-regexp nil t)
4513 (replace-match "" nil nil))
4514 (should
4515 (string-equal
4516 (format "%s\n" (file-name-nondirectory tmp-name))
4517 (buffer-string))))
4518
4519 ;; Cleanup.
4520 (ignore-errors (delete-file tmp-name)))
4521 4501
4522 ;; Test `async-shell-command' with error buffer. 4502 ;; Test `{async-}shell-command' with error buffer.
4523 (let ((stderr (generate-new-buffer "*stderr*")) proc) 4503 (let ((stderr (generate-new-buffer "*stderr*")))
4524 (unwind-protect 4504 (unwind-protect
4525 (with-temp-buffer 4505 (with-temp-buffer
4526 (async-shell-command "cat /; sleep 1" (current-buffer) stderr) 4506 (funcall
4527 (setq proc (get-buffer-process (current-buffer))) 4507 this-shell-command "cat /; sleep 1" (current-buffer) stderr)
4528 ;; Read stderr. 4508 ;; Check stderr.
4529 (when (processp proc) 4509 (when (eq this-shell-command #'tramp--test-async-shell-command)
4530 (with-timeout (10 (tramp--test-timeout-handler)) 4510 (ignore-errors
4531 (while (accept-process-output proc nil nil t))) 4511 (delete-process (get-buffer-process (current-buffer)))))
4532 (delete-process proc)) 4512 (should (zerop (buffer-size)))
4533 (with-current-buffer stderr 4513 (with-current-buffer stderr
4534 (should 4514 (should
4535 (string-match "cat:.* Is a directory" (buffer-string))))) 4515 (string-match "cat:.* Is a directory" (buffer-string)))))
4536 4516
4537 ;; Cleanup. 4517 ;; Cleanup.
4538 (ignore-errors (kill-buffer stderr)))) 4518 (ignore-errors (kill-buffer stderr)))))
4539 4519
4540 ;; Test sending string to `async-shell-command'. 4520 ;; Test sending string to `async-shell-command'.
4541 (unwind-protect 4521 (unwind-protect
4542 (with-temp-buffer 4522 (with-temp-buffer
4543 (write-region "foo" nil tmp-name) 4523 (write-region "foo" nil tmp-name)
4544 (should (file-exists-p tmp-name)) 4524 (should (file-exists-p tmp-name))
4545 (async-shell-command "read line; ls $line" (current-buffer)) 4525 (tramp--test-async-shell-command
4546 (process-send-string 4526 "read line; ls $line" (current-buffer) nil
4547 (get-buffer-process (current-buffer))
4548 (format "%s\n" (file-name-nondirectory tmp-name))) 4527 (format "%s\n" (file-name-nondirectory tmp-name)))
4549 ;; Read output.
4550 (with-timeout (10 (tramp--test-timeout-handler))
4551 (while (accept-process-output
4552 (get-buffer-process (current-buffer)) nil nil t)))
4553 ;; `ls' could produce colorized output.
4554 (goto-char (point-min))
4555 (while
4556 (re-search-forward tramp-display-escape-sequence-regexp nil t)
4557 (replace-match "" nil nil))
4558 (should 4528 (should
4559 (string-equal 4529 (string-equal
4560 ;; tramp-adb.el echoes, so we must add the string. 4530 ;; tramp-adb.el echoes, so we must add the string.
@@ -6239,7 +6209,7 @@ If INTERACTIVE is non-nil, the tests are run interactively."
6239;; do not work properly for `nextcloud'. 6209;; do not work properly for `nextcloud'.
6240;; * Fix `tramp-test29-start-file-process' and 6210;; * Fix `tramp-test29-start-file-process' and
6241;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?). 6211;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?).
6242;; * Implement `tramp-test31-interrupt-process' for `adb'. 6212;; * Implement `tramp-test31-interrupt-process' for `adb'. Fix `:unstable'.
6243;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'. A remote 6213;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'. A remote
6244;; file name operation cannot run in the timer. Remove `:unstable' tag? 6214;; file name operation cannot run in the timer. Remove `:unstable' tag?
6245 6215