"Like `directory-file-name' for Tramp files."
;; If localname component of filename is "/", leave it unchanged.
;; Otherwise, remove any trailing slash from localname component.
- ;; Method, host, etc, are unchanged. Does it make sense to try
- ;; to avoid parsing the filename?
- (with-parsed-tramp-file-name directory nil
- (if (and (not (zerop (length localname)))
- (eq (aref localname (1- (length localname))) ?/)
- (not (string= localname "/")))
- (substring directory 0 -1)
- directory)))
+ ;; Method, host, etc, are unchanged.
+ (while (with-parsed-tramp-file-name directory nil
+ (and (not (zerop (length localname)))
+ (eq (aref localname (1- (length localname))) ?/)
+ (not (string= localname "/"))))
+ (setq directory (substring directory 0 -1)))
+ directory)
(defun tramp-handle-directory-files (directory &optional full match nosort)
"Like `directory-files' for Tramp files."
(t (tramp-make-tramp-file-name
method user domain host port "" hop)))))))))
+(defun tramp-handle-file-selinux-context (_filename)
+ "Like `file-selinux-context' for Tramp files."
+ ;; Return nil context.
+ '(nil nil nil nil))
+
(defun tramp-handle-file-symlink-p (filename)
"Like `file-symlink-p' for Tramp files."
(let ((x (tramp-compat-file-attribute-type (file-attributes filename))))
(string-equal
(directory-file-name "/method:host:/path/to/file/")
"/method:host:/path/to/file"))
+ (should
+ (string-equal
+ (directory-file-name "/method:host:/path/to/file//")
+ "/method:host:/path/to/file"))
(should
(string-equal
(file-name-as-directory "/method:host:/path/to/file")
;; There might be a summary line.
"\\(total.+[[:digit:]]+\n\\)?"
;; We don't know in which order ".", ".." and "foo" appear.
- "\\(.+ \\(\\.?\\.\\|foo\\)\n\\)\\{3\\}")))))
+ (format
+ "\\(.+ %s\\( ->.+\\)?\n\\)\\{%d\\}"
+ (regexp-opt (directory-files tmp-name1))
+ (length (directory-files tmp-name1))))))))
;; Cleanup.
(ignore-errors (delete-directory tmp-name1 'recursive))))))
;; Since Emacs 27.1.
(skip-unless (fboundp 'file-system-info))
- ;; `file-system-info' exists since Emacs 27. We don't
- ;; want to see compiler warnings for older Emacsen.
+ ;; `file-system-info' exists since Emacs 27. We don't want to see
+ ;; compiler warnings for older Emacsen.
(let ((fsi (with-no-warnings
(file-system-info tramp-test-temporary-file-directory))))
(skip-unless fsi)
(skip-unless (tramp--test-enabled))
(skip-unless (not (tramp--test-mock-p)))
- (let ((default-directory (expand-file-name temporary-file-directory)))
- (let ((code
- (format
- "(message \"Tramp loaded: %%s\" (consp (file-attributes \"%s\")))"
- tramp-test-temporary-file-directory)))
+ (let ((default-directory (expand-file-name temporary-file-directory))
+ (code
+ (format
+ "(message \"Tramp loaded: %%s\" (consp (file-attributes %S)))"
+ tramp-test-temporary-file-directory)))
+ (should
+ (string-match
+ "Tramp loaded: t[\n\r]+"
+ (shell-command-to-string
+ (format
+ "%s -batch -Q -L %s --eval %s"
+ (expand-file-name invocation-name invocation-directory)
+ (mapconcat 'shell-quote-argument load-path " -L ")
+ (shell-quote-argument code)))))))
+
+(ert-deftest tramp-test42-delay-load ()
+ "Check that Tramp is loaded lazily, only when needed."
+ ;; Tramp is neither loaded at Emacs startup, nor when completing a
+ ;; non-Tramp file name like "/foo". Completing a Tramp-alike file
+ ;; name like "/foo:" autoloads Tramp, when `tramp-mode' is t.
+ (let ((default-directory (expand-file-name temporary-file-directory))
+ (code
+ "(progn \
+ (setq tramp-mode %s) \
+ (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
+ (file-name-all-completions \"/foo\" \"/\") \
+ (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
+ (file-name-all-completions \"/foo:\" \"/\") \
+ (message \"Tramp loaded: %%s\" (featurep 'tramp)))"))
+ ;; Tramp doesn't load when `tramp-mode' is nil since Emacs 26.1.
+ (dolist (tm (if (tramp--test-emacs26-p) '(t nil) '(nil)))
(should
(string-match
- "Tramp loaded: t[\n\r]+"
+ (format
+ "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: %s[\n\r]+"
+ tm)
(shell-command-to-string
(format
"%s -batch -Q -L %s --eval %s"
(expand-file-name invocation-name invocation-directory)
(mapconcat 'shell-quote-argument load-path " -L ")
- (shell-quote-argument code))))))))
+ (shell-quote-argument (format code tm)))))))))
-(ert-deftest tramp-test43-recursive-load ()
+(ert-deftest tramp-test42-recursive-load ()
"Check that Tramp does not fail due to recursive load."
(skip-unless (tramp--test-enabled))
(mapconcat 'shell-quote-argument load-path " -L ")
(shell-quote-argument code))))))))
-(ert-deftest tramp-test44-remote-load-path ()
+(ert-deftest tramp-test42-remote-load-path ()
"Check that Tramp autoloads its packages with remote `load-path'."
;; `tramp-cleanup-all-connections' is autoloaded from tramp-cmds.el.
;; It shall still work, when a remote file name is in the
(mapconcat 'shell-quote-argument load-path " -L ")
(shell-quote-argument code)))))))
-(ert-deftest tramp-test45-delay-load ()
- "Check that Tramp is loaded lazily, only when needed."
- ;; Tramp is neither loaded at Emacs startup, nor when completing a
- ;; non-Tramp file name like "/foo". Completing a Tramp-alike file
- ;; name like "/foo:" autoloads Tramp, when `tramp-mode' is t.
- (let ((code
- "(progn \
- (setq tramp-mode %s) \
- (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
- (file-name-all-completions \"/foo\" \"/\") \
- (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
- (file-name-all-completions \"/foo:\" \"/\") \
- (message \"Tramp loaded: %%s\" (featurep 'tramp)))"))
- ;; Tramp doesn't load when `tramp-mode' is nil since Emacs 26.1.
- (dolist (tm (if (tramp--test-emacs26-p) '(t nil) '(nil)))
- (should
- (string-match
- (format
- "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: %s[\n\r]+"
- tm)
- (shell-command-to-string
- (format
- "%s -batch -Q -L %s --eval %s"
- (expand-file-name invocation-name invocation-directory)
- (mapconcat 'shell-quote-argument load-path " -L ")
- (shell-quote-argument (format code tm)))))))))
-
-(ert-deftest tramp-test46-unload ()
+(ert-deftest tramp-test43-unload ()
"Check that Tramp and its subpackages unload completely.
Since it unloads Tramp, it shall be the last test to run."
:tags '(:expensive-test)
(ignore-errors (all-completions "tramp" (symbol-value x)))
(ert-fail (format "Hook `%s' still contains Tramp function" x)))))))
+(defun tramp-test-all (&optional interactive)
+ "Run all tests for \\[tramp]."
+ (interactive "p")
+ (funcall
+ (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
+
;; TODO:
;; * dired-compress-file
;; * Fix `tramp-test30-interrupt-process', timeout doesn't work reliably.
;; * Fix Bug#16928 in `tramp-test41-asynchronous-requests'.
-(defun tramp-test-all (&optional interactive)
- "Run all tests for \\[tramp]."
- (interactive "p")
- (funcall
- (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
-
(provide 'tramp-tests)
;;; tramp-tests.el ends here