aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-export-config-pdf-open-guard.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-25 17:51:17 -0500
committerCraig Jennings <c@cjennings.net>2026-05-25 17:51:17 -0500
commitd665582d6fc19c15a772c6ec24ff822e7e3c37f9 (patch)
tree40c44ed42cd4e4805de626221eae88a05ea484d1 /tests/test-org-export-config-pdf-open-guard.el
parentc414a6346f970f0ac49f92222471efeaf7e922d0 (diff)
downloaddotemacs-d665582d6fc19c15a772c6ec24ff822e7e3c37f9.tar.gz
dotemacs-d665582d6fc19c15a772c6ec24ff822e7e3c37f9.zip
fix(org): guard external-tool assumptions in export and publishing commands
Four export/publishing commands shelled out to external tools without checking they exist, so a missing tool surfaced as an opaque process error — or, for reveal.js, a silently broken presentation. I added a command-time guard to each that names the tool and what's needed: - zathura, in the pandoc PDF export-and-open command - the hugo binary and the platform file-manager opener, in hugo-config - the local reveal.js checkout (run scripts/setup-reveal.sh), shared by the reveal export and preview commands - pandoc, in the web-clip protocol handler The checks run only when the command runs, so startup stays quiet. Each guard has a test asserting the user-error fires when the tool is absent, and the existing happy-path tests now stub the lookups so they exercise the real path rather than tripping the new guard.
Diffstat (limited to 'tests/test-org-export-config-pdf-open-guard.el')
-rw-r--r--tests/test-org-export-config-pdf-open-guard.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test-org-export-config-pdf-open-guard.el b/tests/test-org-export-config-pdf-open-guard.el
new file mode 100644
index 00000000..8d798871
--- /dev/null
+++ b/tests/test-org-export-config-pdf-open-guard.el
@@ -0,0 +1,45 @@
+;;; test-org-export-config-pdf-open-guard.el --- zathura open guard test -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; `my/org-pandoc-export-to-pdf-and-open' opens the exported PDF with zathura
+;; via `start-process'. Without zathura on PATH that call fails with an opaque
+;; error. These tests pin the command-time guard: a missing zathura signals a
+;; `user-error' naming the tool, and a present zathura lets the open proceed.
+;; Requiring the module then ox fires the deferred ox-pandoc :config in batch,
+;; which is where the function is defined.
+
+;;; Code:
+
+;; Initialize package system for batch mode so elpa packages (ox-pandoc) load.
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+(require 'cl-lib)
+(require 'org)
+(require 'org-export-config)
+(require 'ox)
+;; The function under test lives in ox-pandoc's :config block. In batch the
+;; deferred :after-ox config does not fire on a bare module load, so require
+;; ox-pandoc directly to ensure the function is defined.
+(require 'ox-pandoc)
+
+(ert-deftest test-org-export-config-pdf-open-missing-zathura-errors ()
+ "Error: missing zathura signals a user-error before opening the PDF."
+ (cl-letf (((symbol-function 'executable-find) (lambda (&rest _) nil)))
+ (should-error (my/org-pandoc-export-to-pdf-and-open) :type 'user-error)))
+
+(ert-deftest test-org-export-config-pdf-open-present-zathura-proceeds ()
+ "Normal: with zathura present, the open step runs without error."
+ (let ((started nil))
+ (cl-letf (((symbol-function 'executable-find)
+ (lambda (cmd &rest _) (if (equal cmd "zathura") "/usr/bin/zathura" nil)))
+ ((symbol-function 'org-pandoc-export-to-latex-pdf)
+ (lambda (&rest _) "/tmp/out.pdf"))
+ ((symbol-function 'start-process)
+ (lambda (&rest _) (setq started t) 'fake-process)))
+ (my/org-pandoc-export-to-pdf-and-open)
+ (should started))))
+
+(provide 'test-org-export-config-pdf-open-guard)
+;;; test-org-export-config-pdf-open-guard.el ends here