diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2022-09-09 17:10:28 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2022-09-09 17:10:28 +0200 |
commit | 08cc6c4d9e42079f88c6c30d9a2324dd6f0cec2b (patch) | |
tree | a5f6e5325a24feb9a481df77c20e27e3b42683e7 /test/lisp/net/tramp-tests.el | |
parent | 72c64dd73c93a92f91431435a0295d748588a4ed (diff) | |
download | emacs-08cc6c4d9e42079f88c6c30d9a2324dd6f0cec2b.tar.gz |
Make use of rx in Tramp backward compatoble
* lisp/net/tramp-compat.el (tramp-compat-rx--runtime-params): New defvar.
(tramp-compat-rx--transform-items)
(tramp-compat-rx--transform-item, tramp-compat-rx--transform):
New defuns. Suggested by Mattias EngdegÄrd <mattiase@acm.org>.
(tramp-compat-rx): New defalias or defmacro.
(tramp-compat-string-replace, tramp-compat-string-search):
Use regexp-quote.
* lisp/net/tramp.el:
* lisp/net/tramp-adb.el:
* lisp/net/tramp-archive.el:
* lisp/net/tramp-cmds.el:
* lisp/net/tramp-crypt.el:
* lisp/net/tramp-fuse.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-sh.el:
* lisp/net/tramp-smb.el:
* lisp/net/tramp-sudoedit.el: Use `tramp-compat-rx' where indicated.
* test/lisp/net/tramp-archive-tests.el:
* test/lisp/net/tramp-tests.el: Use `tramp-compat-rx' where indicated.
Diffstat (limited to 'test/lisp/net/tramp-tests.el')
-rw-r--r-- | test/lisp/net/tramp-tests.el | 104 |
1 files changed, 63 insertions, 41 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 6f7c6702e76..2db44494388 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2295,9 +2295,9 @@ This checks also `file-name-as-directory', `file-name-directory', ;; Check `directory-abbrev-alist' abbreviation. (let ((directory-abbrev-alist - `((,(rx bos (literal home-dir) "/foo") + `((,(tramp-compat-rx bos (literal home-dir) "/foo") . ,(concat home-dir "/f")) - (,(rx bos (literal remote-host) "/nowhere") + (,(tramp-compat-rx bos (literal remote-host) "/nowhere") . ,(concat remote-host "/nw"))))) (should (equal (abbreviate-file-name (concat home-dir "/foo/bar")) (concat remote-host-nohop "~/f/bar"))) @@ -2510,7 +2510,8 @@ This checks also `file-name-as-directory', `file-name-directory', (string-match-p (if (and (null noninteractive) (or (eq visit t) (null visit) (stringp visit))) - (rx bol "Wrote " (literal tmp-name) "\n" eos) + (tramp-compat-rx + bol "Wrote " (literal tmp-name) "\n" eos) (rx bos)) tramp--test-messages)))))) @@ -3211,24 +3212,26 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." (with-temp-buffer (insert-directory tmp-name1 nil) (goto-char (point-min)) - (should (looking-at-p (rx (literal tmp-name1))))) + (should (looking-at-p (tramp-compat-rx (literal tmp-name1))))) (with-temp-buffer (insert-directory (file-name-as-directory tmp-name1) nil) (goto-char (point-min)) (should (looking-at-p - (rx (literal (file-name-as-directory tmp-name1)))))) + (tramp-compat-rx (literal (file-name-as-directory tmp-name1)))))) (with-temp-buffer (insert-directory tmp-name1 "-al") (goto-char (point-min)) (should - (looking-at-p (rx bol (+ nonl) blank (literal tmp-name1) eol)))) + (looking-at-p + (tramp-compat-rx bol (+ nonl) blank (literal tmp-name1) eol)))) (with-temp-buffer (insert-directory (file-name-as-directory tmp-name1) "-al") (goto-char (point-min)) (should (looking-at-p - (rx bol (+ nonl) blank (literal tmp-name1) "/" eol)))) + (tramp-compat-rx + bol (+ nonl) blank (literal tmp-name1) "/" eol)))) (with-temp-buffer (insert-directory (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p) @@ -3312,15 +3315,17 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." (goto-char (point-min)) (should (re-search-forward - (rx (literal - (file-relative-name - tmp-name1 ert-remote-temporary-file-directory))))) + (tramp-compat-rx + (literal + (file-relative-name + tmp-name1 ert-remote-temporary-file-directory))))) (goto-char (point-min)) (should (re-search-forward - (rx (literal - (file-relative-name - tmp-name2 ert-remote-temporary-file-directory)))))) + (tramp-compat-rx + (literal + (file-relative-name + tmp-name2 ert-remote-temporary-file-directory)))))) (kill-buffer buffer) ;; Check for expanded directory and file names. @@ -3332,16 +3337,18 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." (goto-char (point-min)) (should (re-search-forward - (rx (literal - (file-relative-name - tmp-name3 ert-remote-temporary-file-directory))))) + (tramp-compat-rx + (literal + (file-relative-name + tmp-name3 ert-remote-temporary-file-directory))))) (goto-char (point-min)) (should (re-search-forward - (rx (literal - (file-relative-name - tmp-name4 - ert-remote-temporary-file-directory)))))) + (tramp-compat-rx + (literal + (file-relative-name + tmp-name4 + ert-remote-temporary-file-directory)))))) (kill-buffer buffer) ;; Check for special characters. @@ -3360,16 +3367,18 @@ This tests also `file-directory-p' and `file-accessible-directory-p'." (goto-char (point-min)) (should (re-search-forward - (rx (literal - (file-relative-name - tmp-name3 ert-remote-temporary-file-directory))))) + (tramp-compat-rx + (literal + (file-relative-name + tmp-name3 ert-remote-temporary-file-directory))))) (goto-char (point-min)) (should (re-search-forward - (rx (literal - (file-relative-name - tmp-name4 - ert-remote-temporary-file-directory)))))) + (tramp-compat-rx + (literal + (file-relative-name + tmp-name4 + ert-remote-temporary-file-directory)))))) (kill-buffer buffer)) ;; Cleanup. @@ -3599,6 +3608,9 @@ This tests also `access-file', `file-readable-p', (cons '(nil "perl" nil) tramp-connection-properties))) (progn + ;; `ert-test-result-duration' exists since Emacs 27. It + ;; doesn't hurt to call it unconditionally, because + ;; `skip-unless' hides the error. (skip-unless (< (ert-test-result-duration result) 300)) (funcall (ert-test-body ert-test))) (ert-skip (format "Test `%s' must run before" ',test))))) @@ -3627,6 +3639,9 @@ This tests also `access-file', `file-readable-p', (nil "id" nil)) tramp-connection-properties))) (progn + ;; `ert-test-result-duration' exists since Emacs 27. It + ;; doesn't hurt to call it unconditionally, because + ;; `skip-unless' hides the error. (skip-unless (< (ert-test-result-duration result) 300)) (funcall (ert-test-body ert-test))) (ert-skip (format "Test `%s' must run before" ',test))))) @@ -3653,6 +3668,9 @@ This tests also `access-file', `file-readable-p', (nil "readlink" nil)) tramp-connection-properties))) (progn + ;; `ert-test-result-duration' exists since Emacs 27. It + ;; doesn't hurt to call it unconditionally, because + ;; `skip-unless' hides the error. (skip-unless (< (ert-test-result-duration result) 300)) (funcall (ert-test-body ert-test))) (ert-skip (format "Test `%s' must run before" ',test))))) @@ -5679,7 +5697,7 @@ INPUT, if non-nil, is a string sent to the process." ;; Variable is set. (should (string-match-p - (rx (literal envvar)) + (tramp-compat-rx (literal envvar)) (funcall this-shell-command-to-string "set")))) (unless (tramp-direct-async-process-p) @@ -5706,7 +5724,7 @@ INPUT, if non-nil, is a string sent to the process." ;; Variable is unset. (should-not (string-match-p - (rx (literal envvar)) + (tramp-compat-rx (literal envvar)) ;; We must remove PS1, the output is truncated otherwise. ;; We must suppress "_=VAR...". (funcall @@ -6598,7 +6616,7 @@ This is used in tests which we don't want to tag :body nil :tags '(:tramp-asynchronous-processes)))) ;; tramp-adb.el cannot apply multi-byte commands. (not (and (tramp--test-adb-p) - (string-match-p (rx multibyte) default-directory))))) + (string-match-p (tramp-compat-rx multibyte) default-directory))))) (defun tramp--test-crypt-p () "Check, whether the remote directory is encrypted." @@ -6906,14 +6924,14 @@ This requires restrictions of file name syntax." (should (string-equal (caar (directory-files-and-attributes - file1 nil (rx (literal elt1)))) + file1 nil (tramp-compat-rx (literal elt1)))) elt1)) (should (string-equal (funcall (if quoted #'tramp-compat-file-name-quote #'identity) (cadr (car (directory-files-and-attributes - file1 nil (rx (literal elt1)))))) + file1 nil (tramp-compat-rx (literal elt1)))))) (file-remote-p (file-truename file2) 'localname))) (delete-file file3) (should-not (file-exists-p file3)))) @@ -6968,8 +6986,9 @@ This requires restrictions of file name syntax." (goto-char (point-min)) (should (re-search-forward - (rx bol (literal envvar) - "=" (literal (getenv envvar)) eol)))))))) + (tramp-compat-rx + bol (literal envvar) + "=" (literal (getenv envvar)) eol)))))))) ;; Cleanup. (ignore-errors (kill-buffer buffer)) @@ -7511,9 +7530,10 @@ process sentinels. They shall not disturb each other." (dolist (tm '(t nil)) (should (string-match-p - (rx "Tramp loaded: nil" (+ (any "\n\r")) - "Tramp loaded: nil" (+ (any "\n\r")) - "Tramp loaded: " (literal (symbol-name tm)) (+ (any "\n\r"))) + (tramp-compat-rx + "Tramp loaded: nil" (+ (any "\n\r")) + "Tramp loaded: nil" (+ (any "\n\r")) + "Tramp loaded: " (literal (symbol-name tm)) (+ (any "\n\r"))) (shell-command-to-string (format "%s -batch -Q -L %s --eval %s" @@ -7558,10 +7578,11 @@ process sentinels. They shall not disturb each other." (tramp-cleanup-all-connections))")) (should (string-match-p - (rx "Loading " - (literal - (expand-file-name - "tramp-cmds" (file-name-directory (locate-library "tramp"))))) + (tramp-compat-rx + "Loading " + (literal + (expand-file-name + "tramp-cmds" (file-name-directory (locate-library "tramp"))))) (shell-command-to-string (format "%s -batch -Q -L %s -l tramp-sh --eval %s" @@ -7665,6 +7686,7 @@ If INTERACTIVE is non-nil, the tests are run interactively." ;; * file-in-directory-p ;; * file-name-case-insensitive-p ;; * tramp-get-remote-gid +;; * tramp-get-remote-groups ;; * tramp-get-remote-uid ;; * tramp-set-file-uid-gid |