diff options
| author | Michael Albinus | 2024-11-15 14:28:08 +0100 |
|---|---|---|
| committer | Michael Albinus | 2024-11-15 14:28:08 +0100 |
| commit | 310ce93d02c5317be589803fbde96fd20b96e496 (patch) | |
| tree | b0ae9cf8c4877b8433079b218d2cce2a4a8bfda8 | |
| parent | cc9188b1900079f87d76cc8b7493d64a9ccd9d36 (diff) | |
| download | emacs-310ce93d02c5317be589803fbde96fd20b96e496.tar.gz emacs-310ce93d02c5317be589803fbde96fd20b96e496.zip | |
Remove Tramp temp files if advised during tests
* lisp/net/tramp-fuse.el (tramp-fuse-name-prefix): New defconst.
(tramp-fuse-mount-point): Use it.
* test/lisp/net/tramp-tests.el (tramp-test-name-prefix): New defconst.
(tramp--test-make-temp-name, tramp-test40-make-nearby-temp-file)
(tramp-test47-read-password, tramp-test47-read-otp-password):
Use it.
(tramp--test-enabled-checked): Move down.
(tramp--test-enabled): Delete all Tramp temp files when
environment variable $TRAMP_TEST_CLEANUP_TEMP_FILES is set.
(tramp-test02-file-name-dissect-separate):
Adapt `tramp-crypt-directories' according to syntax.
(tramp-test47-read-password):
Let-bind `tramp-connection-properties' instead of modifying
`tramp-methods'.
| -rw-r--r-- | lisp/net/tramp-fuse.el | 6 | ||||
| -rw-r--r-- | lisp/net/tramp-smb.el | 2 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 156 |
3 files changed, 118 insertions, 46 deletions
diff --git a/lisp/net/tramp-fuse.el b/lisp/net/tramp-fuse.el index df33c7a4c3b..e34f735fa00 100644 --- a/lisp/net/tramp-fuse.el +++ b/lisp/net/tramp-fuse.el | |||
| @@ -138,13 +138,17 @@ | |||
| 138 | "Time period to check whether the mount point still exists. | 138 | "Time period to check whether the mount point still exists. |
| 139 | It has the same meaning as `remote-file-name-inhibit-cache'.") | 139 | It has the same meaning as `remote-file-name-inhibit-cache'.") |
| 140 | 140 | ||
| 141 | ;;;###tramp-autoload | ||
| 142 | (defconst tramp-fuse-name-prefix "tramp-" | ||
| 143 | "Prefix to use for temporary FUSE mount points.") | ||
| 144 | |||
| 141 | (defun tramp-fuse-mount-point (vec) | 145 | (defun tramp-fuse-mount-point (vec) |
| 142 | "Return local mount point of VEC." | 146 | "Return local mount point of VEC." |
| 143 | (let ((remote-file-name-inhibit-cache tramp-fuse-mount-timeout)) | 147 | (let ((remote-file-name-inhibit-cache tramp-fuse-mount-timeout)) |
| 144 | (or (tramp-get-file-property vec "/" "mount-point") | 148 | (or (tramp-get-file-property vec "/" "mount-point") |
| 145 | (expand-file-name | 149 | (expand-file-name |
| 146 | (concat | 150 | (concat |
| 147 | tramp-temp-name-prefix | 151 | tramp-fuse-name-prefix |
| 148 | (tramp-file-name-method vec) "." | 152 | (tramp-file-name-method vec) "." |
| 149 | (when (tramp-file-name-user vec) | 153 | (when (tramp-file-name-user vec) |
| 150 | (concat (tramp-file-name-user-domain vec) "@")) | 154 | (concat (tramp-file-name-user-domain vec) "@")) |
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 797e481e3fb..8d090a6969f 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el | |||
| @@ -765,7 +765,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 765 | (forward-line) | 765 | (forward-line) |
| 766 | (delete-region (point-min) (point))) | 766 | (delete-region (point-min) (point))) |
| 767 | (while (and (not (eobp)) (looking-at-p (rx bol (+ nonl) ":" (+ nonl)))) | 767 | (while (and (not (eobp)) (looking-at-p (rx bol (+ nonl) ":" (+ nonl)))) |
| 768 | (forward-line)) | 768 | (forward-line)) |
| 769 | (delete-region (point) (point-max)) | 769 | (delete-region (point) (point-max)) |
| 770 | (throw 'tramp-action 'ok)))) | 770 | (throw 'tramp-action 'ok)))) |
| 771 | 771 | ||
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 32f65621aa4..d658b061116 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -33,6 +33,14 @@ | |||
| 33 | ;; remote host, set this environment variable to "/dev/null" or | 33 | ;; remote host, set this environment variable to "/dev/null" or |
| 34 | ;; whatever is appropriate on your system. | 34 | ;; whatever is appropriate on your system. |
| 35 | 35 | ||
| 36 | ;; All temporary Tramp test files are removed prior test run. | ||
| 37 | ;; Therefore, two test runs cannot be performed in parallel. | ||
| 38 | |||
| 39 | ;; The environment variable $TRAMP_TEST_CLEANUP_TEMP_FILES, when set, | ||
| 40 | ;; forces the removal of all temporary Tramp files prior test run. | ||
| 41 | ;; This shouldn't be set if the test suite runs in parallel using | ||
| 42 | ;; Tramp on a production system. | ||
| 43 | |||
| 36 | ;; For slow remote connections, `tramp-test45-asynchronous-requests' | 44 | ;; For slow remote connections, `tramp-test45-asynchronous-requests' |
| 37 | ;; might be too heavy. Setting $REMOTE_PARALLEL_PROCESSES to a proper | 45 | ;; might be too heavy. Setting $REMOTE_PARALLEL_PROCESSES to a proper |
| 38 | ;; value less than 10 could help. | 46 | ;; value less than 10 could help. |
| @@ -128,7 +136,8 @@ | |||
| 128 | (tramp-dissect-file-name ert-remote-temporary-file-directory)) | 136 | (tramp-dissect-file-name ert-remote-temporary-file-directory)) |
| 129 | "The used `tramp-file-name' structure.") | 137 | "The used `tramp-file-name' structure.") |
| 130 | 138 | ||
| 131 | (setq auth-source-save-behavior nil | 139 | (setq auth-source-cache-expiry nil |
| 140 | auth-source-save-behavior nil | ||
| 132 | password-cache-expiry nil | 141 | password-cache-expiry nil |
| 133 | remote-file-name-inhibit-cache nil | 142 | remote-file-name-inhibit-cache nil |
| 134 | tramp-allow-unsafe-temporary-files t | 143 | tramp-allow-unsafe-temporary-files t |
| @@ -138,39 +147,8 @@ | |||
| 138 | tramp-persistency-file-name nil | 147 | tramp-persistency-file-name nil |
| 139 | tramp-verbose 0) | 148 | tramp-verbose 0) |
| 140 | 149 | ||
| 141 | (defvar tramp--test-enabled-checked nil | 150 | (defconst tramp-test-name-prefix "tramp-test" |
| 142 | "Cached result of `tramp--test-enabled'. | 151 | "Prefix to use for temporary test files.") |
| 143 | If the function did run, the value is a cons cell, the `cdr' | ||
| 144 | being the result.") | ||
| 145 | |||
| 146 | (defun tramp--test-enabled () | ||
| 147 | "Whether remote file access is enabled." | ||
| 148 | (unless (consp tramp--test-enabled-checked) | ||
| 149 | (setq | ||
| 150 | tramp--test-enabled-checked | ||
| 151 | (cons | ||
| 152 | t (ignore-errors | ||
| 153 | (and | ||
| 154 | (file-remote-p ert-remote-temporary-file-directory) | ||
| 155 | (file-directory-p ert-remote-temporary-file-directory) | ||
| 156 | (file-writable-p ert-remote-temporary-file-directory)))))) | ||
| 157 | |||
| 158 | (when (cdr tramp--test-enabled-checked) | ||
| 159 | ;; Remove old test files. | ||
| 160 | (dolist (dir `(,temporary-file-directory | ||
| 161 | ,tramp-compat-temporary-file-directory | ||
| 162 | ,ert-remote-temporary-file-directory)) | ||
| 163 | (dolist (file (directory-files dir 'full (rx bos (? ".#") "tramp-test"))) | ||
| 164 | (ignore-errors | ||
| 165 | (if (file-directory-p file) | ||
| 166 | (delete-directory file 'recursive) | ||
| 167 | (delete-file file))))) | ||
| 168 | ;; Cleanup connection. | ||
| 169 | (ignore-errors | ||
| 170 | (tramp-cleanup-connection tramp-test-vec nil 'keep-password))) | ||
| 171 | |||
| 172 | ;; Return result. | ||
| 173 | (cdr tramp--test-enabled-checked)) | ||
| 174 | 152 | ||
| 175 | (defun tramp--test-make-temp-name (&optional local quoted) | 153 | (defun tramp--test-make-temp-name (&optional local quoted) |
| 176 | "Return a temporary file name for test. | 154 | "Return a temporary file name for test. |
| @@ -180,7 +158,7 @@ The temporary file is not created." | |||
| 180 | (funcall | 158 | (funcall |
| 181 | (if quoted #'file-name-quote #'identity) | 159 | (if quoted #'file-name-quote #'identity) |
| 182 | (expand-file-name | 160 | (expand-file-name |
| 183 | (make-temp-name "tramp-test") | 161 | (make-temp-name tramp-test-name-prefix) |
| 184 | (if local temporary-file-directory ert-remote-temporary-file-directory)))) | 162 | (if local temporary-file-directory ert-remote-temporary-file-directory)))) |
| 185 | 163 | ||
| 186 | ;; Method "smb" supports `make-symbolic-link' only if the remote host | 164 | ;; Method "smb" supports `make-symbolic-link' only if the remote host |
| @@ -248,6 +226,56 @@ is greater than 10. | |||
| 248 | (tramp--test-message | 226 | (tramp--test-message |
| 249 | "%s %f sec" ,message (float-time (time-subtract nil start)))))) | 227 | "%s %f sec" ,message (float-time (time-subtract nil start)))))) |
| 250 | 228 | ||
| 229 | (defvar tramp--test-enabled-checked nil | ||
| 230 | "Cached result of `tramp--test-enabled'. | ||
| 231 | If the function did run, the value is a cons cell, the `cdr' | ||
| 232 | being the result.") | ||
| 233 | |||
| 234 | (defun tramp--test-enabled () | ||
| 235 | "Whether remote file access is enabled." | ||
| 236 | (unless (consp tramp--test-enabled-checked) | ||
| 237 | (setq | ||
| 238 | tramp--test-enabled-checked | ||
| 239 | (cons | ||
| 240 | t (ignore-errors | ||
| 241 | (and | ||
| 242 | (file-remote-p ert-remote-temporary-file-directory) | ||
| 243 | (file-directory-p ert-remote-temporary-file-directory) | ||
| 244 | (file-writable-p ert-remote-temporary-file-directory)))))) | ||
| 245 | |||
| 246 | (when (cdr tramp--test-enabled-checked) | ||
| 247 | ;; Remove old test files. | ||
| 248 | (dolist (dir `(,temporary-file-directory | ||
| 249 | ,tramp-compat-temporary-file-directory | ||
| 250 | ,ert-remote-temporary-file-directory)) | ||
| 251 | (dolist | ||
| 252 | (file | ||
| 253 | (directory-files | ||
| 254 | dir 'full | ||
| 255 | (rx bos (? ".#") | ||
| 256 | (| (literal tramp-test-name-prefix) | ||
| 257 | (eval (if (getenv "TRAMP_TEST_CLEANUP_TEMP_FILES") | ||
| 258 | tramp-temp-name-prefix 'unmatchable)))))) | ||
| 259 | |||
| 260 | ;; Exclude sockets and FUSE mount points. | ||
| 261 | (ignore-errors | ||
| 262 | (unless | ||
| 263 | (or (string-prefix-p | ||
| 264 | "srw" (file-attribute-modes (file-attributes file))) | ||
| 265 | (string-match-p (rx bos (literal tramp-fuse-name-prefix) | ||
| 266 | (regexp tramp-method-regexp) ".") | ||
| 267 | (file-name-nondirectory file))) | ||
| 268 | (tramp--test-message "Delete %s" file) | ||
| 269 | (if (file-directory-p file) | ||
| 270 | (delete-directory file 'recursive) | ||
| 271 | (delete-file file)))))) | ||
| 272 | ;; Cleanup connection. | ||
| 273 | (ignore-errors | ||
| 274 | (tramp-cleanup-connection tramp-test-vec nil 'keep-password))) | ||
| 275 | |||
| 276 | ;; Return result. | ||
| 277 | (cdr tramp--test-enabled-checked)) | ||
| 278 | |||
| 251 | (ert-deftest tramp-test00-availability () | 279 | (ert-deftest tramp-test00-availability () |
| 252 | "Test availability of Tramp functions." | 280 | "Test availability of Tramp functions." |
| 253 | :expected-result (if (tramp--test-enabled) :passed :failed) | 281 | :expected-result (if (tramp--test-enabled) :passed :failed) |
| @@ -1410,10 +1438,20 @@ is greater than 10. | |||
| 1410 | ;; Suppress check for multihops. | 1438 | ;; Suppress check for multihops. |
| 1411 | (tramp-cache-data (make-hash-table :test #'equal)) | 1439 | (tramp-cache-data (make-hash-table :test #'equal)) |
| 1412 | (tramp-connection-properties '((nil "login-program" t))) | 1440 | (tramp-connection-properties '((nil "login-program" t))) |
| 1413 | (syntax tramp-syntax)) | 1441 | (syntax tramp-syntax) |
| 1442 | ;; We must transform `tramp-crypt-directories'. | ||
| 1443 | (tramp-crypt-directories | ||
| 1444 | (mapcar #'tramp-dissect-file-name tramp-crypt-directories))) | ||
| 1414 | (unwind-protect | 1445 | (unwind-protect |
| 1415 | (progn | 1446 | (progn |
| 1416 | (tramp-change-syntax 'separate) | 1447 | (tramp-change-syntax 'separate) |
| 1448 | ;; We must transform `tramp-crypt-directories'. | ||
| 1449 | (setq tramp-crypt-directories | ||
| 1450 | (mapcar | ||
| 1451 | (lambda (vec) | ||
| 1452 | (tramp-make-tramp-file-name | ||
| 1453 | vec (tramp-file-name-localname vec))) | ||
| 1454 | tramp-crypt-directories)) | ||
| 1417 | ;; An unknown method shall raise an error. | 1455 | ;; An unknown method shall raise an error. |
| 1418 | (let (non-essential) | 1456 | (let (non-essential) |
| 1419 | (should-error | 1457 | (should-error |
| @@ -2126,7 +2164,7 @@ is greater than 10. | |||
| 2126 | (when (assoc m tramp-methods) | 2164 | (when (assoc m tramp-methods) |
| 2127 | (let (tramp-connection-properties tramp-default-proxies-alist) | 2165 | (let (tramp-connection-properties tramp-default-proxies-alist) |
| 2128 | (ignore-errors | 2166 | (ignore-errors |
| 2129 | (tramp-cleanup-connection tramp-test-vec nil 'keep-password)) | 2167 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)) |
| 2130 | ;; Single hop. The host name must match `tramp-local-host-regexp'. | 2168 | ;; Single hop. The host name must match `tramp-local-host-regexp'. |
| 2131 | (should-error | 2169 | (should-error |
| 2132 | (find-file (format "/%s:foo:" m)) | 2170 | (find-file (format "/%s:foo:" m)) |
| @@ -4874,7 +4912,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4874 | (ert-deftest tramp-test26-interactive-file-name-completion () | 4912 | (ert-deftest tramp-test26-interactive-file-name-completion () |
| 4875 | "Check interactive completion with different `completion-styles'." | 4913 | "Check interactive completion with different `completion-styles'." |
| 4876 | ;; Method, user and host name in completion mode. | 4914 | ;; Method, user and host name in completion mode. |
| 4877 | (tramp-cleanup-connection tramp-test-vec nil 'keep-password) | 4915 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) |
| 4878 | 4916 | ||
| 4879 | (let ((method (file-remote-p ert-remote-temporary-file-directory 'method)) | 4917 | (let ((method (file-remote-p ert-remote-temporary-file-directory 'method)) |
| 4880 | (user (file-remote-p ert-remote-temporary-file-directory 'user)) | 4918 | (user (file-remote-p ert-remote-temporary-file-directory 'user)) |
| @@ -7028,7 +7066,7 @@ INPUT, if non-nil, is a string sent to the process." | |||
| 7028 | (file-remote-p (temporary-file-directory)))) | 7066 | (file-remote-p (temporary-file-directory)))) |
| 7029 | 7067 | ||
| 7030 | ;; The temporary file shall be located on the remote host. | 7068 | ;; The temporary file shall be located on the remote host. |
| 7031 | (setq tmp-file (make-nearby-temp-file "tramp-test")) | 7069 | (setq tmp-file (make-nearby-temp-file tramp-test-name-prefix)) |
| 7032 | (should (file-exists-p tmp-file)) | 7070 | (should (file-exists-p tmp-file)) |
| 7033 | (should (file-regular-p tmp-file)) | 7071 | (should (file-regular-p tmp-file)) |
| 7034 | (should | 7072 | (should |
| @@ -7038,7 +7076,7 @@ INPUT, if non-nil, is a string sent to the process." | |||
| 7038 | (delete-file tmp-file) | 7076 | (delete-file tmp-file) |
| 7039 | (should-not (file-exists-p tmp-file)) | 7077 | (should-not (file-exists-p tmp-file)) |
| 7040 | 7078 | ||
| 7041 | (setq tmp-file (make-nearby-temp-file "tramp-test" 'dir)) | 7079 | (setq tmp-file (make-nearby-temp-file tramp-test-name-prefix 'dir)) |
| 7042 | (should (file-exists-p tmp-file)) | 7080 | (should (file-exists-p tmp-file)) |
| 7043 | (should (file-directory-p tmp-file)) | 7081 | (should (file-directory-p tmp-file)) |
| 7044 | (delete-directory tmp-file) | 7082 | (delete-directory tmp-file) |
| @@ -7937,7 +7975,7 @@ process sentinels. They shall not disturb each other." | |||
| 7937 | 7975 | ||
| 7938 | (let ((pass "secret") | 7976 | (let ((pass "secret") |
| 7939 | (mock-entry (copy-tree (assoc "mock" tramp-methods))) | 7977 | (mock-entry (copy-tree (assoc "mock" tramp-methods))) |
| 7940 | mocked-input tramp-methods) | 7978 | mocked-input tramp-methods auth-sources) |
| 7941 | ;; We must mock `read-string', in order to avoid interactive | 7979 | ;; We must mock `read-string', in order to avoid interactive |
| 7942 | ;; arguments. | 7980 | ;; arguments. |
| 7943 | (cl-letf* (((symbol-function #'read-string) | 7981 | (cl-letf* (((symbol-function #'read-string) |
| @@ -7976,12 +8014,42 @@ process sentinels. They shall not disturb each other." | |||
| 7976 | (setq mocked-input nil) | 8014 | (setq mocked-input nil) |
| 7977 | (auth-source-forget-all-cached) | 8015 | (auth-source-forget-all-cached) |
| 7978 | (ert-with-temp-file netrc-file | 8016 | (ert-with-temp-file netrc-file |
| 7979 | :prefix "tramp-test" :suffix "" | 8017 | :prefix tramp-test-name-prefix :suffix "" |
| 7980 | :text (format | 8018 | :text (format |
| 7981 | "machine %s port mock password %s" | 8019 | "machine %s port mock password %s" |
| 7982 | (file-remote-p ert-remote-temporary-file-directory 'host) pass) | 8020 | (file-remote-p ert-remote-temporary-file-directory 'host) pass) |
| 7983 | (let ((auth-sources `(,netrc-file))) | 8021 | (let ((auth-sources `(,netrc-file))) |
| 7984 | (should (file-exists-p ert-remote-temporary-file-directory))))))))) | 8022 | (should (file-exists-p ert-remote-temporary-file-directory)))))) |
| 8023 | |||
| 8024 | ;; Checking session-timeout. | ||
| 8025 | (with-no-warnings (when (symbol-plist 'ert-with-temp-file) | ||
| 8026 | (tramp-cleanup-connection tramp-test-vec 'keep-debug) | ||
| 8027 | (let ((tramp-connection-properties | ||
| 8028 | (cons '(nil "session-timeout" 1) | ||
| 8029 | tramp-connection-properties))) | ||
| 8030 | (setq mocked-input nil) | ||
| 8031 | (auth-source-forget-all-cached) | ||
| 8032 | (ert-with-temp-file netrc-file | ||
| 8033 | :prefix tramp-test-name-prefix :suffix "" | ||
| 8034 | :text (format | ||
| 8035 | "machine %s port mock password %s" | ||
| 8036 | (file-remote-p ert-remote-temporary-file-directory 'host) | ||
| 8037 | pass) | ||
| 8038 | (let ((auth-sources `(,netrc-file))) | ||
| 8039 | (should (file-exists-p ert-remote-temporary-file-directory)))) | ||
| 8040 | ;; Session established, password cached. | ||
| 8041 | (should | ||
| 8042 | (password-in-cache-p | ||
| 8043 | (auth-source-format-cache-entry | ||
| 8044 | (tramp-get-connection-property tramp-test-vec " pw-spec")))) | ||
| 8045 | ;; We want to see the timeout message. | ||
| 8046 | (tramp--test-instrument-test-case 3 | ||
| 8047 | (sleep-for 2)) | ||
| 8048 | ;; Session cancelled, no password in cache. | ||
| 8049 | (should-not | ||
| 8050 | (password-in-cache-p | ||
| 8051 | (auth-source-format-cache-entry | ||
| 8052 | (tramp-get-connection-property tramp-test-vec " pw-spec")))))))))) | ||
| 7985 | 8053 | ||
| 7986 | (ert-deftest tramp-test47-read-otp-password () | 8054 | (ert-deftest tramp-test47-read-otp-password () |
| 7987 | "Check Tramp one-time password handling." | 8055 | "Check Tramp one-time password handling." |
| @@ -8033,7 +8101,7 @@ process sentinels. They shall not disturb each other." | |||
| 8033 | (setq mocked-input nil) | 8101 | (setq mocked-input nil) |
| 8034 | (auth-source-forget-all-cached) | 8102 | (auth-source-forget-all-cached) |
| 8035 | (ert-with-temp-file netrc-file | 8103 | (ert-with-temp-file netrc-file |
| 8036 | :prefix "tramp-test" :suffix "" | 8104 | :prefix tramp-test-name-prefix :suffix "" |
| 8037 | :text (format | 8105 | :text (format |
| 8038 | "machine %s port mock password %s" | 8106 | "machine %s port mock password %s" |
| 8039 | (file-remote-p ert-remote-temporary-file-directory 'host) | 8107 | (file-remote-p ert-remote-temporary-file-directory 'host) |