]> git.eshelyaron.com Git - emacs.git/commitdiff
Add test for 'locate-user-emacs-file'
authorStefan Kangas <stefankangas@gmail.com>
Sat, 8 Mar 2025 11:23:50 +0000 (12:23 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 12 Mar 2025 18:46:56 +0000 (19:46 +0100)
* test/lisp/files-tests.el
(files-test-locate-user-emacs-file): New test.

(cherry picked from commit 9c6e8589ee5eae0f793994c96d434b77f54749de)

test/lisp/files-tests.el

index 0e4f649d3d10124857d7d6cc36f9e44caa792bcc..ed63b6f6fb48d02e14983e4e91e37c11145d5c08 100644 (file)
 (defun files-test-fun1 ()
   (setq files-test-result t))
 
+(ert-deftest files-test-locate-user-emacs-file ()
+  (ert-with-temp-directory home
+    (with-environment-variables (("HOME" home))
+      (let* ((user-emacs-directory (expand-file-name ".emacs.d/" home)))
+        (make-directory user-emacs-directory 'parents)
+        (should-error (locate-user-emacs-file nil "any-file")
+                      :type 'wrong-type-argument)
+        ;; No file exists.
+        (should (equal (locate-user-emacs-file "always")
+                       (expand-file-name "always" user-emacs-directory)))
+        (should (equal (locate-user-emacs-file "always" "never")
+                       (expand-file-name "always" user-emacs-directory)))
+        ;; Only the file in $HOME/.conf exists.
+        (let ((exists (expand-file-name "exists" home)))
+          (write-region "data" nil exists nil 'quietly)
+          (should (equal (locate-user-emacs-file "missing" "exists")
+                         exists)))
+        ;; Only the file in ~/.emacs.d/ exists.
+        (let ((exists (expand-file-name "exists" user-emacs-directory)))
+          (write-region "data" nil exists nil 'quietly)
+          (should (equal (locate-user-emacs-file "exists" "missing")
+                         exists)))
+        ;; Both files exist.
+        (let* ((basename "testconfig")
+               (in-home (expand-file-name basename home))
+               (in-edir (expand-file-name basename user-emacs-directory)))
+          (write-region "data" nil in-home nil 'quietly)
+          (write-region "data" nil in-edir nil 'quietly)
+          (should (equal (locate-user-emacs-file basename)
+                         in-edir))
+          (should (equal (locate-user-emacs-file basename "anything")
+                         in-edir)))))))
+
 ;; Test combinations:
 ;; `enable-local-variables' t, nil, :safe, :all, or something else.
 ;; `enable-local-eval' t, nil, or something else.