aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-30 08:29:42 -0500
committerCraig Jennings <c@cjennings.net>2026-04-30 09:13:48 -0500
commit0fb3ae438277146a1167cc46ed6c3218a14281ff (patch)
treea2c0ecf210a9b42ed552558b81b16888e642c35d /tests
parent21d5a737f0278baeafd4d72e59cc9505043d91a9 (diff)
downloaddotemacs-0fb3ae438277146a1167cc46ed6c3218a14281ff.tar.gz
dotemacs-0fb3ae438277146a1167cc46ed6c3218a14281ff.zip
test(config-utilities): cover with-timer, compile-buffer, summary, info commands
Four new test files extending the existing coverage of cj/emacs-build--format-build-time. The interactive heavyweights (cj/recompile-emacs-home, cj/delete-emacs-home-compiled-files, cj/benchmark-this-method, cj/validate-org-agenda-timestamps) are out of scope for this pass — each needs an internal/wrapper split first before tests can exercise the logic without UI. - with-timer macro: 4 tests asserting it returns the FORMS' value, evaluates the body exactly once, emits both announce and done messages, and returns the last form when given multiple. - cj/compile-this-elisp-buffer: 6 tests dispatching across native-async, native-sync, and byte-compile fallbacks, plus the not-elisp / no-buffer-file-name error paths and the sync-native error catch. - cj/emacs-build--summary-string: 5 tests asserting the shape of the multi-line report (Version, System, Build date, Capabilities section, yes/no flag rendering) without locking exact wording. - info-commands smoke: 5 tests exercising cj/info-emacs-build, cj/info-loaded-packages, cj/info-loaded-features, cj/reload-init-file, and cj/org-alert-list-timers via boundary-mocked pop-to-buffer and load-file, asserting buffer creation, content shape, or echo-area message as appropriate. 20 new tests, all passing. Full suite green.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-config-utilities--compile-this-elisp-buffer.el95
-rw-r--r--tests/test-config-utilities--info-commands-smoke.el83
-rw-r--r--tests/test-config-utilities--summary-string.el54
-rw-r--r--tests/test-config-utilities--with-timer.el54
4 files changed, 286 insertions, 0 deletions
diff --git a/tests/test-config-utilities--compile-this-elisp-buffer.el b/tests/test-config-utilities--compile-this-elisp-buffer.el
new file mode 100644
index 00000000..fb5e288a
--- /dev/null
+++ b/tests/test-config-utilities--compile-this-elisp-buffer.el
@@ -0,0 +1,95 @@
+;;; test-config-utilities--compile-this-elisp-buffer.el --- Tests for cj/compile-this-elisp-buffer -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for `cj/compile-this-elisp-buffer'. The function dispatches
+;; among native-compile-async, native-compile (sync), and
+;; byte-compile-file based on which is fboundp. Tests force each
+;; branch by mocking fboundp at the boundary.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'config-utilities)
+
+(defmacro test-config-utilities--with-elisp-buffer (path &rest body)
+ "Run BODY in a temp buffer visiting PATH (a .el file path).
+Skips the interactive `save-buffer' so tests stay free of disk side
+effects."
+ (declare (indent 1) (debug t))
+ `(with-temp-buffer
+ (setq buffer-file-name ,path)
+ (cl-letf (((symbol-function 'save-buffer) (lambda () nil)))
+ ,@body)))
+
+(ert-deftest test-config-utilities-compile-buffer-not-elisp-raises ()
+ "Error: a buffer whose file isn't .el raises `user-error'."
+ (test-config-utilities--with-elisp-buffer "/tmp/not-elisp.txt"
+ (should-error (cj/compile-this-elisp-buffer) :type 'user-error)))
+
+(ert-deftest test-config-utilities-compile-buffer-no-buffer-file-name-raises ()
+ "Error: a buffer with no `buffer-file-name' raises `user-error'."
+ (with-temp-buffer
+ (setq buffer-file-name nil)
+ (should-error (cj/compile-this-elisp-buffer) :type 'user-error)))
+
+(ert-deftest test-config-utilities-compile-buffer-prefers-native-async ()
+ "Normal: `native-compile-async' is preferred when available."
+ (let (called-with)
+ (test-config-utilities--with-elisp-buffer "/tmp/some.el"
+ (cl-letf (((symbol-function 'fboundp)
+ (lambda (sym)
+ (memq sym '(native-compile-async native-compile byte-compile-file))))
+ ((symbol-function 'native-compile-async)
+ (lambda (file) (setq called-with file)))
+ ((symbol-function 'native-compile)
+ (lambda (_) (error "should not call sync native-compile")))
+ ((symbol-function 'byte-compile-file)
+ (lambda (_) (error "should not call byte-compile-file"))))
+ (cj/compile-this-elisp-buffer)
+ (should (equal called-with "/tmp/some.el"))))))
+
+(ert-deftest test-config-utilities-compile-buffer-falls-back-to-sync-native ()
+ "Normal: `native-compile' is used when async isn't available."
+ (let (called-with)
+ (test-config-utilities--with-elisp-buffer "/tmp/some.el"
+ (cl-letf (((symbol-function 'fboundp)
+ (lambda (sym) (memq sym '(native-compile byte-compile-file))))
+ ((symbol-function 'native-compile)
+ (lambda (file) (setq called-with file)))
+ ((symbol-function 'byte-compile-file)
+ (lambda (_) (error "should not call byte-compile-file"))))
+ (cj/compile-this-elisp-buffer)
+ (should (equal called-with "/tmp/some.el"))))))
+
+(ert-deftest test-config-utilities-compile-buffer-falls-back-to-byte-compile ()
+ "Normal: `byte-compile-file' is used when neither native option is available."
+ (let (called-with)
+ (test-config-utilities--with-elisp-buffer "/tmp/some.el"
+ (cl-letf (((symbol-function 'fboundp)
+ (lambda (sym) (eq sym 'byte-compile-file)))
+ ((symbol-function 'byte-compile-file)
+ (lambda (file) (setq called-with file) "/tmp/some.elc")))
+ (cj/compile-this-elisp-buffer)
+ (should (equal called-with "/tmp/some.el"))))))
+
+(ert-deftest test-config-utilities-compile-buffer-handles-sync-native-error ()
+ "Error: a sync `native-compile' that signals is caught and reported.
+Asserts no error escapes by running the function and checking that the
+message captured contains the failure prefix."
+ (test-config-utilities--with-elisp-buffer "/tmp/some.el"
+ (let (captured)
+ (cl-letf (((symbol-function 'fboundp)
+ (lambda (sym) (memq sym '(native-compile byte-compile-file))))
+ ((symbol-function 'native-compile)
+ (lambda (_) (error "boom")))
+ ((symbol-function 'message)
+ (lambda (fmt &rest args)
+ (setq captured (apply #'format fmt args)))))
+ (cj/compile-this-elisp-buffer))
+ (should (string-match-p "Native compile failed" captured)))))
+
+(provide 'test-config-utilities--compile-this-elisp-buffer)
+;;; test-config-utilities--compile-this-elisp-buffer.el ends here
diff --git a/tests/test-config-utilities--info-commands-smoke.el b/tests/test-config-utilities--info-commands-smoke.el
new file mode 100644
index 00000000..f28ec712
--- /dev/null
+++ b/tests/test-config-utilities--info-commands-smoke.el
@@ -0,0 +1,83 @@
+;;; test-config-utilities--info-commands-smoke.el --- Smoke tests for the cj/info-* family + reload-init-file -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Smoke tests for the simple interactive commands in config-utilities.el:
+;; cj/info-emacs-build, cj/info-loaded-packages, cj/info-loaded-features,
+;; cj/reload-init-file, and cj/org-alert-list-timers. Each is exercised
+;; with `pop-to-buffer' and `load-file' mocked so the test doesn't open
+;; real windows or reload init.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'config-utilities)
+
+(defmacro test-config-utilities--with-display-mocks (&rest body)
+ "Run BODY with `pop-to-buffer' replaced so it doesn't open a window."
+ (declare (indent 0) (debug t))
+ `(cl-letf (((symbol-function 'pop-to-buffer)
+ (lambda (buf &rest _) (set-buffer buf) (current-buffer))))
+ ,@body))
+
+(ert-deftest test-config-utilities-info-emacs-build-creates-summary-buffer ()
+ "Smoke: `cj/info-emacs-build' creates *Emacs-Build-Summary* with content."
+ (let ((buf (get-buffer "*Emacs-Build-Summary*")))
+ (when buf (let ((kill-buffer-query-functions nil)) (kill-buffer buf))))
+ (test-config-utilities--with-display-mocks
+ (cj/info-emacs-build)
+ (let ((buf (get-buffer "*Emacs-Build-Summary*")))
+ (should (buffer-live-p buf))
+ (with-current-buffer buf
+ (should (string-match-p "Version:" (buffer-string))))
+ (let ((kill-buffer-query-functions nil)) (kill-buffer buf)))))
+
+(ert-deftest test-config-utilities-info-loaded-packages-creates-buffer ()
+ "Smoke: `cj/info-loaded-packages' creates *loaded-packages* with a count line."
+ (let ((buf (get-buffer "*loaded-packages*")))
+ (when buf (let ((kill-buffer-query-functions nil)) (kill-buffer buf))))
+ (test-config-utilities--with-display-mocks
+ (cj/info-loaded-packages)
+ (let ((buf (get-buffer "*loaded-packages*")))
+ (should (buffer-live-p buf))
+ (with-current-buffer buf
+ (should (string-match-p "total packages currently loaded"
+ (buffer-string))))
+ (let ((kill-buffer-query-functions nil)) (kill-buffer buf)))))
+
+(ert-deftest test-config-utilities-info-loaded-features-creates-buffer ()
+ "Smoke: `cj/info-loaded-features' creates *loaded-features* with a count line."
+ (let ((buf (get-buffer "*loaded-features*")))
+ (when buf (let ((kill-buffer-query-functions nil)) (kill-buffer buf))))
+ (test-config-utilities--with-display-mocks
+ (cj/info-loaded-features)
+ (let ((buf (get-buffer "*loaded-features*")))
+ (should (buffer-live-p buf))
+ (with-current-buffer buf
+ (should (string-match-p "features currently loaded"
+ (buffer-string))))
+ (let ((kill-buffer-query-functions nil)) (kill-buffer buf)))))
+
+(ert-deftest test-config-utilities-reload-init-file-loads-user-init-file ()
+ "Smoke: `cj/reload-init-file' calls `load-file' on `user-init-file'."
+ (let (called-with)
+ (cl-letf (((symbol-function 'load-file)
+ (lambda (file) (setq called-with file))))
+ (cj/reload-init-file))
+ (should (equal called-with user-init-file))))
+
+(ert-deftest test-config-utilities-org-alert-list-timers-no-timers-messages ()
+ "Boundary: `cj/org-alert-list-timers' with no matching timers emits a
+\"none found\" message."
+ (let (captured)
+ (cl-letf ((timer-list nil)
+ ((symbol-function 'message)
+ (lambda (fmt &rest args)
+ (setq captured (apply #'format fmt args)))))
+ (cj/org-alert-list-timers))
+ (should (string-match-p "No org-alert-check timers" captured))))
+
+(provide 'test-config-utilities--info-commands-smoke)
+;;; test-config-utilities--info-commands-smoke.el ends here
diff --git a/tests/test-config-utilities--summary-string.el b/tests/test-config-utilities--summary-string.el
new file mode 100644
index 00000000..cd9ae77a
--- /dev/null
+++ b/tests/test-config-utilities--summary-string.el
@@ -0,0 +1,54 @@
+;;; test-config-utilities--summary-string.el --- Tests for cj/emacs-build--summary-string -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for `cj/emacs-build--summary-string'. The function returns a
+;; multi-line string covering Emacs version, system, build metadata,
+;; and capability flags. Tests assert that key sections are present
+;; without locking to exact wording.
+
+;;; Code:
+
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'config-utilities)
+
+(ert-deftest test-config-utilities-summary-string-includes-version-line ()
+ "Normal: summary string includes a Version line with `emacs-version'."
+ (let ((text (cj/emacs-build--summary-string)))
+ (should (string-match-p (regexp-quote (format "Version: %s" emacs-version))
+ text))))
+
+(ert-deftest test-config-utilities-summary-string-includes-system-line ()
+ "Normal: summary string includes the System: line."
+ (should (string-match-p "^System: " (cj/emacs-build--summary-string))))
+
+(ert-deftest test-config-utilities-summary-string-includes-build-date-line ()
+ "Normal: summary string includes Build date."
+ (should (string-match-p "^Build date: " (cj/emacs-build--summary-string))))
+
+(ert-deftest test-config-utilities-summary-string-includes-capabilities-section ()
+ "Normal: summary string includes the Capabilities section with the
+known capability lines (native compilation, dynamic modules, GnuTLS,
+libxml2, ImageMagick, SQLite)."
+ (let ((text (cj/emacs-build--summary-string)))
+ (should (string-match-p "Capabilities:" text))
+ (dolist (cap '("Native compilation"
+ "Dynamic modules"
+ "GnuTLS"
+ "libxml2"
+ "ImageMagick"
+ "SQLite"))
+ (should (string-match-p (regexp-quote cap) text)))))
+
+(ert-deftest test-config-utilities-summary-string-renders-yes-or-no-flags ()
+ "Boundary: each capability line ends in either \"yes\" or \"no\"."
+ (let ((text (cj/emacs-build--summary-string)))
+ (dolist (cap '("Native compilation" "Dynamic modules"
+ "GnuTLS" "libxml2"
+ "ImageMagick" "SQLite"))
+ (let ((re (concat "^- " (regexp-quote cap) ": \\(yes\\|no\\)")))
+ (should (string-match-p re text))))))
+
+(provide 'test-config-utilities--summary-string)
+;;; test-config-utilities--summary-string.el ends here
diff --git a/tests/test-config-utilities--with-timer.el b/tests/test-config-utilities--with-timer.el
new file mode 100644
index 00000000..74bbbc02
--- /dev/null
+++ b/tests/test-config-utilities--with-timer.el
@@ -0,0 +1,54 @@
+;;; test-config-utilities--with-timer.el --- Tests for the with-timer macro -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for the `with-timer' macro from config-utilities.el. The macro
+;; runs FORMS, prints a timing message, and returns the value of FORMS.
+;; These tests verify that the macro preserves the result through the
+;; timing wrapper and that the announce/done messages fire.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'config-utilities)
+
+(ert-deftest test-config-utilities-with-timer-returns-forms-value ()
+ "Normal: with-timer returns the value of the wrapped FORMS."
+ (let ((inhibit-message t))
+ (should (= 42 (with-timer "compute"
+ (+ 40 2))))))
+
+(ert-deftest test-config-utilities-with-timer-evaluates-forms-once ()
+ "Boundary: with-timer evaluates the body exactly once.
+Guards against the macro accidentally re-evaluating FORMS for the
+elapsed-time message or similar."
+ (let ((counter 0)
+ (inhibit-message t))
+ (with-timer "count"
+ (cl-incf counter))
+ (should (= 1 counter))))
+
+(ert-deftest test-config-utilities-with-timer-emits-announce-and-done-messages ()
+ "Boundary: with-timer emits both \"TITLE...\" and \"TITLE... done\" messages."
+ (let (messages)
+ (cl-letf (((symbol-function 'message)
+ (lambda (fmt &rest args) (push (apply #'format fmt args) messages))))
+ (with-timer "tag"
+ :ignored))
+ (let ((all (string-join (nreverse messages) "\n")))
+ (should (string-match-p "^tag\\.\\.\\.$" all))
+ (should (string-match-p "^tag\\.\\.\\. done (" all)))))
+
+(ert-deftest test-config-utilities-with-timer-multiple-forms-returns-last ()
+ "Boundary: with-timer with multiple forms returns the last form's value."
+ (let ((inhibit-message t))
+ (should (equal "third"
+ (with-timer "multi"
+ "first"
+ "second"
+ "third")))))
+
+(provide 'test-config-utilities--with-timer)
+;;; test-config-utilities--with-timer.el ends here