diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-25 17:00:15 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-25 17:00:15 -0500 |
| commit | c83b13ea891d034190b7b8582ce45f2bfaf84f40 (patch) | |
| tree | 24eaf61c32566673af4acad04c42706379c9580f | |
| parent | 9aa180ea57f79f79c156a0956677e13c5263b478 (diff) | |
| download | dotemacs-c83b13ea891d034190b7b8582ce45f2bfaf84f40.tar.gz dotemacs-c83b13ea891d034190b7b8582ce45f2bfaf84f40.zip | |
test(system-defaults): cover custom-file, backups, and GC-hook registration
system-defaults.el had no coverage for its settings, only its functions (in test-system-defaults-functions.el) and the vc-follow-symlinks default. I added three settings smoke tests: custom-file is redirected to a temp trashbin rather than the repo, backups land under user-emacs-directory/backups, and the minibuffer GC hooks are actually wired onto the minibuffer hooks.
I pulled the sandbox loader the vc-follow-symlinks test had inline into tests/testutil-system-defaults.el so both files share one copy. The backups test clears cj/backup-directory before loading — it's a defvar, so once an earlier test loads the module it keeps that first sandbox path and won't recompute, which made the assertion fail until I forced the recompute.
| -rw-r--r-- | tests/test-system-defaults-vc-follow-symlinks.el | 54 | ||||
| -rw-r--r-- | tests/test-system-defaults.el | 68 | ||||
| -rw-r--r-- | tests/testutil-system-defaults.el | 69 |
3 files changed, 142 insertions, 49 deletions
diff --git a/tests/test-system-defaults-vc-follow-symlinks.el b/tests/test-system-defaults-vc-follow-symlinks.el index 34406986..e8966d7b 100644 --- a/tests/test-system-defaults-vc-follow-symlinks.el +++ b/tests/test-system-defaults-vc-follow-symlinks.el @@ -7,60 +7,16 @@ ;;; Code: -(require 'cl-lib) -(require 'autorevert) -(require 'bookmark) (require 'ert) -(require 'server) -(require 'vc-hooks) - -(defvar org-dir nil - "Test binding for system-defaults bookmark path setup.") - -(defvar user-home-dir nil - "Test binding for system-defaults default directory setup.") - -(defvar use-package-always-ensure nil - "Test binding for use-package package installation policy.") - -(defconst test-system-defaults--repo-root - (file-name-directory - (directory-file-name - (file-name-directory (or load-file-name buffer-file-name)))) - "Repository root for system-defaults tests.") - -(defmacro test-system-defaults--with-load-environment (&rest body) - "Run BODY with side effects from system-defaults.el stubbed." - `(let ((user-emacs-directory (file-name-as-directory - (make-temp-file "system-defaults-emacs-" t))) - (user-home-dir (file-name-as-directory - (make-temp-file "system-defaults-home-" t))) - (org-dir (file-name-as-directory - (make-temp-file "system-defaults-org-" t))) - (use-package-always-ensure nil)) - (cl-letf (((symbol-function 'server-running-p) (lambda (&rest _) t)) - ((symbol-function 'server-start) #'ignore) - ((symbol-function 'set-locale-environment) #'ignore) - ((symbol-function 'prefer-coding-system) #'ignore) - ((symbol-function 'set-default-coding-systems) #'ignore) - ((symbol-function 'set-terminal-coding-system) #'ignore) - ((symbol-function 'set-keyboard-coding-system) #'ignore) - ((symbol-function 'set-selection-coding-system) #'ignore) - ((symbol-function 'set-charset-priority) #'ignore) - ((symbol-function 'global-auto-revert-mode) #'ignore) - ((symbol-function 'recentf-mode) #'ignore)) - (unless (fboundp 'use-package) - (defmacro use-package (&rest _args) nil)) - ,@body))) +(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) +(require 'testutil-system-defaults) (ert-deftest test-system-defaults-vc-follow-symlinks-normal-sets-t () "Normal: system-defaults follows version-controlled symlinks without asking." (test-system-defaults--with-load-environment - (let ((vc-follow-symlinks nil)) - (load (expand-file-name "modules/system-defaults.el" - test-system-defaults--repo-root) - nil t) - (should (eq vc-follow-symlinks t))))) + (let ((vc-follow-symlinks nil)) + (test-system-defaults--load) + (should (eq vc-follow-symlinks t))))) (provide 'test-system-defaults-vc-follow-symlinks) ;;; test-system-defaults-vc-follow-symlinks.el ends here diff --git a/tests/test-system-defaults.el b/tests/test-system-defaults.el new file mode 100644 index 00000000..bc3694db --- /dev/null +++ b/tests/test-system-defaults.el @@ -0,0 +1,68 @@ +;;; test-system-defaults.el --- Smoke tests for system-defaults settings -*- lexical-binding: t; -*- + +;;; Commentary: + +;; system-defaults.el holds high-impact defaults with no behavior of its own +;; to unit-test, so these are characterization smoke tests on the *settings* +;; most likely to cause damage if they regressed silently: where Customize +;; writes land, where backups go, and whether the minibuffer GC hooks are +;; installed. Load happens in the shared sandbox (testutil-system-defaults.el). +;; +;; The module's functions (cj/disabled, the GC hook bodies, unpropertize-kill-ring, +;; cj/log-comp-warning) are covered by test-system-defaults-functions.el, and the +;; vc-follow-symlinks default by test-system-defaults-vc-follow-symlinks.el. + +;;; Code: + +(require 'ert) +(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) +(require 'testutil-system-defaults) + +;;; custom-file redirection + +(ert-deftest test-system-defaults-custom-file-redirected-to-tempfile () + "Normal: custom-file points at a throwaway temp file, never the repo. +This is what stops accidental Customize writes from landing in tracked init." + (test-system-defaults--with-load-environment + (let ((custom-file nil)) + (test-system-defaults--load) + (should (stringp custom-file)) + (should (string-prefix-p (file-name-as-directory + (expand-file-name temporary-file-directory)) + (expand-file-name custom-file))) + (should (string-match-p "emacs-customizations-trashbin-" + (file-name-nondirectory custom-file))) + (should-not (string-prefix-p (expand-file-name user-emacs-directory) + (expand-file-name custom-file)))))) + +;;; backup directory + +(ert-deftest test-system-defaults-backups-redirected-under-user-emacs-dir () + "Normal: backups are redirected into user-emacs-directory/backups. +cj/backup-directory is a defvar that only recomputes when unbound, so the +test clears it first to capture the path derived from the sandbox." + (test-system-defaults--with-load-environment + (makunbound 'cj/backup-directory) + (let ((backup-directory-alist nil)) + (test-system-defaults--load) + (let ((dir (cdr (assoc "." backup-directory-alist)))) + (should dir) + (should (string-prefix-p (expand-file-name user-emacs-directory) + (expand-file-name dir))) + (should (string-suffix-p "backups" (directory-file-name dir))))))) + +;;; minibuffer GC hooks + +(ert-deftest test-system-defaults-minibuffer-gc-hooks-registered () + "Normal: the minibuffer GC raise/restore hooks are installed. +Their bodies are tested in test-system-defaults-functions.el; this asserts +they are actually wired onto the minibuffer hooks." + (test-system-defaults--with-load-environment + (let ((minibuffer-setup-hook nil) + (minibuffer-exit-hook nil)) + (test-system-defaults--load) + (should (memq 'cj/minibuffer-setup-hook minibuffer-setup-hook)) + (should (memq 'cj/minibuffer-exit-hook minibuffer-exit-hook))))) + +(provide 'test-system-defaults) +;;; test-system-defaults.el ends here diff --git a/tests/testutil-system-defaults.el b/tests/testutil-system-defaults.el new file mode 100644 index 00000000..d1e669dc --- /dev/null +++ b/tests/testutil-system-defaults.el @@ -0,0 +1,69 @@ +;;; testutil-system-defaults.el --- Shared load harness for system-defaults tests -*- lexical-binding: t; -*- + +;;; Commentary: + +;; system-defaults.el has startup side effects (server start, coding-system +;; setup, recentf, file creation under `user-emacs-directory'). Tests that +;; assert one of its settings load the module fresh in a sandbox with those +;; external interactions stubbed, then inspect the variable they own. This +;; file holds that harness so each system-defaults test file shares one copy. + +;;; Code: + +(require 'cl-lib) +(require 'autorevert) +(require 'bookmark) +(require 'server) +(require 'vc-hooks) + +(defvar org-dir nil + "Test binding for system-defaults bookmark path setup.") + +(defvar user-home-dir nil + "Test binding for system-defaults default directory setup.") + +(defvar use-package-always-ensure nil + "Test binding for use-package package installation policy.") + +(defconst test-system-defaults--repo-root + (file-name-directory + (directory-file-name + (file-name-directory (or load-file-name buffer-file-name)))) + "Repository root, derived from this file's location under tests/.") + +(defmacro test-system-defaults--with-load-environment (&rest body) + "Run BODY with the side effects of loading system-defaults.el stubbed. +`user-emacs-directory', `user-home-dir', and `org-dir' are redirected to +throwaway temp directories so file creation lands in the sandbox." + (declare (indent 0)) + `(let ((user-emacs-directory (file-name-as-directory + (make-temp-file "system-defaults-emacs-" t))) + (user-home-dir (file-name-as-directory + (make-temp-file "system-defaults-home-" t))) + (org-dir (file-name-as-directory + (make-temp-file "system-defaults-org-" t))) + (use-package-always-ensure nil)) + (cl-letf (((symbol-function 'server-running-p) (lambda (&rest _) t)) + ((symbol-function 'server-start) #'ignore) + ((symbol-function 'set-locale-environment) #'ignore) + ((symbol-function 'prefer-coding-system) #'ignore) + ((symbol-function 'set-default-coding-systems) #'ignore) + ((symbol-function 'set-terminal-coding-system) #'ignore) + ((symbol-function 'set-keyboard-coding-system) #'ignore) + ((symbol-function 'set-selection-coding-system) #'ignore) + ((symbol-function 'set-charset-priority) #'ignore) + ((symbol-function 'global-auto-revert-mode) #'ignore) + ((symbol-function 'recentf-mode) #'ignore)) + (unless (fboundp 'use-package) + (defmacro use-package (&rest _args) nil)) + ,@body))) + +(defun test-system-defaults--load () + "Load system-defaults.el fresh from the repo for a smoke assertion. +Call inside `test-system-defaults--with-load-environment'." + (load (expand-file-name "modules/system-defaults.el" + test-system-defaults--repo-root) + nil t)) + +(provide 'testutil-system-defaults) +;;; testutil-system-defaults.el ends here |
