aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-16 17:14:01 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-16 17:14:01 +0100
commit74ec2c1c56ec178ac5b4cd47fb3b7837ebb8f942 (patch)
tree1abb7dad07106e343e67aacdd1b5041fb1e66e21
parent041122b3057752a761f2e54b5d52adcd2136f8ad (diff)
Add test for make-nearby-temp-file
-rw-r--r--compat-26.el2
-rw-r--r--compat-27.el44
-rw-r--r--compat-tests.el18
3 files changed, 44 insertions, 20 deletions
diff --git a/compat-26.el b/compat-26.el
index 0670851..3502f66 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -368,7 +368,7 @@ the variable `temporary-file-directory' is returned."
default-directory
temporary-file-directory))))
-(compat-defun make-nearby-temp-file (prefix &optional dir-flag suffix) ;; <UNTESTED>
+(compat-defun make-nearby-temp-file (prefix &optional dir-flag suffix) ;; <compat-tests:make-nearby-temp-file>
"Create a temporary file as close as possible to `default-directory'.
If PREFIX is a relative file name, and `default-directory' is a
remote file name or located on a mounted file systems, the
diff --git a/compat-27.el b/compat-27.el
index 0dbad6e..04c4b5b 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -419,25 +419,31 @@ 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'."
- ;; 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))
+ (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)))
(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 f1b630f..d8aab1c 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1232,15 +1232,33 @@
(should-equal t (always 1)) ;; single argument
(should-equal t (always 1 2 3 4))) ;; multiple arguments
+(ert-deftest make-nearby-temp-file ()
+ ;; TODO Test tramp remote directory.
+ (let ((file1 (make-nearby-temp-file "compat-tests"))
+ (file2 (make-nearby-temp-file "compat-tests" nil "suffix"))
+ (dir (make-nearby-temp-file "compat-tests" t)))
+ (should (string-suffix-p "suffix" file2))
+ (should (file-regular-p file1))
+ (should (file-regular-p file2))
+ (should (file-directory-p dir))
+ (should-equal (file-name-directory file1) temporary-file-directory)
+ (should-equal (file-name-directory file2) temporary-file-directory)
+ (should-equal (file-name-directory dir) temporary-file-directory)
+ (delete-file file1)
+ (delete-file file2)
+ (delete-directory dir)))
+
(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 Test tramp remote directory.
(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)
+ ;; TODO Test tramp remote directory.
(let ((default-directory (format "/sudo:%s@localhost:/" user-login-name)))
(should (file-directory-p (car (exec-path))))))