From 6ad8745833c2cc722cc73fd86ac63cd4741d2b2b Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 2 Sep 2025 12:09:17 +0200 Subject: [PATCH] Extend tramp-test26-interactive-file-name-completion * lisp/net/tramp.el (tramp-get-completion-methods): Use `tramp-compat-seq-keep'. * test/lisp/net/tramp-tests.el (completions-max-height): Declare. (tramp-test26-interactive-file-name-completion): Extend test. --- lisp/net/tramp.el | 2 +- test/lisp/net/tramp-tests.el | 142 ++++++++++++++++++++++------------- 2 files changed, 89 insertions(+), 55 deletions(-) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index c7450bc015d..9bf1b4ae6c3 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3261,7 +3261,7 @@ remote host and localname (filename on remote host)." (defun tramp-get-completion-methods (partial-method &optional multi-hop) "Return all method completions for PARTIAL-METHOD. If MULTI-HOP is non-nil, return only multi-hop capable methods." - (mapcar + (tramp-compat-seq-keep (lambda (method) (and method (string-prefix-p (or partial-method "") method) (or (not multi-hop) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 892e4ef519c..8c230f43cf3 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -91,6 +91,9 @@ (defvar tramp-remote-process-environment) (defvar tramp-use-connection-share) +;; Declared in Emacs 29.1. +(defvar completions-max-height) + ;; Declared in Emacs 30.1. (defvar project-mode-line) (defvar remote-file-name-access-timeout) @@ -5002,30 +5005,33 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (tramp--test-deftest-with-ls tramp-test26-file-name-completion) -;; This test is inspired by Bug#51386, Bug#52758, Bug#53513, Bug#54042 -;; and Bug#60505. +;; This test is inspired by Bug#51386, Bug#52758, Bug#53513, +;; Bug#54042, Bug#60505 and Bug#79236. (ert-deftest tramp-test26-interactive-file-name-completion () "Check interactive completion with different `completion-styles'." + :tags '(:expensive-test) (skip-unless (tramp--test-enabled)) - ;; (when (get-buffer trace-buffer) (kill-buffer trace-buffer)) - ;; (dolist (elt (append - ;; (mapcar - ;; #'intern (all-completions "tramp-" obarray #'functionp)) - ;; tramp-trace-functions)) - ;; (unless (get elt 'tramp-suppress-trace) - ;; (trace-function-background elt))) - ;; (trace-function-background #'completion-file-name-table) - ;; (trace-function-background #'read-file-name) - ;; Method, user and host name in completion mode. - (let ((method (file-remote-p ert-remote-temporary-file-directory 'method)) - (user (file-remote-p ert-remote-temporary-file-directory 'user)) - (host (file-remote-p ert-remote-temporary-file-directory 'host)) - (hop (file-remote-p ert-remote-temporary-file-directory 'hop)) - (orig-syntax tramp-syntax) - (non-essential t) - (inhibit-message (not (ignore-errors (edebug-mode))))) + (let* (;; Set this to `t' if you want to run all tests. + (expensive nil) ;(tramp--test-expensive-test-p)) + ;; Set this to `t' if you want to see the traces. + (tramp-trace nil) + (method (file-remote-p ert-remote-temporary-file-directory 'method)) + (user (file-remote-p ert-remote-temporary-file-directory 'user)) + (host (file-remote-p ert-remote-temporary-file-directory 'host)) + (hop (and expensive + (file-remote-p ert-remote-temporary-file-directory 'hop))) + ;; All multi-hop capable methods. + (method-list + (and hop (sort (mapcar + (lambda (x) + (substring x (length tramp-prefix-format))) + (tramp-get-completion-methods "" t))))) + (orig-syntax tramp-syntax) + (non-essential t) + (inhibit-message + (and (not tramp-trace) (not (ignore-errors (edebug-mode)))))) ;; `file-remote-p' returns as host the string "host#port", which ;; isn't useful. (when (and (stringp host) @@ -5034,6 +5040,15 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." host)) (setq host (replace-match "" nil nil host))) + (when tramp-trace + (when (get-buffer trace-buffer) (kill-buffer trace-buffer)) + (dolist + (elt (mapcar #'intern (all-completions "tramp-" obarray #'functionp))) + (unless (get elt 'tramp-suppress-trace) + (trace-function-background elt))) + (trace-function-background #'completion-file-name-table) + (trace-function-background #'read-file-name)) + (unwind-protect (dolist (syntax (if (tramp--test-expensive-test-p) (tramp-syntax-values) `(,orig-syntax))) @@ -5045,21 +5060,21 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (dolist (style - (if (tramp--test-expensive-test-p) - ;; FIXME: It doesn't work for `initials' and - ;; `shorthand' completion styles. Should it? - ;; `orderless' passes the tests, but it is an ELPA package. - ;; What about `company' backends, `consult', `cider', `helm'? + (if expensive + ;; `initials' uses "/" as separator, it doesn't apply here. + ;; `shorthand' is about symbols, it doesn't apply here. `(emacs21 emacs22 basic partial-completion substring ;; FIXME: `flex' is not compatible with IPv6 hosts. - ,@(unless (string-match-p tramp-ipv6-regexp host) '(flex))) + ,@(unless (string-match-p tramp-ipv6-regexp host) '(flex)) + ;; `orderless' is an ELPA package. + ;; What about `company' backends, `consult', + ;; `cider', `helm'? + orderless) '(basic))) (when (assoc style completion-styles-alist) (let* (;; Force the real minibuffer in batch mode. (executing-kbd-macro noninteractive) - ;; FIXME: Is this TRT for test? - (minibuffer-completing-file-name t) (confirm-nonexistent-file-or-buffer nil) (completion-styles `(,style)) completion-category-defaults @@ -5072,6 +5087,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." `(any ,(string-replace ":" "" completion-pcm-word-delimiters)))) + ;; Don't truncate in *Completions* buffer. + (completions-max-height most-positive-fixnum) ;; This is needed for the `simplified' syntax. (tramp-default-method method) (method-string @@ -5097,7 +5114,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." ;; Needed for host name completion. (default-user (file-remote-p - (concat tramp-prefix-format hop method-string host-string) + (concat + tramp-prefix-format hop method-string host-string) 'user)) (default-user-string (unless (tramp-string-empty-or-nil-p default-user) @@ -5107,8 +5125,18 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (dolist (test-and-result ;; These are triples of strings (TEST-STRING - ;; RESULT-CHECK COMPLETION-CHECK). + ;; RESULT-CHECK COMPLETION-CHECK). If + ;; COMPLETION-CHECK is a list, it is the complete + ;; result the contents of *Completions* shall be + ;; checked with. (append + ;; Complete hop. + (unless (tramp-string-empty-or-nil-p hop) + `((,(concat tramp-prefix-format hop) + ,(concat tramp-prefix-format hop) + ,(if (string-empty-p tramp-method-regexp) + (or default-user-string host-string) + method-list)))) ;; Complete method name. (unless (string-empty-p tramp-method-regexp) `((,(concat @@ -5127,7 +5155,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." tramp-prefix-format hop method-string user-string) ,user-string))) ;; Complete host name. - (unless (tramp-string-empty-or-nil-p host) + (unless (tramp-string-empty-or-nil-p host-string) `((,(concat tramp-prefix-format hop method-string ipv6-prefix @@ -5138,8 +5166,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." default-user-string host-string) ,host-string))) ;; Complete user and host name. - (unless (or (tramp-string-empty-or-nil-p user) - (tramp-string-empty-or-nil-p host)) + (unless (or (tramp-string-empty-or-nil-p user-string) + (tramp-string-empty-or-nil-p host-string)) `((,(concat tramp-prefix-format hop method-string user-string ipv6-prefix @@ -5152,8 +5180,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (dolist (predicate - (if (and (tramp--test-expensive-test-p) - (tramp--test-emacs31-p)) + (if (and expensive (tramp--test-emacs31-p)) ;; `nil' will be expanded to `file-exists-p'. ;; `read-directory-name' uses `file-directory-p'. ;; `file-directory-p' works since Emacs 31. @@ -5161,8 +5188,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." '(file-exists-p file-directory-p) '(nil))) (ignore-errors (kill-buffer "*Completions*")) - ;; (when (get-buffer trace-buffer) - ;; (kill-buffer trace-buffer)) + (when tramp-trace + (when (get-buffer trace-buffer) + (kill-buffer trace-buffer))) (discard-input) (setq test (car test-and-result) unread-command-events @@ -5186,11 +5214,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." eos)) result)) (progn - ;; (tramp--test-message - ;; (concat - ;; "syntax: %s style: %s predicate: %s " - ;; "test: %s result: %s") - ;; syntax style predicate test result) + (when tramp-trace + (tramp--test-message + (concat + "syntax: %s style: %s predicate: %s " + "test: %s result: %s") + syntax style predicate test result)) (should (string-prefix-p (cadr test-and-result) result))) @@ -5212,16 +5241,22 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (point) (point-max)) (rx (any "\r\n\t ")) 'omit))) - ;; (tramp--test-message - ;; (concat - ;; "syntax: %s style: %s predicate: %s test: %s " - ;; "result: %s completions: %S") - ;; syntax style predicate test result completions) - (should - (member (caddr test-and-result) completions))))))))) + (when tramp-trace + (tramp--test-message + (concat + "syntax: %s style: %s predicate: %s test: %s " + "result: %s completions: %S") + syntax style predicate test result completions)) + (if (stringp (caddr test-and-result)) + (should + (member (caddr test-and-result) completions)) + (should + (equal + (caddr test-and-result) (sort completions))))))))))) ;; Cleanup. - ;; (untrace-all) + (when tramp-trace + (untrace-all)) (tramp-change-syntax orig-syntax) (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)))) @@ -8879,15 +8914,12 @@ If INTERACTIVE is non-nil, the tests are run interactively." ;; * tramp-set-file-uid-gid ;; * Work on skipped tests. Make a comment, when it is impossible. -;; * Use `skip-when' starting with Emacs 30.1. ;; * Revisit expensive tests, once problems in `tramp-error' are solved. ;; * Fix `tramp-test06-directory-file-name' for "ftp". ;; * In `tramp-test26-file-name-completion', check also user, domain, ;; port and hop. -;; * In `tramp-test26-interactive-file-name-completion', check `flex', -;; `initials' and `shorthand' completion styles. Should -;; `minibuffer-completing-file-name' and `completion-pcm--delim-wild-regex' -;; be bound? Check also domain, port and hop. +;; * In `tramp-test26-interactive-file-name-completion', should +;; `completion-pcm--delim-wild-regex' be bound? Check also domain and port. ;; * Check, why a process filter t doesn't work in ;; `tramp-test29-start-file-process' and ;; `tramp-test30-make-process'. @@ -8899,6 +8931,8 @@ If INTERACTIVE is non-nil, the tests are run interactively." ;; * Check, why direct async processes do not work for ;; `tramp-test45-asynchronous-requests'. +;; Use `skip-when' starting with Emacs 30.1. + ;; Starting with Emacs 29, use `ert-with-temp-file' and ;; `ert-with-temp-directory'.