Improve error message for missing home directory in Tramp

* lisp/net/tramp-sh.el (tramp-open-shell): Improve check for
`tramp-histfile-override'.  (Bug#81799)

* test/lisp/net/tramp-archive-tests.el (tramp-archive-test51-auto-load)
(tramp-archive-test51-delay-load)
(tramp-archive-test52-without-remote-files): Rename.

* test/lisp/net/tramp-tests.el (tramp--test-box-p): Adapt docstring.
(tramp-test45-home-directory): New test.
(tramp-test46-asynchronous-requests)
(tramp-test46-force-remote-file-error)
(tramp-test47-dired-compress-file)
(tramp-test47-dired-compress-dir)
(tramp-test47-file-notifications, tramp-test48-read-password)
(tramp-test48-read-otp-password, tramp-test48-read-security-key)
(tramp-test48-read-fingerprint, tramp-test49-session-timeout)
(tramp-test50-external-backend-function, tramp-test51-auto-load)
(tramp-test51-delay-load, tramp-test51-recursive-load)
(tramp-test51-remote-load-path)
(tramp-test52-without-remote-files, tramp-test53-unload): Rename.
This commit is contained in:
Michael Albinus 2026-09-07 15:02:09 +02:00
parent c51fa25fb1
commit ddb09cb965
3 changed files with 74 additions and 38 deletions

View file

@ -4444,16 +4444,21 @@ file exists and nonzero exit status otherwise."
(tramp-wait-for-output (tramp-get-connection-process vec))
;; Check proper HISTFILE setting. We give up when not working.
(when (and (stringp tramp-histfile-override)
(file-name-directory tramp-histfile-override))
(tramp-barf-unless-okay
vec
(format
"(cd %s)"
(tramp-shell-quote-argument
(file-name-directory tramp-histfile-override)))
"`tramp-histfile-override' uses invalid file `%s'"
tramp-histfile-override))
(when (stringp tramp-histfile-override)
(when (and (string-match-p "~" tramp-histfile-override)
(or (not (tramp-get-home-directory vec))
(not (file-directory-p (tramp-get-home-directory vec)))))
(tramp-user-error
vec "No home directory, change `tramp-histfile-override'"))
(when (file-name-directory tramp-histfile-override)
(tramp-barf-unless-okay
vec
(format
"(cd %s)"
(tramp-shell-quote-argument
(file-name-directory tramp-histfile-override)))
"`tramp-histfile-override' uses invalid file `%s'"
tramp-histfile-override)))
(tramp-flush-connection-property
(tramp-get-connection-process vec) "scripts")

View file

@ -925,7 +925,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
(tramp-archive--test-deftest-cascaded tramp-archive-test44-user-group-ids)
(ert-deftest tramp-archive-test50-auto-load ()
(ert-deftest tramp-archive-test51-auto-load ()
"Check that `tramp-archive' autoloads properly."
:tags '(:expensive-test)
(skip-unless tramp-archive-enabled)
@ -967,7 +967,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
(format "(setq tramp-archive-enabled %s)" enabled))
(shell-quote-argument (format code file)))))))))))
(ert-deftest tramp-archive-test50-delay-load ()
(ert-deftest tramp-archive-test51-delay-load ()
"Check that `tramp-archive' is loaded lazily, only when needed."
:tags '(:expensive-test)
(skip-unless tramp-archive-enabled)
@ -1006,7 +1006,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
code tae tramp-archive-test-file-archive
(concat tramp-archive-test-archive "foo"))))))))))
(ert-deftest tramp-archive-test51-without-remote-files ()
(ert-deftest tramp-archive-test52-without-remote-files ()
"Check that Tramp can be suppressed."
(skip-unless tramp-archive-enabled)

View file

@ -41,7 +41,7 @@
;; This shouldn't be set if the test suite runs in parallel using
;; Tramp on a production system.
;; For slow remote connections, `tramp-test45-asynchronous-requests'
;; For slow remote connections, `tramp-test46-asynchronous-requests'
;; might be too heavy. Setting $REMOTE_PARALLEL_PROCESSES to a proper
;; value less than 10 could help.
@ -7688,7 +7688,7 @@ This is used in tests which we don't want to tag
(defun tramp--test-box-p ()
"Check, whether the toolbox or distrobox method is used.
This does not support `tramp-test45-asynchronous-requests'."
This does not support `tramp-test46-asynchronous-requests'."
(string-match-p
(rx bol (| "toolbox" "distrobox") eol)
(file-remote-p ert-remote-temporary-file-directory 'method)))
@ -8317,14 +8317,46 @@ should all return proper values."
(should (consp groups))
(dolist (group groups) (should (stringp group)))))))
;; `tramp-test45-asynchronous-requests' could be blocked. So we set a
;; This test is inspired by Bug#81799.
(ert-deftest tramp-test45-home-directory ()
"Test remote home directory."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
(skip-unless (tramp-get-home-directory tramp-test-vec))
(should
(string-equal
(tramp-get-home-directory tramp-test-vec)
(file-local-name
(expand-file-name
(concat (file-remote-p ert-remote-temporary-file-directory) "~")))))
(should
(string-equal
(tramp-get-home-directory
tramp-test-vec (file-remote-p ert-remote-temporary-file-directory 'user))
(file-local-name
(expand-file-name
(concat
(file-remote-p ert-remote-temporary-file-directory) "~"
(file-remote-p ert-remote-temporary-file-directory 'user))))))
;; There shall be a user-error if `tramp-histfile-override' isn't proper.
(when (tramp--test-sh-p)
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
(cl-letf* (((symbol-function #'tramp-get-home-directory) #'ignore))
(let ((tramp-histfile-override (default-value 'tramp-histfile-override)))
(should-error
(file-truename ert-remote-temporary-file-directory)
:type 'user-error)))))
;; `tramp-test46-asynchronous-requests' could be blocked. So we set a
;; timeout of 300 seconds, and we send a SIGUSR1 signal after 300
;; seconds. Similar check is performed in the timer function.
(defconst tramp--test-asynchronous-requests-timeout 300
"Timeout for `tramp-test45-asynchronous-requests'.")
"Timeout for `tramp-test46-asynchronous-requests'.")
;; This test is inspired by Bug#16928.
(ert-deftest tramp-test45-asynchronous-requests ()
(ert-deftest tramp-test46-asynchronous-requests ()
"Check parallel asynchronous requests.
Such requests could arrive from timers, process filters and
process sentinels. They shall not disturb each other."
@ -8514,11 +8546,11 @@ process sentinels. They shall not disturb each other."
(ignore-errors (cancel-timer timer))
(ignore-errors (delete-directory tmp-name 'recursive))))))
;; (tramp--test-deftest-direct-async-process tramp-test45-asynchronous-requests
;; (tramp--test-deftest-direct-async-process tramp-test46-asynchronous-requests
;; 'unstable)
;; This test is inspired by Bug#49954 and Bug#60534.
(ert-deftest tramp-test45-force-remote-file-error ()
(ert-deftest tramp-test46-force-remote-file-error ()
"Force `remote-file-error'."
:tags '(:expensive-test :tramp-asynchronous-processes :unstable)
;; It shall run only if selected explicitly.
@ -8553,7 +8585,7 @@ process sentinels. They shall not disturb each other."
(directory-files default-directory)
(dired-uncache default-directory))))
(ert-deftest tramp-test46-dired-compress-file ()
(ert-deftest tramp-test47-dired-compress-file ()
"Check that Tramp (un)compresses normal files."
(skip-unless (tramp--test-enabled))
(skip-unless (tramp--test-sh-p))
@ -8574,7 +8606,7 @@ process sentinels. They shall not disturb each other."
(should (string= tmp-name (dired-get-filename)))
(delete-file tmp-name)))
(ert-deftest tramp-test46-dired-compress-dir ()
(ert-deftest tramp-test47-dired-compress-dir ()
"Check that Tramp (un)compresses directories."
(skip-unless (tramp--test-enabled))
(skip-unless (tramp--test-sh-p))
@ -8598,7 +8630,7 @@ process sentinels. They shall not disturb each other."
;; More exhaustive tests are performed in filenotify-tests.el,
;; selector "remote".
(ert-deftest tramp-test46-file-notifications ()
(ert-deftest tramp-test47-file-notifications ()
"Check that Tramp handles file notifications."
:tags '(:unstable)
(skip-unless (tramp--test-enabled))
@ -8652,7 +8684,7 @@ process sentinels. They shall not disturb each other."
(when (fboundp 'file-notify-rm-all-watches)
(with-no-warnings (file-notify-rm-all-watches))))))
(ert-deftest tramp-test47-read-password ()
(ert-deftest tramp-test48-read-password ()
"Check Tramp password handling."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
@ -8743,7 +8775,7 @@ process sentinels. They shall not disturb each other."
;; Cleanup.
(tramp-cleanup-connection tramp-test-vec 'keep-debug))
(ert-deftest tramp-test47-read-otp-password ()
(ert-deftest tramp-test48-read-otp-password ()
"Check Tramp one-time password handling."
:tags '(:expensive-test)
(skip-unless (tramp--test-mock-p))
@ -8804,7 +8836,7 @@ process sentinels. They shall not disturb each other."
;; Cleanup.
(tramp-cleanup-connection tramp-test-vec 'keep-debug))
(ert-deftest tramp-test47-read-security-key ()
(ert-deftest tramp-test48-read-security-key ()
"Check Tramp security key handling."
:tags '(:expensive-test)
(skip-unless (tramp--test-mock-p))
@ -8880,7 +8912,7 @@ process sentinels. They shall not disturb each other."
;; Cleanup.
(tramp-cleanup-connection tramp-test-vec 'keep-debug))
(ert-deftest tramp-test47-read-fingerprint ()
(ert-deftest tramp-test48-read-fingerprint ()
"Check Tramp fingerprint handling."
:tags '(:expensive-test)
(skip-unless (tramp--test-mock-p))
@ -8927,7 +8959,7 @@ process sentinels. They shall not disturb each other."
(tramp-cleanup-connection tramp-test-vec 'keep-debug))
;; This test is inspired by Bug#78572.
(ert-deftest tramp-test48-session-timeout ()
(ert-deftest tramp-test49-session-timeout ()
"Check that Tramp handles a session timeout properly."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
@ -9017,7 +9049,7 @@ process sentinels. They shall not disturb each other."
"Helper function for `tramp--test-operation' handler."
default-directory)
(ert-deftest tramp-test49-external-backend-function ()
(ert-deftest tramp-test50-external-backend-function ()
"Check that Tramp handles external functions for a given backend."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
@ -9244,7 +9276,7 @@ process sentinels. They shall not disturb each other."
(tramp--handle-test-operation "foo"))))))
;; This test is inspired by Bug#29163.
(ert-deftest tramp-test50-auto-load ()
(ert-deftest tramp-test51-auto-load ()
"Check that Tramp autoloads properly."
;; If we use another syntax but `default', Tramp is already loaded
;; due to the `tramp-change-syntax' call.
@ -9269,7 +9301,7 @@ process sentinels. They shall not disturb each other."
(mapconcat #'shell-quote-argument load-path " -L ")
(shell-quote-argument code)))))))
(ert-deftest tramp-test50-delay-load ()
(ert-deftest tramp-test51-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
@ -9299,7 +9331,7 @@ process sentinels. They shall not disturb each other."
(mapconcat #'shell-quote-argument load-path " -L ")
(shell-quote-argument (format code tm)))))))))
(ert-deftest tramp-test50-recursive-load ()
(ert-deftest tramp-test51-recursive-load ()
"Check that Tramp does not fail due to recursive load."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
@ -9324,7 +9356,7 @@ process sentinels. They shall not disturb each other."
(mapconcat #'shell-quote-argument load-path " -L ")
(shell-quote-argument code))))))))
(ert-deftest tramp-test50-remote-load-path ()
(ert-deftest tramp-test51-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
@ -9349,7 +9381,7 @@ process sentinels. They shall not disturb each other."
(mapconcat #'shell-quote-argument load-path " -L ")
(shell-quote-argument code)))))))
(ert-deftest tramp-test51-without-remote-files ()
(ert-deftest tramp-test52-without-remote-files ()
"Check that Tramp can be suppressed."
(skip-unless (tramp--test-enabled))
@ -9364,7 +9396,7 @@ process sentinels. They shall not disturb each other."
(setq tramp-mode t)
(should (file-remote-p ert-remote-temporary-file-directory)))
(ert-deftest tramp-test52-unload ()
(ert-deftest tramp-test53-unload ()
"Check that Tramp and its subpackages unload completely.
Since it unloads Tramp, it shall be the last test to run."
:tags '(:expensive-test)
@ -9465,7 +9497,6 @@ If INTERACTIVE is non-nil, the tests are run interactively."
;; * file-equal-p (partly done in `tramp-test21-file-links')
;; * file-in-directory-p
;; * file-name-case-insensitive-p
;; * tramp-get-home-directory
;; * tramp-set-file-uid-gid
;; * Work on skipped tests. Make a comment, when it is impossible.
@ -9482,10 +9513,10 @@ If INTERACTIVE is non-nil, the tests are run interactively."
;; `tramp-test31-signal-process' for "adb", "sshfs" and for direct
;; async processes. Check, why they don't run stable.
;; * Fix the limitations for "smb" in `tramp--test-check-files'.
;; * Check, why `tramp-test45-asynchronous-requests' often fails. The
;; * Check, why `tramp-test46-asynchronous-requests' often fails. The
;; famous reentrant error?
;; * Check, why direct async processes do not work for
;; `tramp-test45-asynchronous-requests'.
;; `tramp-test46-asynchronous-requests'.
;; Use `skip-when' starting with Emacs 30.1.