From 2e3905c728bacb713ee7857091d1d69d2b0473f4 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 24 May 2026 14:42:58 -0500 Subject: test(org-capture): smoke-test template key uniqueness and file targets Org capture templates are assembled across org-capture-config, quick-video-capture, org-contacts-config and other modules, so a duplicate dispatch key or a file target pointing at an unset path variable would be easy to miss. Added a smoke test that loads the cleanly-loadable capture modules, applies their lazy additions, and asserts no two templates share a key and that every symbol-valued file target resolves to a non-empty string path. Literal-string targets (the video template's no-save (file "")) and lambda targets (the drill file pickers) are intentionally excluded; webclipper templates need org-web-tools and are covered by their own test. --- tests/test-org-capture-templates-integrity.el | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/test-org-capture-templates-integrity.el (limited to 'tests') diff --git a/tests/test-org-capture-templates-integrity.el b/tests/test-org-capture-templates-integrity.el new file mode 100644 index 00000000..dd7e1dc3 --- /dev/null +++ b/tests/test-org-capture-templates-integrity.el @@ -0,0 +1,67 @@ +;;; test-org-capture-templates-integrity.el --- Capture-template smoke tests -*- lexical-binding: t; -*- + +;;; Commentary: +;; Org capture templates are assembled across several feature modules +;; (org-capture-config, quick-video-capture, org-contacts-config, ...), so a +;; duplicate dispatch key or a file target pointing at an unset path variable +;; would be easy to miss. These smoke tests load the cleanly-loadable capture +;; modules, apply their lazy additions, and assert key uniqueness and that +;; symbol-valued file targets resolve to non-empty path strings. +;; +;; Webclipper templates register only when org-web-tools is installed and are +;; covered by their own test (test-org-webclipper-commands.el), so they are out +;; of scope here. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'user-constants) +(require 'org) +(require 'org-capture) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'org-capture-config) +(require 'quick-video-capture) +(require 'org-contacts-config) + +(defun test-capture--assembled-templates () + "Return `org-capture-templates' with the cleanly-loadable lazy additions. +Contacts registers its template via `with-eval-after-load' on load; the +video-download template is registered on demand here." + (cj/setup-video-download) + org-capture-templates) + +(defun test-capture--file-target-path-symbol (entry) + "Return ENTRY's file-target path symbol, or nil for literal/lambda targets. +Only plain symbol path slots are returned; a literal \"\" (the video +template's no-save target) or a lambda (the drill file pickers) yields nil." + (when (>= (length entry) 4) + (let ((target (nth 3 entry))) + (when (and (consp target) + (memq (car target) + '(file file+headline file+olp file+datetree + file+olp+datetree file+function))) + (let ((path (nth 1 target))) + (and (symbolp path) path)))))) + +;;; Smoke Cases + +(ert-deftest test-org-capture-template-keys-are-unique () + "Smoke: no two capture templates share a dispatch key." + (let* ((keys (mapcar #'car (test-capture--assembled-templates))) + (deduped (cl-remove-duplicates keys :test #'equal :from-end t))) + (should (equal keys deduped)))) + +(ert-deftest test-org-capture-file-targets-point-at-nonempty-paths () + "Smoke: every symbol-valued file target resolves to a non-empty string path. +Literal-string targets and lambda targets are intentionally excluded." + (dolist (entry (test-capture--assembled-templates)) + (let ((sym (test-capture--file-target-path-symbol entry))) + (when sym + (should (boundp sym)) + (should (stringp (symbol-value sym))) + (should-not (string-empty-p (symbol-value sym))))))) + +(provide 'test-org-capture-templates-integrity) +;;; test-org-capture-templates-integrity.el ends here -- cgit v1.2.3