From: Stefan Kangas Date: Sat, 8 Mar 2025 11:23:50 +0000 (+0100) Subject: Add test for 'locate-user-emacs-file' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6bbfc69f4f0539dc8b4fdd54aba9eee4bc5e30a6;p=emacs.git Add test for 'locate-user-emacs-file' * test/lisp/files-tests.el (files-test-locate-user-emacs-file): New test. (cherry picked from commit 9c6e8589ee5eae0f793994c96d434b77f54749de) --- diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 0e4f649d3d1..ed63b6f6fb4 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -37,6 +37,39 @@ (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.