(when (stringp res) (file-local-name res)))
;; Use 1 rather than file-executable-p to better match the
;; behavior of call-process.
- (locate-file command exec-path exec-suffixes 1)))
+ (let ((default-directory (file-name-quote default-directory 'top)))
+ (locate-file command exec-path exec-suffixes 1))))
(defun load-library (library)
"Load the Emacs Lisp library named LIBRARY.
process-environment)))
(should (equal old (file-truename (abbreviate-file-name testfile))))))
+(ert-deftest files-tests-executable-find ()
+ "Test that `executable-find' works also with a relative or remote PATH.
+See <https://debbugs.gnu.org/35241>."
+ (let ((tmpfile (make-temp-file "files-test")))
+ (unwind-protect
+ (progn
+ (set-file-modes tmpfile #o777)
+ (let ((exec-path `(,temporary-file-directory)))
+ (should
+ (equal tmpfile
+ (executable-find (file-name-nondirectory tmpfile)))))
+ ;; An empty element of `exec-path' means `default-directory'.
+ (let ((default-directory temporary-file-directory)
+ (exec-path nil))
+ (should
+ (equal tmpfile
+ (executable-find (file-name-nondirectory tmpfile)))))
+ ;; The remote file name shall be quoted, and handled like a
+ ;; non-existing directory.
+ (let ((default-directory "/ssh::")
+ (exec-path (append exec-path `("." ,temporary-file-directory))))
+ (should
+ (equal tmpfile
+ (executable-find (file-name-nondirectory tmpfile))))))
+ (delete-file tmpfile))))
+
(provide 'files-tests)
;;; files-tests.el ends here