aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-05 05:26:44 -0500
committerCraig Jennings <c@cjennings.net>2026-05-05 05:26:44 -0500
commitfd658b166a8dcf716c82cca28f370990a9df83af (patch)
tree33dba19d419831a0743779b14fd19b8aaa70d7a5 /tests
parentbac40a5dbc241cab055f92431a80b7971896fde4 (diff)
downloadorg-drill-fd658b166a8dcf716c82cca28f370990a9df83af.tar.gz
org-drill-fd658b166a8dcf716c82cca28f370990a9df83af.zip
fix: skip LaTeX preview on TTY frames (upstream #44)
Issue #44 (2021): running org-drill in a TTY emacsclient (the reporter mentioned tmux) raised "Window system frame should be used" because LaTeX preview helpers (org-latex-preview, org--latex-preview-region) require a window system and weren't guarded. Wrapped both call sites with (when (display-graphic-p) ...). - org-drill--show-latex-fragments: now a silent no-op on TTY - present-default-answer's clear-and-preview block: same guard LaTeX previews are inherently graphical. The right behavior on TTY is to skip the preview rather than crash the session — TTY users still see the underlying source text just fine.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-drill-tty-safe.el49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test-org-drill-tty-safe.el b/tests/test-org-drill-tty-safe.el
new file mode 100644
index 0000000..7ec5cf2
--- /dev/null
+++ b/tests/test-org-drill-tty-safe.el
@@ -0,0 +1,49 @@
+;;; test-org-drill-tty-safe.el --- Regression for TTY/no-window-system error -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Upstream issue #44 (2021-10). Running org-drill in a TTY emacsclient
+;; (e.g., inside tmux) produced "error: Window system frame should be
+;; used" because the LaTeX preview helpers (`org-latex-preview',
+;; `org--latex-preview-region') require a window-system frame and
+;; weren't guarded.
+;;
+;; Fix: gate `org-drill--show-latex-fragments' on `display-graphic-p',
+;; making it a no-op on TTY. LaTeX previews are inherently graphical
+;; — the right behavior in TTY is to skip the preview rather than
+;; crash the session.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+(require 'org)
+(require 'org-drill)
+
+;;;; Regression — #44
+
+(ert-deftest test-show-latex-fragments-noop-on-tty ()
+ "On a non-graphic display, the helper should be a silent no-op
+rather than calling org-latex-preview (which requires a window
+system frame)."
+ (let ((latex-preview-called nil))
+ (cl-letf (((symbol-function 'display-graphic-p) (lambda () nil))
+ ((symbol-function 'org-clear-latex-preview)
+ (lambda () (setq latex-preview-called 'cleared)))
+ ((symbol-function 'org-latex-preview)
+ (lambda (&rest _) (setq latex-preview-called 'displayed))))
+ (org-drill--show-latex-fragments)
+ (should (null latex-preview-called)))))
+
+(ert-deftest test-show-latex-fragments-runs-on-graphic-display ()
+ "On a graphic display, the helper still calls through to org-latex-preview."
+ (let ((latex-preview-called nil))
+ (cl-letf (((symbol-function 'display-graphic-p) (lambda () t))
+ ((symbol-function 'org-clear-latex-preview) #'ignore)
+ ((symbol-function 'org-latex-preview)
+ (lambda (&rest _) (setq latex-preview-called t))))
+ (org-drill--show-latex-fragments)
+ (should latex-preview-called))))
+
+(provide 'test-org-drill-tty-safe)
+
+;;; test-org-drill-tty-safe.el ends here