aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compat-27.el46
-rw-r--r--compat-tests.el11
2 files changed, 28 insertions, 29 deletions
diff --git a/compat-27.el b/compat-27.el
index 41686f3..0dbad6e 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -413,37 +413,31 @@ in all cases, since that is the standard symbol for byte."
(if (string= prefixed-unit "") "" (or space ""))
prefixed-unit))))
-(compat-defun exec-path () ;; <UNTESTED>
+(compat-defun exec-path () ;; <compat-tests:exec-path>
"Return list of directories to search programs to run in remote subprocesses.
The remote host is identified by `default-directory'. For remote
hosts that do not support subprocesses, this returns nil.
If `default-directory' is a local directory, this function returns
the value of the variable `exec-path'."
- (cond
- ((let ((handler (find-file-name-handler default-directory 'exec-path)))
- ;; FIXME: The handler was added in 27.1, and this compatibility
- ;; function only applies to versions of Emacs before that.
- (when handler
- (condition-case nil
- (funcall handler 'exec-path)
- (error nil)))))
- ((file-remote-p default-directory)
- ;; TODO: This is not completely portable, even if "sh" and
- ;; "getconf" should be provided on every POSIX system, the chance
- ;; of this not working are greater than zero.
- ;;
- ;; FIXME: This invokes a shell process every time exec-path is
- ;; called. It should instead be cached on a host-local basis.
- (with-temp-buffer
- (if (condition-case nil
- (zerop (process-file "sh" nil t nil "-c" "getconf PATH"))
- (file-missing t))
- (list "/bin" "/usr/bin")
- (let (path)
- (while (re-search-forward "\\([^:]+?\\)[\n:]" nil t)
- (push (match-string 1) path))
- (nreverse path)))))
- (exec-path)))
+ ;; NOTE: We cannot use the 'exec-path file name handler here since it didn't
+ ;; exist before Emacs 27.1.
+ (if (file-remote-p default-directory)
+ ;; TODO: This is not completely portable, even if "sh" and
+ ;; "getconf" should be provided on every POSIX system, the chance
+ ;; of this not working are greater than zero.
+ ;;
+ ;; FIXME: This invokes a shell process every time exec-path is
+ ;; called. It should instead be cached on a host-local basis.
+ (with-temp-buffer
+ (if (condition-case nil
+ (zerop (process-file "sh" nil t nil "-c" "getconf PATH"))
+ (file-missing t))
+ (list "/bin" "/usr/bin")
+ (let (path)
+ (while (re-search-forward "\\([^:]+?\\)[\n:]" nil t)
+ (push (match-string 1) path))
+ (nreverse path))))
+ exec-path))
(compat-defun executable-find (command &optional remote) ;; <compat-tests:executable-find>
"Search for COMMAND in `exec-path' and return the absolute file name.
diff --git a/compat-tests.el b/compat-tests.el
index 5d035f5..f1b630f 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1235,9 +1235,14 @@
(ert-deftest executable-find ()
(should (member (executable-find "sh") '("/usr/bin/sh" "/bin/sh")))
(should (member (executable-find "ls") '("/usr/bin/ls" "/bin/ls")))
- ;; TODO These dummy calls are executed locally, test Tramp!
- (should (member (compat-call executable-find "sh" t) '("/usr/bin/sh" "/bin/sh")))
- (should (member (compat-call executable-find "ls" t) '("/usr/bin/ls" "/bin/ls"))))
+ (let ((default-directory (format "/sudo:%s@localhost:/" user-login-name)))
+ (should (member (compat-call executable-find "sh" t) '("/usr/bin/sh" "/bin/sh")))
+ (should (member (compat-call executable-find "ls" t) '("/usr/bin/ls" "/bin/ls")))))
+
+(ert-deftest exec-path ()
+ (should-equal (exec-path) exec-path)
+ (let ((default-directory (format "/sudo:%s@localhost:/" user-login-name)))
+ (should (file-directory-p (car (exec-path))))))
(ert-deftest with-existing-directory ()
(let ((dir (make-temp-name "/tmp/not-exist-")))