diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-03 19:10:44 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-03 19:10:44 -0500 |
| commit | 9acaf3899aedb69300a29a0d0c8b468e5f4ad729 (patch) | |
| tree | e6b4371107685f0a7225876b882145fbc363347d /tests | |
| parent | 475d6305e150c0a8ac61738eabe434c432acd991 (diff) | |
| download | dotemacs-9acaf3899aedb69300a29a0d0c8b468e5f4ad729.tar.gz dotemacs-9acaf3899aedb69300a29a0d0c8b468e5f4ad729.zip | |
fix: expand local ELPA mirror paths with expand-file-name
`(concat user-home-dir ".elpa-mirrors/")` was producing `/home/cjennings.elpa-mirrors/` because `getenv HOME` doesn't return a trailing slash on Linux. The local mirrors were silently dropping out of `package-archives` because `file-accessible-directory-p` couldn't find the bogus path.
I replaced the `concat` calls for `elpa-mirror-location` and `localrepo-location` with `expand-file-name`, which handles the slash for us. I also lifted the four per-archive subdirs into their own constants (`elpa-mirror-gnu-location`, `nongnu`, `melpa`, `stable-melpa`) so the archive registration block stops splicing `concat` strings inline.
I added `tests/test-early-init-paths.el`. It loads `early-init.el` against a temp HOME with the package side effects stubbed and asserts each constant and each `package-archives` entry resolves to the right path.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-early-init-paths.el | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/test-early-init-paths.el b/tests/test-early-init-paths.el new file mode 100644 index 00000000..2051da73 --- /dev/null +++ b/tests/test-early-init-paths.el @@ -0,0 +1,101 @@ +;;; test-early-init-paths.el --- Tests for early-init path construction -*- lexical-binding: t; -*- + +;;; Commentary: + +;; Load early-init.el with package side effects stubbed so path construction can +;; be tested without touching real package archives or the network. + +;;; Code: + +(require 'cl-lib) +(require 'ert) +(require 'package) + +(defvar cj/use-online-repos nil + "Test binding for early-init online repository setup.") + +(defconst test-early-init-paths--repo-root + (file-name-directory + (directory-file-name + (file-name-directory (or load-file-name buffer-file-name)))) + "Repository root for early-init path tests.") + +(defun test-early-init-paths--load-with-temp-home (home emacs-home) + "Load early-init.el with HOME and EMACS-HOME as isolated roots." + (let ((process-environment (copy-sequence process-environment)) + (user-emacs-directory (file-name-as-directory emacs-home)) + (package-user-dir (expand-file-name "elpa/" emacs-home)) + (package-archives nil) + (package-archive-priorities nil) + (debug-on-error nil) + (debug-on-quit nil)) + (setq cj/use-online-repos nil) + (setenv "HOME" home) + (cl-letf (((symbol-function 'package-initialize) #'ignore) + ((symbol-function 'package-installed-p) (lambda (_package) t)) + ((symbol-function 'package-refresh-contents) #'ignore) + ((symbol-function 'package-install) #'ignore)) + (load (expand-file-name "early-init.el" test-early-init-paths--repo-root) nil t)) + (list :user-home-dir user-home-dir + :elpa-mirror-location elpa-mirror-location + :localrepo-location localrepo-location + :gnu elpa-mirror-gnu-location + :nongnu elpa-mirror-nongnu-location + :melpa elpa-mirror-melpa-location + :stable-melpa elpa-mirror-stable-melpa-location + :package-archives package-archives + :package-archive-priorities package-archive-priorities))) + +(ert-deftest test-early-init-paths-normal-expanded-under-home () + "Normal: local mirror paths expand under HOME, not beside it." + (let* ((home (make-temp-file "early-init-home-" t)) + (emacs-home (make-temp-file "early-init-emacs-" t)) + (_ (dolist (dir '(".localrepo" + ".elpa-mirrors/gnu" + ".elpa-mirrors/nongnu" + ".elpa-mirrors/melpa" + ".elpa-mirrors/stable-melpa")) + (make-directory (expand-file-name dir emacs-home) t))) + ;; Mirror directories intentionally live under HOME, while .localrepo + ;; lives under user-emacs-directory. + (_ (dolist (dir '(".elpa-mirrors/gnu" + ".elpa-mirrors/nongnu" + ".elpa-mirrors/melpa" + ".elpa-mirrors/stable-melpa")) + (make-directory (expand-file-name dir home) t))) + (result (test-early-init-paths--load-with-temp-home home emacs-home))) + (should (string= (plist-get result :user-home-dir) home)) + (should (string= (plist-get result :elpa-mirror-location) + (expand-file-name ".elpa-mirrors/" home))) + (should (string= (plist-get result :localrepo-location) + (expand-file-name ".localrepo/" emacs-home))) + (should (string= (plist-get result :gnu) + (expand-file-name ".elpa-mirrors/gnu/" home))) + (should-not (string= (plist-get result :elpa-mirror-location) + (concat home ".elpa-mirrors/"))))) + +(ert-deftest test-early-init-paths-normal-local-archives-use-expanded-paths () + "Normal: local package archives use expanded path constants." + (let* ((home (make-temp-file "early-init-home-" t)) + (emacs-home (make-temp-file "early-init-emacs-" t))) + (make-directory (expand-file-name ".localrepo/" emacs-home) t) + (dolist (dir '(".elpa-mirrors/gnu" + ".elpa-mirrors/nongnu" + ".elpa-mirrors/melpa" + ".elpa-mirrors/stable-melpa")) + (make-directory (expand-file-name dir home) t)) + (let* ((result (test-early-init-paths--load-with-temp-home home emacs-home)) + (archives (plist-get result :package-archives))) + (should (equal (cdr (assoc "localrepo" archives)) + (expand-file-name ".localrepo/" emacs-home))) + (should (equal (cdr (assoc "gnu-local" archives)) + (expand-file-name ".elpa-mirrors/gnu/" home))) + (should (equal (cdr (assoc "nongnu-local" archives)) + (expand-file-name ".elpa-mirrors/nongnu/" home))) + (should (equal (cdr (assoc "melpa-local" archives)) + (expand-file-name ".elpa-mirrors/melpa/" home))) + (should (equal (cdr (assoc "melpa-stable-local" archives)) + (expand-file-name ".elpa-mirrors/stable-melpa/" home)))))) + +(provide 'test-early-init-paths) +;;; test-early-init-paths.el ends here |
