aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2023-02-06 18:13:22 +0100
committerMichael Albinus2023-02-06 18:13:22 +0100
commit907fd1f7ff402f9d226ebb3b891ea5b54fac1d1c (patch)
treeafaec6a6d89c54c5ce5798afd6bf21dffda204a4 /test
parent7f8f19da2492cd11b984c67259bfb645984d9c06 (diff)
downloademacs-907fd1f7ff402f9d226ebb3b891ea5b54fac1d1c.tar.gz
emacs-907fd1f7ff402f9d226ebb3b891ea5b54fac1d1c.zip
Improve Tramp file name completion
This fixes Bug#51386, Bug#52758, Bug#53513, Bug#54042 and Bug#60505. * doc/misc/tramp.texi (File name completion): Remove completion styles restrictions. * lisp/minibuffer.el (completion-styles): Fix docstring. * lisp/net/tramp.el (tramp-methods) <->: Add. (tramp-completion-file-name-handler-alist): Add `expand-file-name', `file-exists-p', `file-name-directory' and `file-name-nondirectory'. (tramp-dissect-file-name): Do not extra check for `tramp-default-method-marker'. (tramp-completion-handle-expand-file-name) (tramp-completion-handle-file-exists-p) (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-nondirectory): New defuns. (tramp-completion-handle-file-name-all-completions): Remove duplicates. * test/lisp/net/tramp-tests.el (tramp-test26-interactive-file-name-completion): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/tramp-tests.el150
1 files changed, 137 insertions, 13 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index cc93970be28..d903ba626b9 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4529,24 +4529,22 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4529 (setq host (match-string 1 host))) 4529 (setq host (match-string 1 host)))
4530 4530
4531 (unwind-protect 4531 (unwind-protect
4532 (dolist 4532 (dolist (syntax (if (tramp--test-expensive-test-p)
4533 (syntax 4533 (tramp-syntax-values) `(,orig-syntax)))
4534 (if (tramp--test-expensive-test-p)
4535 (tramp-syntax-values) `(,orig-syntax)))
4536 (tramp-change-syntax syntax) 4534 (tramp-change-syntax syntax)
4537 ;; This has cleaned up all connection data, which are used 4535 ;; This has cleaned up all connection data, which are used
4538 ;; for completion. We must refill the cache. 4536 ;; for completion. We must refill the cache.
4539 (tramp-set-connection-property tramp-test-vec "property" nil) 4537 (tramp-set-connection-property tramp-test-vec "property" nil)
4540 4538
4541 (let ;; This is needed for the `separate' syntax. 4539 (let (;; This is needed for the `separate' syntax.
4542 ((prefix-format (substring tramp-prefix-format 1)) 4540 (prefix-format (substring tramp-prefix-format 1))
4543 ;; This is needed for the IPv6 host name syntax. 4541 ;; This is needed for the IPv6 host name syntax.
4544 (ipv6-prefix 4542 (ipv6-prefix
4545 (and (string-match-p tramp-ipv6-regexp host) 4543 (and (string-match-p tramp-ipv6-regexp host)
4546 tramp-prefix-ipv6-format)) 4544 tramp-prefix-ipv6-format))
4547 (ipv6-postfix 4545 (ipv6-postfix
4548 (and (string-match-p tramp-ipv6-regexp host) 4546 (and (string-match-p tramp-ipv6-regexp host)
4549 tramp-postfix-ipv6-format))) 4547 tramp-postfix-ipv6-format)))
4550 ;; Complete method name. 4548 ;; Complete method name.
4551 (unless (or (tramp-string-empty-or-nil-p method) 4549 (unless (or (tramp-string-empty-or-nil-p method)
4552 (string-empty-p tramp-method-regexp)) 4550 (string-empty-p tramp-method-regexp))
@@ -4637,6 +4635,132 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4637 ;; Cleanup. 4635 ;; Cleanup.
4638 (ignore-errors (delete-directory tmp-name 'recursive))))))) 4636 (ignore-errors (delete-directory tmp-name 'recursive)))))))
4639 4637
4638;; This test is inspired by Bug#51386, Bug#52758, Bug#53513, Bug#54042
4639;; and Bug#60505.
4640;; TODO: Add tests for user names and multi-hop file names.
4641(ert-deftest tramp-test26-interactive-file-name-completion ()
4642 "Check interactive completion with different `completion-styles'."
4643 ;; Method and host name in completion mode. This kind of completion
4644 ;; does not work on MS Windows.
4645 (unless (memq system-type '(cygwin windows-nt))
4646 (let ((method (file-remote-p ert-remote-temporary-file-directory 'method))
4647 (host (file-remote-p ert-remote-temporary-file-directory 'host))
4648 (orig-syntax tramp-syntax)
4649 (non-essential t))
4650 (when (and (stringp host) (string-match tramp-host-with-port-regexp host))
4651 (setq host (match-string 1 host)))
4652
4653 (unwind-protect
4654 (dolist (syntax (if (tramp--test-expensive-test-p)
4655 (tramp-syntax-values) `(,orig-syntax)))
4656 (tramp-change-syntax syntax)
4657 ;; This has cleaned up all connection data, which are used
4658 ;; for completion. We must refill the cache.
4659 (tramp-set-connection-property tramp-test-vec "property" nil)
4660
4661 (dolist
4662 (style
4663 (if (tramp--test-expensive-test-p)
4664 ;; It doesn't work for `initials' and `shorthand'
4665 ;; completion styles. Should it?
4666 '(emacs21 emacs22 basic partial-completion substring flex)
4667 '(basic)))
4668
4669 (let (;; Force the real minibuffer in batch mode.
4670 (executing-kbd-macro t)
4671 (completion-styles `(,style))
4672 (completions-format 'one-column)
4673 completion-category-defaults
4674 completion-category-overrides
4675 ;; This is needed for the `simplified' syntax,
4676 (tramp-default-method method)
4677 (method-string
4678 (unless (string-empty-p tramp-method-regexp)
4679 (concat method tramp-postfix-method-format)))
4680 ;; This is needed for the IPv6 host name syntax.
4681 (ipv6-prefix
4682 (and (string-match-p tramp-ipv6-regexp host)
4683 tramp-prefix-ipv6-format))
4684 (ipv6-postfix
4685 (and (string-match-p tramp-ipv6-regexp host)
4686 tramp-postfix-ipv6-format))
4687 test result completions)
4688
4689 ;; Complete method name.
4690 (unless (string-empty-p tramp-method-regexp)
4691 (ignore-errors (kill-buffer "*Completions*"))
4692 (discard-input)
4693 (setq test (concat
4694 tramp-prefix-format
4695 (substring-no-properties method 0 2))
4696 unread-command-events
4697 (mapcar #'identity (concat test "\t\n"))
4698 completions nil
4699 result (read-file-name "Prompt: "))
4700 (if (not (get-buffer "*Completions*"))
4701 (progn
4702 (tramp--test-message
4703 "syntax: %s style: %s test: %s result: %s"
4704 syntax style test result)
4705 (should
4706 (string-prefix-p
4707 (concat tramp-prefix-format method-string)
4708 result)))
4709 (with-current-buffer "*Completions*"
4710 (re-search-forward
4711 (rx bol (1+ nonl) "possible completions:" eol))
4712 (forward-line 1)
4713 (setq completions
4714 (split-string
4715 (buffer-substring-no-properties (point) (point-max))
4716 (rx (any "\r\n")) 'omit)))
4717 (tramp--test-message
4718 "syntax: %s style: %s test: %s result: %s completions: %S"
4719 syntax style test result completions)
4720 (should (member method-string completions))))
4721
4722 ;; Complete host name.
4723 (unless (or (tramp-string-empty-or-nil-p host)
4724 (tramp--test-gvfs-p method))
4725 (ignore-errors (kill-buffer "*Completions*"))
4726 (discard-input)
4727 (setq test (concat
4728 tramp-prefix-format method-string
4729 (substring-no-properties host 0 2))
4730 unread-command-events
4731 (mapcar #'identity (concat test "\t\n"))
4732 completions nil
4733 result (read-file-name "Prompt: "))
4734 (if (not (get-buffer "*Completions*"))
4735 (progn
4736 (tramp--test-message
4737 "syntax: %s style: %s test: %s result: %s"
4738 syntax style test result)
4739 (should
4740 (string-equal
4741 (concat
4742 tramp-prefix-format method-string
4743 ipv6-prefix host ipv6-postfix tramp-postfix-host-format)
4744 result)))
4745 (with-current-buffer "*Completions*"
4746 (re-search-forward
4747 (rx bol (1+ nonl) "possible completions:" eol))
4748 (forward-line 1)
4749 (setq completions
4750 (split-string
4751 (buffer-substring-no-properties (point) (point-max))
4752 (rx (any "\r\n")) 'omit)))
4753 (tramp--test-message
4754 "syntax: %s style: %s test: %s result: %s completions: %S"
4755 syntax style test result completions)
4756 (should
4757 (member
4758 (concat host tramp-postfix-host-format)
4759 completions)))))))
4760
4761 ;; Cleanup.
4762 (tramp-change-syntax orig-syntax)))))
4763
4640(ert-deftest tramp-test27-load () 4764(ert-deftest tramp-test27-load ()
4641 "Check `load'." 4765 "Check `load'."
4642 (skip-unless (tramp--test-enabled)) 4766 (skip-unless (tramp--test-enabled))