]> git.eshelyaron.com Git - emacs.git/commitdiff
Harden ert-resource-directory against errors
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 27 Oct 2021 14:04:31 +0000 (16:04 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 27 Oct 2021 14:04:31 +0000 (16:04 +0200)
* lisp/emacs-lisp/ert-x.el (ert-resource-directory): Be more
resilient -- don't bug out if called from a file that's not
visiting a directory.

lisp/emacs-lisp/ert-x.el

index 3fc57d5182df9ae502669822b86eb53384e4a25d..a492ef5093fca0a1a61f86e915ff02b11deea7d1 100644 (file)
@@ -368,17 +368,17 @@ variable `ert-resource-directory-format'.  Before formatting, the
 file name will be trimmed using `string-trim' with arguments
 `ert-resource-directory-trim-left-regexp' and
 `ert-resource-directory-trim-right-regexp'."
-  `(let* ((testfile ,(or (macroexp-file-name)
-                         buffer-file-name))
-          (default-directory (file-name-directory testfile)))
-     (file-truename
-      (if (file-accessible-directory-p "resources/")
-          (expand-file-name "resources/")
-        (expand-file-name
-         (format ert-resource-directory-format
-                 (string-trim testfile
-                              ert-resource-directory-trim-left-regexp
-                              ert-resource-directory-trim-right-regexp)))))))
+  `(when-let ((testfile ,(or (macroexp-file-name)
+                             buffer-file-name)))
+     (let ((default-directory (file-name-directory testfile)))
+       (file-truename
+        (if (file-accessible-directory-p "resources/")
+            (expand-file-name "resources/")
+          (expand-file-name
+           (format ert-resource-directory-format
+                   (string-trim testfile
+                                ert-resource-directory-trim-left-regexp
+                                ert-resource-directory-trim-right-regexp))))))))
 
 (defmacro ert-resource-file (file)
   "Return absolute file name of resource (test data) file named FILE.