diff options
| author | Michael Albinus | 2020-02-01 14:29:45 +0100 |
|---|---|---|
| committer | Michael Albinus | 2020-02-01 14:29:45 +0100 |
| commit | bb1d42b955629487537dee9423d5a4fc837033ae (patch) | |
| tree | 68024f1fbcb916db0b12957aa54d727cf270595b /test | |
| parent | d3ead375092e2690c1d1d6a5dd82e6e89cdf4f4c (diff) | |
| download | emacs-bb1d42b955629487537dee9423d5a4fc837033ae.tar.gz emacs-bb1d42b955629487537dee9423d5a4fc837033ae.zip | |
Implement `shell-command-dont-erase-buffer' in Tramp. (Bug#39067)
* lisp/net/tramp.el (tramp-handle-shell-command):
Handle `shell-command-dont-erase-buffer'. (Bug#39067)
* test/lisp/net/tramp-tests.el (shell-command-dont-erase-buffer):
Declare.
(tramp-test10-write-region, tramp-test21-file-links): Use function
symbols.
(tramp--test-async-shell-command): Don't assume that
`async-shell-command' returns the process object.
(tramp-test32-shell-command): Rework `async-shell-command-width' test.
(tramp-test32-shell-command-dont-erase-buffer): New test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 141 |
1 files changed, 115 insertions, 26 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 7ffd22e77be..89ab493c062 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -72,6 +72,8 @@ | |||
| 72 | (defvar connection-local-profile-alist) | 72 | (defvar connection-local-profile-alist) |
| 73 | ;; Needed for Emacs 26. | 73 | ;; Needed for Emacs 26. |
| 74 | (defvar async-shell-command-width) | 74 | (defvar async-shell-command-width) |
| 75 | ;; Needed for Emacs 27. | ||
| 76 | (defvar shell-command-dont-erase-buffer) | ||
| 75 | 77 | ||
| 76 | ;; Beautify batch mode. | 78 | ;; Beautify batch mode. |
| 77 | (when noninteractive | 79 | (when noninteractive |
| @@ -2389,14 +2391,14 @@ This checks also `file-name-as-directory', `file-name-directory', | |||
| 2389 | tramp--test-messages)))))))) | 2391 | tramp--test-messages)))))))) |
| 2390 | 2392 | ||
| 2391 | ;; Do not overwrite if excluded. | 2393 | ;; Do not overwrite if excluded. |
| 2392 | (cl-letf (((symbol-function 'y-or-n-p) (lambda (_prompt) t)) | 2394 | (cl-letf (((symbol-function #'y-or-n-p) (lambda (_prompt) t)) |
| 2393 | ;; Ange-FTP. | 2395 | ;; Ange-FTP. |
| 2394 | ((symbol-function 'yes-or-no-p) (lambda (_prompt) t))) | 2396 | ((symbol-function 'yes-or-no-p) (lambda (_prompt) t))) |
| 2395 | (write-region "foo" nil tmp-name nil nil nil 'mustbenew)) | 2397 | (write-region "foo" nil tmp-name nil nil nil 'mustbenew)) |
| 2396 | ;; `mustbenew' is passed to Tramp since Emacs 26.1. | 2398 | ;; `mustbenew' is passed to Tramp since Emacs 26.1. |
| 2397 | (when (tramp--test-emacs26-p) | 2399 | (when (tramp--test-emacs26-p) |
| 2398 | (should-error | 2400 | (should-error |
| 2399 | (cl-letf (((symbol-function 'y-or-n-p) 'ignore) | 2401 | (cl-letf (((symbol-function #'y-or-n-p) #'ignore) |
| 2400 | ;; Ange-FTP. | 2402 | ;; Ange-FTP. |
| 2401 | ((symbol-function 'yes-or-no-p) 'ignore)) | 2403 | ((symbol-function 'yes-or-no-p) 'ignore)) |
| 2402 | (write-region "foo" nil tmp-name nil nil nil 'mustbenew)) | 2404 | (write-region "foo" nil tmp-name nil nil nil 'mustbenew)) |
| @@ -3416,11 +3418,11 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3416 | :type 'file-already-exists)) | 3418 | :type 'file-already-exists)) |
| 3417 | (when (tramp--test-expensive-test) | 3419 | (when (tramp--test-expensive-test) |
| 3418 | ;; A number means interactive case. | 3420 | ;; A number means interactive case. |
| 3419 | (cl-letf (((symbol-function 'yes-or-no-p) #'ignore)) | 3421 | (cl-letf (((symbol-function #'yes-or-no-p) #'ignore)) |
| 3420 | (should-error | 3422 | (should-error |
| 3421 | (make-symbolic-link tmp-name1 tmp-name2 0) | 3423 | (make-symbolic-link tmp-name1 tmp-name2 0) |
| 3422 | :type 'file-already-exists))) | 3424 | :type 'file-already-exists))) |
| 3423 | (cl-letf (((symbol-function 'yes-or-no-p) (lambda (_prompt) t))) | 3425 | (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_prompt) t))) |
| 3424 | (make-symbolic-link tmp-name1 tmp-name2 0) | 3426 | (make-symbolic-link tmp-name1 tmp-name2 0) |
| 3425 | (should | 3427 | (should |
| 3426 | (string-equal | 3428 | (string-equal |
| @@ -3492,11 +3494,11 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3492 | (add-name-to-file tmp-name1 tmp-name2) | 3494 | (add-name-to-file tmp-name1 tmp-name2) |
| 3493 | :type 'file-already-exists) | 3495 | :type 'file-already-exists) |
| 3494 | ;; A number means interactive case. | 3496 | ;; A number means interactive case. |
| 3495 | (cl-letf (((symbol-function 'yes-or-no-p) #'ignore)) | 3497 | (cl-letf (((symbol-function #'yes-or-no-p) #'ignore)) |
| 3496 | (should-error | 3498 | (should-error |
| 3497 | (add-name-to-file tmp-name1 tmp-name2 0) | 3499 | (add-name-to-file tmp-name1 tmp-name2 0) |
| 3498 | :type 'file-already-exists)) | 3500 | :type 'file-already-exists)) |
| 3499 | (cl-letf (((symbol-function 'yes-or-no-p) (lambda (_prompt) t))) | 3501 | (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_prompt) t))) |
| 3500 | (add-name-to-file tmp-name1 tmp-name2 0) | 3502 | (add-name-to-file tmp-name1 tmp-name2 0) |
| 3501 | (should (file-regular-p tmp-name2))) | 3503 | (should (file-regular-p tmp-name2))) |
| 3502 | (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists) | 3504 | (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists) |
| @@ -4437,7 +4439,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4437 | (command output-buffer &optional error-buffer input) | 4439 | (command output-buffer &optional error-buffer input) |
| 4438 | "Like `async-shell-command', reading the output. | 4440 | "Like `async-shell-command', reading the output. |
| 4439 | INPUT, if non-nil, is a string sent to the process." | 4441 | INPUT, if non-nil, is a string sent to the process." |
| 4440 | (let ((proc (async-shell-command command output-buffer error-buffer)) | 4442 | (async-shell-command command output-buffer error-buffer) |
| 4443 | (let ((proc (get-buffer-process output-buffer)) | ||
| 4441 | (delete-exited-processes t)) | 4444 | (delete-exited-processes t)) |
| 4442 | (when (stringp input) | 4445 | (when (stringp input) |
| 4443 | (process-send-string proc input)) | 4446 | (process-send-string proc input)) |
| @@ -4532,25 +4535,111 @@ INPUT, if non-nil, is a string sent to the process." | |||
| 4532 | (buffer-string)))) | 4535 | (buffer-string)))) |
| 4533 | 4536 | ||
| 4534 | ;; Cleanup. | 4537 | ;; Cleanup. |
| 4535 | (ignore-errors (delete-file tmp-name))) | 4538 | (ignore-errors (delete-file tmp-name))))) |
| 4536 | 4539 | ||
| 4537 | ;; Test `async-shell-command-width'. Since Emacs 27.1. | 4540 | ;; Test `async-shell-command-width'. It exists since Emacs 26.1, |
| 4538 | (when (ignore-errors | 4541 | ;; but seems to work since Emacs 27.1 only. |
| 4539 | (and (boundp 'async-shell-command-width) | 4542 | (when (and (tramp--test-sh-p) (tramp--test-emacs27-p)) |
| 4540 | (zerop (call-process "tput" nil nil nil "cols")) | 4543 | (let* ((async-shell-command-width 1024) |
| 4541 | (zerop (process-file "tput" nil nil nil "cols")))) | 4544 | (cols (ignore-errors |
| 4542 | (let (async-shell-command-width) | 4545 | (read (tramp--test-shell-command-to-string-asynchronously |
| 4543 | (should | 4546 | "tput cols"))))) |
| 4544 | (string-equal | 4547 | (when (natnump cols) |
| 4545 | (format "%s\n" (car (process-lines "tput" "cols"))) | 4548 | (should (= cols async-shell-command-width)))))) |
| 4546 | (tramp--test-shell-command-to-string-asynchronously | 4549 | |
| 4547 | "tput cols"))) | 4550 | (ert-deftest tramp-test32-shell-command-dont-erase-buffer () |
| 4548 | (setq async-shell-command-width 1024) | 4551 | "Check `shell-command'." |
| 4549 | (should | 4552 | :tags '(:expensive-test) |
| 4550 | (string-equal | 4553 | (skip-unless (tramp--test-enabled)) |
| 4551 | "1024\n" | 4554 | (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p))) |
| 4552 | (tramp--test-shell-command-to-string-asynchronously | 4555 | ;; Prior Emacs 27, `shell-command-dont-erase-buffer' wasn't working properly. |
| 4553 | "tput cols")))))))) | 4556 | (skip-unless (tramp--test-emacs27-p)) |
| 4557 | |||
| 4558 | ;; We check both the local and remote case, in order to guarantee | ||
| 4559 | ;; that they behave similar. | ||
| 4560 | (dolist (default-directory | ||
| 4561 | `(,temporary-file-directory ,tramp-test-temporary-file-directory)) | ||
| 4562 | (let ((buffer (generate-new-buffer "foo")) | ||
| 4563 | ;; Suppress nasty messages. | ||
| 4564 | (inhibit-message t) | ||
| 4565 | point kill-buffer-query-functions) | ||
| 4566 | (unwind-protect | ||
| 4567 | (progn | ||
| 4568 | ;; Don't erase if buffer is the current one. Point is not moved. | ||
| 4569 | (let (shell-command-dont-erase-buffer) | ||
| 4570 | (with-temp-buffer | ||
| 4571 | (insert "bar") | ||
| 4572 | (setq point (point)) | ||
| 4573 | (should (string-equal "bar" (buffer-string))) | ||
| 4574 | (should (= (point) (point-max))) | ||
| 4575 | (shell-command "echo baz" (current-buffer)) | ||
| 4576 | (should (string-equal "barbaz\n" (buffer-string))) | ||
| 4577 | (should (= point (point))))) | ||
| 4578 | |||
| 4579 | ;; Erase if the buffer is not current one. | ||
| 4580 | (let (shell-command-dont-erase-buffer) | ||
| 4581 | (with-current-buffer buffer | ||
| 4582 | (erase-buffer) | ||
| 4583 | (insert "bar") | ||
| 4584 | (setq point (point)) | ||
| 4585 | (should (string-equal "bar" (buffer-string))) | ||
| 4586 | (should (= (point) (point-max))) | ||
| 4587 | (with-temp-buffer | ||
| 4588 | (shell-command "echo baz" buffer)) | ||
| 4589 | (should (string-equal "baz\n" (buffer-string))) | ||
| 4590 | (should (= point (point))))) | ||
| 4591 | |||
| 4592 | ;; Erase if buffer is the current one, but | ||
| 4593 | ;; `shell-command-dont-erase-buffer' is set to `erase'. | ||
| 4594 | (let ((shell-command-dont-erase-buffer 'erase)) | ||
| 4595 | (with-temp-buffer | ||
| 4596 | (insert "bar") | ||
| 4597 | (setq point (point)) | ||
| 4598 | (should (string-equal "bar" (buffer-string))) | ||
| 4599 | (should (= (point) (point-max))) | ||
| 4600 | (shell-command "echo baz" (current-buffer)) | ||
| 4601 | (should (string-equal "baz\n" (buffer-string))) | ||
| 4602 | (should (= (point) (point-max))))) | ||
| 4603 | |||
| 4604 | ;; Don't erase if `shell-command-dont-erase-buffer' is set | ||
| 4605 | ;; to `beg-last-out'. Check point. | ||
| 4606 | (let ((shell-command-dont-erase-buffer 'beg-last-out)) | ||
| 4607 | (with-temp-buffer | ||
| 4608 | (insert "bar") | ||
| 4609 | (setq point (point)) | ||
| 4610 | (should (string-equal "bar" (buffer-string))) | ||
| 4611 | (should (= (point) (point-max))) | ||
| 4612 | (shell-command "echo baz" (current-buffer)) | ||
| 4613 | (should (string-equal "barbaz\n" (buffer-string))) | ||
| 4614 | (should (= point (point))))) | ||
| 4615 | |||
| 4616 | ;; Don't erase if `shell-command-dont-erase-buffer' is set | ||
| 4617 | ;; to `end-last-out'. Check point. | ||
| 4618 | (let ((shell-command-dont-erase-buffer 'end-last-out)) | ||
| 4619 | (with-temp-buffer | ||
| 4620 | (insert "bar") | ||
| 4621 | (setq point (point)) | ||
| 4622 | (should (string-equal "bar" (buffer-string))) | ||
| 4623 | (should (= (point) (point-max))) | ||
| 4624 | (shell-command "echo baz" (current-buffer)) | ||
| 4625 | (should (string-equal "barbaz\n" (buffer-string))) | ||
| 4626 | (should (= (point) (point-max))))) | ||
| 4627 | |||
| 4628 | ;; Don't erase if `shell-command-dont-erase-buffer' is set | ||
| 4629 | ;; to `save-point'. Check point. | ||
| 4630 | (let ((shell-command-dont-erase-buffer 'save-point)) | ||
| 4631 | (with-temp-buffer | ||
| 4632 | (insert "bar") | ||
| 4633 | (goto-char (1- (point-max))) | ||
| 4634 | (setq point (point)) | ||
| 4635 | (should (string-equal "bar" (buffer-string))) | ||
| 4636 | (should (= (point) (1- (point-max)))) | ||
| 4637 | (shell-command "echo baz" (current-buffer)) | ||
| 4638 | (should (string-equal "barbaz\n" (buffer-string))) | ||
| 4639 | (should (= point (point)))))) | ||
| 4640 | |||
| 4641 | ;; Cleanup. | ||
| 4642 | (ignore-errors (kill-buffer buffer)))))) | ||
| 4554 | 4643 | ||
| 4555 | ;; This test is inspired by Bug#23952. | 4644 | ;; This test is inspired by Bug#23952. |
| 4556 | (ert-deftest tramp-test33-environment-variables () | 4645 | (ert-deftest tramp-test33-environment-variables () |